[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 348166.
RedDocMD added a comment.

Removed extra include


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -76,11 +76,18 @@
   {{"release"}, ::handleRelease},
   {{"swap", 1}, ::handleSwap},
   {{"get"}, ::handleGet}};
+
+  // TODO: Get rid after 

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 348165.
RedDocMD marked 10 inline comments as done.
RedDocMD added a comment.

More refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -76,11 +76,18 @@
   {{"release"}, ::handleRelease},
   {{"swap", 1}, ::handleSwap},
   {{"get"}, 

[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 348164.
lichray added a comment.

Simplify implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D103131: support debug info for alias variable

2021-05-26 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui updated this revision to Diff 348160.
kamleshbhalui added a comment.

match gcc behavior


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103131

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-alias.c


Index: clang/test/CodeGen/debug-info-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple 
x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,12 @@
   setTLSMode(GA, *VD);
 
   SetCommonAttributes(GD, GA);
+
+  // Emit global alias debug information.
+  if (const auto *VD = dyn_cast(D)) {
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  DI->EmitGlobalAlias(VD);
+  }
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit information about global alias.
+  void EmitGlobalAlias(const VarDecl *Decl);
+
   /// Emit C++ using directive.
   void EmitUsingDirective(const UsingDirectiveDecl );
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4945,6 +4945,20 @@
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitGlobalAlias(const VarDecl *D) {
+  if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
+return;
+
+  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+  StringRef Name = D->getName();
+  llvm::DIType *Ty = getOrCreateType(D->getType(), Unit);
+  llvm::DIScope *DContext = getDeclContextDescriptor(D);
+  auto Loc = getLineNumber(D->getLocation());
+  DBuilder.createGlobalVariableExpression(
+  DContext, Name, StringRef(), Unit, Loc, Ty,
+  !D->hasExternalFormalLinkage(), false);
+}
+
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
   if (!LexicalBlockStack.empty())
 return LexicalBlockStack.back();


Index: clang/test/CodeGen/debug-info-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,12 @@
   setTLSMode(GA, *VD);
 
   SetCommonAttributes(GD, GA);
+
+  // Emit global alias debug information.
+  if (const auto *VD = dyn_cast(D)) {
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  DI->EmitGlobalAlias(VD);
+  }
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit information about global alias.
+  void EmitGlobalAlias(const VarDecl *Decl);
+
   /// Emit C++ using directive.
   void EmitUsingDirective(const UsingDirectiveDecl );
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4945,6 +4945,20 @@
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitGlobalAlias(const VarDecl *D) {
+  if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
+return;
+
+  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+  StringRef Name = D->getName();
+  llvm::DIType *Ty = getOrCreateType(D->getType(), Unit);
+  llvm::DIScope *DContext = getDeclContextDescriptor(D);
+  auto Loc = getLineNumber(D->getLocation());
+  DBuilder.createGlobalVariableExpression(
+  DContext, Name, StringRef(), Unit, Loc, Ty,
+  !D->hasExternalFormalLinkage(), false);
+}
+
 llvm::DIScope 

[PATCH] D102663: Bug 49633 - Added warning for static inline global and namespaced declarations

2021-05-26 Thread Serberoth via Phabricator via cfe-commits
serberoth updated this revision to Diff 348156.
serberoth retitled this revision from "Bug 49633 - Added warning for static 
inline global and namespaced declarations for c++17+" to "Bug 49633 - Added 
warning for static inline global and namespaced declarations".
serberoth edited the summary of this revision.
serberoth added a comment.

Updates to testing to ensure warning occurs for variables declared in anonymous 
namespace.
Updates per rsmith to ensure that ext compat warning still occurs fixing 
regressive behaviour.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102663

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/c17-global-static-inline.cpp


Index: clang/test/Sema/c17-global-static-inline.cpp
===
--- /dev/null
+++ clang/test/Sema/c17-global-static-inline.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++17 %s -verify
+
+static inline int should_warn; // expected-warning{{variable 'should_warn' 
declared as both inline and with static storage declaration}}
+
+namespace TestNamespace {
+  
+  static inline int NamespacedShouldWarn; // expected-warning{{variable 
'NamespacedShouldWarn' declared as both inline and with static storage 
declaration}}
+
+};
+
+namespace {
+
+  static inline int AnonNamespaceShouldWarn; // expected-warning{{variable 
'AnonNamespaceShouldWarn' declared as both inline and with static storage 
declaration}}
+
+};
+
+static constexpr inline const volatile float f = 0.0f; // 
expected-warning{{variable 'f' declared as both inline and with static storage 
declaration}}
+
+static inline int TestFunction(int s, int e, int n) {
+  int m = (n - s) / (e - s);
+  return m * m * m * (m * (m * 6 - 15) + 10);
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -84,7 +84,7 @@
 constexpr auto &[i] = n; // expected-error {{cannot be declared 
'constexpr'}}
   }
 
-  static constexpr inline thread_local auto &[j1] = n; // expected-error 
{{cannot be declared with 'constexpr inline' specifiers}}
+  static constexpr inline thread_local auto &[j1] = n; // expected-error 
{{cannot be declared with 'constexpr inline' specifiers}} 
expected-warning{{variable 'j1' declared as both inline and with static storage 
declaration}}
   static thread_local auto &[j2] = n; // expected-warning {{declared with 
'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
@@ -4,7 +4,7 @@
 A() -> A;
 A(int) -> A;
 
-static constexpr inline const volatile A a = {}; // ok, specifiers are 
permitted
+static constexpr inline const volatile A a = {}; // expected-warning{{variable 
'a' declared as both inline and with static storage declaration}}
 A b;
 A c [[]] {};
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7125,6 +7125,11 @@
diag::err_inline_declaration_block_scope) << Name
 << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
 } else {
+  // static inline declarations in the global or namespace scope should get
+  // a warning indicating they are contradictory in nature.
+  if (SC == SC_Static && DC->isFileContext())
+Diag(D.getIdentifierLoc(), diag::warn_static_inline) << Name;
+  
   Diag(D.getDeclSpec().getInlineSpecLoc(),
getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
  : diag::ext_inline_variable);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1466,6 +1466,10 @@
 def warn_cxx14_compat_inline_variable : Warning<
   "inline variables are incompatible with C++ standards before C++17">,
   DefaultIgnore, InGroup;
+def warn_static_inline : Warning<
+  "variable %0 declared as both inline and with static storage declaration">,
+  InGroup;
+
 
 def warn_inline_namespace_reopened_noninline : Warning<
   "inline namespace reopened as a non-inline namespace">,


Index: clang/test/Sema/c17-global-static-inline.cpp

[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 348149.
yaxunl marked an inline comment as done.
yaxunl added a comment.

fix test


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

https://reviews.llvm.org/D103108

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCUDA/device-use-host-var.cu
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -31,7 +31,7 @@
 
 static __device__ int x;
 static __constant__ int y;
-static int z;
+static int z; // dev-note {{host variable declared here}}
 
 __global__ void kernel(int *a) {
   a[0] = x;
Index: clang/test/SemaCUDA/device-use-host-var.cu
===
--- clang/test/SemaCUDA/device-use-host-var.cu
+++ clang/test/SemaCUDA/device-use-host-var.cu
@@ -5,35 +5,61 @@
 
 #include "Inputs/cuda.h"
 
+int func();
+
 struct A {
   int x;
   static int host_var;
 };
 
-int A::host_var;
+int A::host_var; // dev-note {{host variable declared here}}
 
 namespace X {
-  int host_var;
+  int host_var; // dev-note {{host variable declared here}}
 }
 
-static int static_host_var;
+// struct with non-empty ctor.
+struct B1 {
+  int x;
+  B1() { x = 1; }
+};
+
+// struct with non-empty dtor.
+struct B2 {
+  int x;
+  B2() {}
+  ~B2() { x = 0; }
+};
+
+static int static_host_var; // dev-note {{host variable declared here}}
 
 __device__ int global_dev_var;
 __constant__ int global_constant_var;
 __shared__ int global_shared_var;
 
-int global_host_var;
+int global_host_var; // dev-note 8{{host variable declared here}}
 const int global_const_var = 1;
 constexpr int global_constexpr_var = 1;
 
-int global_host_array[2] = {1, 2};
+int global_host_array[2] = {1, 2}; // dev-note {{host variable declared here}}
 const int global_const_array[2] = {1, 2};
 constexpr int global_constexpr_array[2] = {1, 2};
 
-A global_host_struct_var{1};
+A global_host_struct_var{1}; // dev-note 2{{host variable declared here}}
 const A global_const_struct_var{1};
 constexpr A global_constexpr_struct_var{1};
 
+// Check const host var initialized with non-empty ctor is not allowed in
+// device function.
+const B1 b1; // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
+// Check const host var having non-empty dtor is not allowed in device function.
+const B2 b2; // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
+// Check const host var initialized by non-constant initializer is not allowed
+// in device function.
+const int b3 = func(); // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
 template
 __global__ void kernel(F f) { f(); } // dev-note2 {{called by 'kernel<(lambda}}
 
@@ -53,11 +79,14 @@
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
   *out = global_const_var;
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in __device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in __device__ function}}
+  *out = b3; // dev-error {{reference to __host__ variable 'b3' in __device__ function}}
   global_host_var = 1; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
 
   // Check reference of non-constexpr host variables are not allowed.
   int _host_var = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int _const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int _const_var = global_const_var;
   const int _constexpr_var = global_constexpr_var;
   *out = ref_host_var;
   *out = ref_constexpr_var;
@@ -65,18 +94,18 @@
 
   // Check access member of non-constexpr struct type host variable is not allowed.
   *out = global_host_struct_var.x; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
-  *out = global_const_struct_var.x; // dev-error {{reference to __host__ variable 'global_const_struct_var' in __device__ function}}
+  *out = global_const_struct_var.x;
   *out = global_constexpr_struct_var.x;
   global_host_struct_var.x = 1; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
 
   // Check address taking of non-constexpr host variables is not allowed.
   int *p = _host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int *cp = _const_var; // 

[PATCH] D103221: [HIP] Change default lang std to c++14

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a subscriber: dexonsmith.
yaxunl requested review of this revision.

Currently clang and nvcc use c++14 as default std for C++.
gcc 11 even uses c++17 as default std for C++. However,
clang uses c++98 as default std for HIP.

As c++14 has been well adopted and became default for
clang, it seems reasonable to use c++14 as default std
for HIP.


https://reviews.llvm.org/D103221

Files:
  clang/include/clang/Basic/LangStandards.def
  clang/test/Preprocessor/lang-std.cu


Index: clang/test/Preprocessor/lang-std.cu
===
--- /dev/null
+++ clang/test/Preprocessor/lang-std.cu
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck -check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E %s | FileCheck -check-prefix=CXX98 %s
+// RUN: %clang_cc1 -dM -E -std=c++98 -x hip %s | FileCheck -check-prefix=CXX98 
%s
+// RUN: %clang_cc1 -dM -E -std=c++14 %s | FileCheck -check-prefix=CXX14 %s
+
+// CXX98: #define __cplusplus 199711L
+// CXX14: #define __cplusplus 201402L
Index: clang/include/clang/Basic/LangStandards.def
===
--- clang/include/clang/Basic/LangStandards.def
+++ clang/include/clang/Basic/LangStandards.def
@@ -198,7 +198,7 @@
 
 // HIP
 LANGSTANDARD(hip, "hip", HIP, "HIP",
- LineComment | CPlusPlus | Digraphs)
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 
 #undef LANGSTANDARD
 #undef LANGSTANDARD_ALIAS


Index: clang/test/Preprocessor/lang-std.cu
===
--- /dev/null
+++ clang/test/Preprocessor/lang-std.cu
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck -check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E %s | FileCheck -check-prefix=CXX98 %s
+// RUN: %clang_cc1 -dM -E -std=c++98 -x hip %s | FileCheck -check-prefix=CXX98 %s
+// RUN: %clang_cc1 -dM -E -std=c++14 %s | FileCheck -check-prefix=CXX14 %s
+
+// CXX98: #define __cplusplus 199711L
+// CXX14: #define __cplusplus 201402L
Index: clang/include/clang/Basic/LangStandards.def
===
--- clang/include/clang/Basic/LangStandards.def
+++ clang/include/clang/Basic/LangStandards.def
@@ -198,7 +198,7 @@
 
 // HIP
 LANGSTANDARD(hip, "hip", HIP, "HIP",
- LineComment | CPlusPlus | Digraphs)
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 
 #undef LANGSTANDARD
 #undef LANGSTANDARD_ALIAS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103218: [Fuchsia][CMake] Add missing include path.

2021-05-26 Thread Haowei Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ce58c52d50b: [Fuchsia][CMake] Add missing include path. 
(authored by haowei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103218

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -145,7 +145,7 @@
   set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
   set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
   foreach(target 
i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/fdio/include")
+set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
 set(FUCHSIA_${target}_LINKER_FLAGS 
"-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
 set(FUCHSIA_${target}_SYSROOT 
"${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
   endforeach()


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -145,7 +145,7 @@
   set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
   set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
   foreach(target i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/fdio/include")
+set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
 set(FUCHSIA_${target}_LINKER_FLAGS "-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
 set(FUCHSIA_${target}_SYSROOT "${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
   endforeach()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0ce58c5 - [Fuchsia][CMake] Add missing include path.

2021-05-26 Thread Haowei Wu via cfe-commits

Author: Haowei Wu
Date: 2021-05-26T19:59:53-07:00
New Revision: 0ce58c52d50bd2edd09df7c7ef3dd4dc85b05992

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

LOG: [Fuchsia][CMake] Add missing include path.

This patch adds include path for missing header files from "sync".
This patch also fixes the build failures caused by scudo.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 2cc25ba1fda8..db1631f7f143 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -145,7 +145,7 @@ if(FUCHSIA_SDK)
   set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
   set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
   foreach(target 
i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/fdio/include")
+set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
 set(FUCHSIA_${target}_LINKER_FLAGS 
"-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
 set(FUCHSIA_${target}_SYSROOT 
"${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
   endforeach()



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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

There's no reliable way to report this with UBSan because in general we can't 
ever know that a loop will not terminate.  That said, we could report 
*obviously* trivial loops, either with UBSan or just with a diagnostic.  If the 
body of your loop really is empty, and the conditions are trivial, that ought 
to be enough to catch it.

The conformant fix is to do some sort of atomic operation or other side-effect 
in your loop; the non-conformant fix is to disable the optimization with 
`-fno-finite-loops`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D103112

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348142.
erichkeane added a comment.

Apply clang-format patch, except for the changes to IdentifierTable.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,215 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(Func); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(Func); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F2{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // 

[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/test/SemaCUDA/device-use-host-var.cu:90
+  const int _const_var = global_const_var;
   const int _constexpr_var = global_constexpr_var;
   *out = ref_host_var;

tra wrote:
> What happens if we have  `const int _foo = 
> something_we_cant_emit_on_device;`?
> Both if ref_foo is and isn't used from device code.
> 
> 
If we have `const int _foo = something_we_cant_emit_on_device`, 
`__constant__` attribute will not be added. If `ref_foo` is used in device 
code, it will be diagnosed. If `ref_foo` is not used in device code, no 
diagnostics is emitted.


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

https://reviews.llvm.org/D103108

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


[clang] a4b61c8 - The compiler is crashing when compiling a coroutine intrinsic without

2021-05-26 Thread Zahira Ammarguellat via cfe-commits

Author: Zahira Ammarguellat
Date: 2021-05-26T18:07:31-07:00
New Revision: a4b61c82cf1a45c172af2e0242f5019281de14f8

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

LOG: The compiler is crashing when compiling a coroutine intrinsic without
the use of the option fcoroutines-ts. This is a patch to fix this.

Fix for https://bugs.llvm.org/show_bug.cgi?id=50406

Added: 
clang/test/SemaCXX/coroutine-builtins.cpp

Modified: 
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/Builtins.h
clang/lib/Basic/Builtins.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index ead84e2e6279..5a9d0a001829 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1577,22 +1577,22 @@ BUILTIN(__builtin_nontemporal_store, "v.", "t")
 BUILTIN(__builtin_nontemporal_load, "v.", "t")
 
 // Coroutine intrinsics.
-BUILTIN(__builtin_coro_resume, "vv*", "")
-BUILTIN(__builtin_coro_destroy, "vv*", "")
-BUILTIN(__builtin_coro_done, "bv*", "n")
-BUILTIN(__builtin_coro_promise, "v*v*IiIb", "n")
-
-BUILTIN(__builtin_coro_size, "z", "n")
-BUILTIN(__builtin_coro_frame, "v*", "n")
-BUILTIN(__builtin_coro_noop, "v*", "n")
-BUILTIN(__builtin_coro_free, "v*v*", "n")
-
-BUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n")
-BUILTIN(__builtin_coro_alloc, "b", "n")
-BUILTIN(__builtin_coro_begin, "v*v*", "n")
-BUILTIN(__builtin_coro_end, "bv*Ib", "n")
-BUILTIN(__builtin_coro_suspend, "cIb", "n")
-BUILTIN(__builtin_coro_param, "bv*v*", "n")
+LANGBUILTIN(__builtin_coro_resume, "vv*", "", COR_LANG)
+LANGBUILTIN(__builtin_coro_destroy, "vv*", "", COR_LANG)
+LANGBUILTIN(__builtin_coro_done, "bv*", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_promise, "v*v*IiIb", "n", COR_LANG)
+
+LANGBUILTIN(__builtin_coro_size, "z", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_frame, "v*", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_noop, "v*", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_free, "v*v*", "n", COR_LANG)
+
+LANGBUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_alloc, "b", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_begin, "v*v*", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_end, "bv*Ib", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_suspend, "cIb", "n", COR_LANG)
+LANGBUILTIN(__builtin_coro_param, "bv*v*", "n", COR_LANG)
 
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.

diff  --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index eefe549b4fa8..cdaaee48c32d 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -37,6 +37,7 @@ enum LanguageID {
   OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
   OMP_LANG = 0x80,// builtin requires OpenMP.
   CUDA_LANG = 0x100,  // builtin requires CUDA.
+  COR_LANG = 0x200,   // builtin requires use of 'fcoroutine-ts' option.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG,// builtin requires MS mode.

diff  --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 8a70c7eed530..7118aa9dc210 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -60,6 +60,8 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info 
,
   bool BuiltinsUnsupported =
   (LangOpts.NoBuiltin || LangOpts.isNoBuiltinFunc(BuiltinInfo.Name)) &&
   strchr(BuiltinInfo.Attributes, 'f');
+  bool CorBuiltinsUnsupported =
+  !LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG);
   bool MathBuiltinsUnsupported =
 LangOpts.NoMathBuiltin && BuiltinInfo.HeaderName &&
 llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h");
@@ -78,10 +80,11 @@ bool Builtin::Context::builtinIsSupported(const 
Builtin::Info ,
   bool CUDAUnsupported = !LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG;
   bool CPlusPlusUnsupported =
   !LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG;
-  return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported 
&&
- !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
- !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported &&
- !CPlusPlusUnsupported && !CUDAUnsupported;
+  return !BuiltinsUnsupported && !CorBuiltinsUnsupported &&
+ !MathBuiltinsUnsupported && !OclCUnsupported && !OclC1Unsupported &&
+ !OclC2Unsupported && !OpenMPUnsupported && !GnuModeUnsupported &&
+ !MSModeUnsupported && !ObjCUnsupported && !CPlusPlusUnsupported &&
+ !CUDAUnsupported;
 }
 
 /// initializeBuiltins - 

[PATCH] D103184: [AArch64] handle -Wa,-march=

2021-05-26 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:217
+  // after -march. And while only using the the value of last -march, it
+  // includes all the options passed via -Wa,-march.
+  success = true;

This comment is confusing. `-march` is a driver option and the GCC driver will 
internally convert it into the equivalent of `-Wa,-march` before passing the 
total command line to GNU as.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103184

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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-26 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D96418#2783541 , @leonardchan wrote:

>> Well, no, I'm afraid it is actually clear that that code does have UB 
>> according to the C++ standard.  Perhaps you mean that it *shouldn't* have 
>> UB, or that Clang should define its behavior despite the standard.
>>
>> I might agree with you that I don't see the value in using this stronger 
>> rule in C++, but I think it would help to understand the problem a little 
>> better.  I assume this is causing problems for a less trivial test case?  Or 
>> do you really have code that's relying on that loop not terminating?
>
> I see. I guess it's good (and bad) that this discovered this UB in our code 
> base. The example I posted is almost exactly what's in our test case. For 
> this particular one, we need a non-terminating thread, so a thread_create 
> function is passed `do_nothing`. Locally, we could get around this by using 
> something like inline assembly to avoid UB.
>
> (Potentially deviating from this patch) While an infinite loop may be UB 
> according to the standard, it's also something fairly common that can be in a 
> lot of code bases. Although it may be an unintended side-effect, it still 
> seems a bit abrupt that we found about this UB from this patch rather than 
> ubsan or a compiler diagnostic. Are there any plans in the future for 
> something along the lines of improving catching this type of UB? Or 
> alternatively, are there plans of maybe defining it in clang (like a language 
> extension) as @rjmccall points out?

I think this new optimization was mentioned in clang release notes, worth to 
read them. And there is a flag to disable this opt - -fno-finite-loops I think. 
Info about loop finiteness is useful for various optimizations so I dont know 
why clang should promise any behaviour.

Sometime in the future you may compile your code with gcc and boom as well..

And maybe you can use this 
https://clang.llvm.org/extra/clang-tidy/checks/bugprone-infinite-loop.html to 
find infinite loops? Possibly we have compiler remark for it as well (?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D96418#2783541 , @leonardchan wrote:

>> Well, no, I'm afraid it is actually clear that that code does have UB 
>> according to the C++ standard.  Perhaps you mean that it *shouldn't* have 
>> UB, or that Clang should define its behavior despite the standard.
>>
>> I might agree with you that I don't see the value in using this stronger 
>> rule in C++, but I think it would help to understand the problem a little 
>> better.  I assume this is causing problems for a less trivial test case?  Or 
>> do you really have code that's relying on that loop not terminating?
>
> I see. I guess it's good (and bad) that this discovered this UB in our code 
> base. The example I posted is almost exactly what's in our test case. For 
> this particular one, we need a non-terminating thread, so a thread_create 
> function is passed `do_nothing`. Locally, we could get around this by using 
> something like inline assembly to avoid UB.

FWIW, you want an atomic access, something that is explicitly avoiding the UB 
while "busy waiting". Not just some inline assembly that tries to "hide the 
fact" it's UB.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D103142: [clang][clangd] Use reverse header map lookup in suggestPathToFileForDiagnostics

2021-05-26 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Naively, this sounds like it could be a non-trivial tax on build times. But it 
looks like it's only called in Clang from `Sema::diagnoseMissingImport`, which 
only happens on error anyway.




Comment at: clang/unittests/Lex/HeaderMapTest.cpp:9
 
-#include "clang/Basic/CharInfo.h"
-#include "clang/Lex/HeaderMap.h"
-#include "clang/Lex/HeaderMapTypes.h"
+#include "HeaderMapTestUtils.h"
 #include "llvm/ADT/SmallString.h"

Splitting this out seems like a great idea, but please split it out to a 
separate prep commit that's NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103142

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


[PATCH] D103218: [Fuchsia][CMake] Add missing include path.

2021-05-26 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
haowei added reviewers: phosek, mcgrathr, leonardchan, gulfem.
Herald added subscribers: cryptoad, mgorny.
haowei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds include path for missing header files from "sync". This patch 
also fixes the build failures caused by scudo introduced in D103200 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103218

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -145,7 +145,7 @@
   set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
   set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
   foreach(target 
i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/fdio/include")
+set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} 
-I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
 set(FUCHSIA_${target}_LINKER_FLAGS 
"-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
 set(FUCHSIA_${target}_SYSROOT 
"${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
   endforeach()


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -145,7 +145,7 @@
   set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
   set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
   foreach(target i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/fdio/include")
+set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
 set(FUCHSIA_${target}_LINKER_FLAGS "-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
 set(FUCHSIA_${target}_SYSROOT "${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
   endforeach()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-26 Thread ksyx via Phabricator via cfe-commits
ksyx added a comment.

So it seems the better way to do this would definitely by adding a subextension 
as the spec had changed. But I'd like  also to ask how will GCC deal with this 
option, and should we make this option an alias to turn off M extension and 
turn on ZMMul extension?


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

https://reviews.llvm.org/D102839

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


[PATCH] D103142: [clang][clangd] Use reverse header map lookup in suggestPathToFileForDiagnostics

2021-05-26 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added subscribers: JDevlieghere, vsapsai.
bruno added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:1851
 
-
-  return path::convert_to_slash(File.drop_front(BestPrefixLength));
+  // Try resolving resulting filaname via reverse search in header maps,
+  // key from header name is user prefered name for the include file.

-> `filename`



Comment at: clang/lib/Lex/HeaderSearch.cpp:1855
+  for (unsigned I = 0; I != SearchDirs.size(); ++I) {
+if (SearchDirs[I].isHeaderMap()) {
+  StringRef SpelledFilename =

Can we save some dir scanning time by adding this logic to the previous loop? 
Shouldn't get hard to read if you early `continue` for each failed condition.



Comment at: clang/lib/Lex/HeaderSearch.cpp:1859
+  if (!SpelledFilename.empty()) {
+Filename = SpelledFilename;
+break;

I guess one of the rationale behind this change is that whatever is consuming 
your diagnostics is expecting the hmap key entry as an actionable path they 
could use.

I wonder whether other consumers of `suggestPathToFileForDiagnostics` expect an 
actual mapped value or just don't care. If the former, this might be better 
under some flag.

@dexonsmith @vsapsai @JDevlieghere @arphaman how does this relate with what you 
expect out of `suggestPathToFileForDiagnostics`? (If at all).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103142

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


[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-26 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

In D101191#2782963 , @rupprecht wrote:

> The issue I'm seeing seems more directly caused by SLP vectorization, as it 
> goes away with `-fno-slp-vectorize`. This patch merely unblocks that bad 
> optimization AFAICT.

Filed as http://llvm.org/PR50500


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-26 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

> Well, no, I'm afraid it is actually clear that that code does have UB 
> according to the C++ standard.  Perhaps you mean that it *shouldn't* have UB, 
> or that Clang should define its behavior despite the standard.
>
> I might agree with you that I don't see the value in using this stronger rule 
> in C++, but I think it would help to understand the problem a little better.  
> I assume this is causing problems for a less trivial test case?  Or do you 
> really have code that's relying on that loop not terminating?

I see. I guess it's good (and bad) that this discovered this UB in our code 
base. The example I posted is almost exactly what's in our test case. For this 
particular one, we need a non-terminating thread, so a thread_create function 
is passed `do_nothing`. Locally, we could get around this by using something 
like inline assembly to avoid UB.

(Potentially deviating from this patch) While an infinite loop may be UB 
according to the standard, it's also something fairly common that can be in a 
lot of code bases. Although it may be an unintended side-effect, it still seems 
a bit abrupt that we found about this UB from this patch rather than ubsan or a 
compiler diagnostic. Are there any plans in the future for something along the 
lines of improving catching this type of UB? Or alternatively, are there plans 
of maybe defining it in clang (like a language extension) as @rjmccall points 
out?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348121.
erichkeane marked 4 inline comments as done.
erichkeane added a comment.

Ok, this should get me up to date!  Fixed a bunch of the comments referring to 
'expression', added LangOpts::isSYCL, and changed it to DiscriminatorOverride.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,215 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(Func); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(Func); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of 

[PATCH] D102736: Fix tmp files being left on Windows builds.

2021-05-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

I think this look good. Adrian, are your concerns addressed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102736

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-26 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

I saw some bots failure for preinit.c:

  FAIL: ScudoStandalone-i386 :: preinit.c (768 of 856)
   TEST 'ScudoStandalone-i386 :: preinit.c' FAILED 

  Script:
  --
  : 'RUN: at line 1';  
/b/sanitizer-x86_64-linux/build/clang_build/./bin/clang   -m32  -pthread -fPIE 
-pie -O0 -UNDEBUG -Wl,--gc-sections 
-resource-dir=/b/sanitizer-x86_64-linux/build/clang_build/./lib/clang/13.0.0/lib/linux/../../
 -fsanitize=scudo 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/scudo/standalone/preinit.c
 -o 
/b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/scudo/standalone/I386LinuxConfig/Output/preinit.c.tmp
  : 'RUN: at line 2';
/b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/scudo/standalone/I386LinuxConfig/Output/preinit.c.tmp
 2>&1
  --
  Exit Code: 139
  
  Command Output (stderr):
  --
  
/b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/scudo/standalone/I386LinuxConfig/Output/preinit.c.script:
 line 2: 20628 Segmentation fault  
/b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/scudo/standalone/I386LinuxConfig/Output/preinit.c.tmp
 2>&1

Do you know what went on with those?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, that seems to work out cleanly.




Comment at: clang/include/clang/AST/Expr.h:2045
+// representation of the type (or type of the expression) in a way that permits
+// us to properly encode information about the SYCL kernels.
+class UniqueStableNameExpr final

erichkeane wrote:
> rjmccall wrote:
> > rjmccall wrote:
> > > Since this is really just for internal use in system headers (right?), is 
> > > there a need for it to be as flexible as this about whether it takes an 
> > > expression or a type?
> > That said, I don't really have a strong objection to supporting either a 
> > type or an expression operand.
> I had responded to this I thought?  I found no good reason to do expression, 
> we can sprinkle decltype around to deal with that, I'll prep a patch to 
> remove the expr bits.
Okay.  So this doesn't really need trailing storage anymore, and the 
documentation needs to be updated to not mention the expression production.



Comment at: clang/include/clang/AST/Mangle.h:174
+  using KernelMangleCallbackTy =
+  llvm::Optional (*)(ASTContext &, const CXXRecordDecl *);
   explicit ItaniumMangleContext(ASTContext , DiagnosticsEngine )

The concept here isn't kernel-specific, and it's not an arbitrary callback.  I 
think it would be better to call this something more generic, like 
DiscriminatorOverride.

Should the argument have to be a record?  Other local declarations can show up 
as e.g. template arguments, like enums or (I think) static local variables.



Comment at: clang/lib/AST/ASTContext.cpp:11689
+  assert((getLangOpts().SYCLIsDevice || getLangOpts().SYCLIsHost) &&
+ "Only valid for SYCL programs");
+  RD = RD->getCanonicalDecl();

Could you add an `isSYCL()` method on LangOpts as a convenience for this?



Comment at: clang/lib/Basic/IdentifierTable.cpp:159
 return KS_Future;
+  if ((LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) && Flags & KEYSYCL)
+return KS_Enabled;

I think people would generally happier if you parenthesized `Flags & KEYSYCL`, 
even though, yes, this does work under C precedence rules.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:196
+  // If the host and device have different C++ ABIs, mark it as the device
+  // mangle context so that the mangling needs to retrieve the additonal
+  // device lambda mangling number instead of the regular host one.

typo: additonal


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

https://reviews.llvm.org/D103112

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-26 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 348116.
hctim added a comment.

Move lit tests behind the cmake guard: 
"if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE)"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,43 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t 

[PATCH] D103195: Add matchers for gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL and EXPECT_CALL

2021-05-26 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo updated this revision to Diff 348113.

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

https://reviews.llvm.org/D103195

Files:
  clang/include/clang/ASTMatchers/GtestMatchers.h
  clang/lib/ASTMatchers/GtestMatchers.cpp
  clang/unittests/ASTMatchers/GtestMatchersTest.cpp

Index: clang/unittests/ASTMatchers/GtestMatchersTest.cpp
===
--- clang/unittests/ASTMatchers/GtestMatchersTest.cpp
+++ clang/unittests/ASTMatchers/GtestMatchersTest.cpp
@@ -42,6 +42,14 @@
 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
 
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
+  GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
+
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+
 #define EXPECT_EQ(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define EXPECT_NE(val1, val2) \
@@ -55,11 +63,29 @@
 #define EXPECT_LT(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
 
+#define ASSERT_THAT(value, matcher) \
+  ASSERT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) \
+  EXPECT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
 #define ASSERT_EQ(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define ASSERT_NE(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
 
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call)\
+  ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr)   \
+  .Setter(nullptr, 0, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
   namespace testing {
   namespace internal {
   class EqHelper {
@@ -96,8 +122,77 @@
   const T2& val2) {
 return 0;
   }
+
+  // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
+  // argument M must be a type that can be converted to a matcher.
+  template 
+  class PredicateFormatterFromMatcher {
+   public:
+explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {}
+
+// This template () operator allows a PredicateFormatterFromMatcher
+// object to act as a predicate-formatter suitable for using with
+// Google Test's EXPECT_PRED_FORMAT1() macro.
+template 
+int operator()(const char* value_text, const T& x) const {
+  return 0;
+}
+
+   private:
+const M matcher_;
+  };
+
+  template 
+  inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher(
+  M matcher) {
+return PredicateFormatterFromMatcher(matcher);
+  }
+
+  bool GetWithoutMatchers() { return false; }
+
+  template 
+  class MockSpec {
+   public:
+MockSpec() {}
+
+bool InternalDefaultActionSetAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+bool InternalExpectedAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+MockSpec operator()(bool, void*) {
+  return *this;
+}
+  };  // class MockSpec
+
   }  // namespace internal
+
+  template 
+  int StrEq(T val) {
+return 0;
+  }
+  template 
+  int Eq(T val) {
+return 0;
+  }
+
   }  // namespace testing
+
+  class Mock {
+public:
+Mock() {}
+testing::internal::MockSpec gmock_TwoArgsMethod(int, int) {
+  return testing::internal::MockSpec();
+}
+testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) {
+  return testing::internal::MockSpec();
+}
+  };  // class Mock
 )cc";
 
 static std::string wrapGtest(llvm::StringRef Input) {
@@ -187,5 +282,137 @@
   matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr(;
 }
 
+TEST(GtestExpectTest, ThatShouldMatchAssertThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { ASSERT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestAssertThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestExpectTest, ThatShouldMatchExpectThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { EXPECT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestExpectThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestOnCallTest, 

[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348109.
erichkeane added a comment.

Woops!  Last update was JUST the changes, and I forgot to squash.  Here is the 
whole patch.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,215 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(Func); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(Func); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F2{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation 

[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348108.
erichkeane added a comment.
Herald added subscribers: phosek, aheejin, dschuff.

Replace the DeviceLambdaManglingNumber mechanism with the callback mechanism.

Hopefully this is what you were thinking @rjmccall.


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

https://reviews.llvm.org/D103112

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaSYCL.cpp

Index: clang/lib/Sema/SemaSYCL.cpp
===
--- clang/lib/Sema/SemaSYCL.cpp
+++ clang/lib/Sema/SemaSYCL.cpp
@@ -65,16 +65,17 @@
 }
 
 void Sema::AddSYCLKernelLambda(const FunctionDecl *FD) {
-  auto ShouldMangleCallback = [](ASTContext , const CXXRecordDecl *RD) {
-// We ALWAYS want to descend into the lambda mangling for these.
-return true;
+  auto MangleCallback =
+  [](ASTContext , const CXXRecordDecl *RD) -> llvm::Optional {
+Ctx.AddSYCLKernelNamingDecl(RD);
+// We always want to go into the lambda mangling (skipping the unnamed
+// struct version), so make sure we return a value here.
+return 1;
   };
-  auto MangleCallback = [](ASTContext , const CXXRecordDecl *RD,
-   raw_ostream &) { Ctx.AddSYCLKernelNamingDecl(RD); };
 
   QualType Ty = GetSYCLKernelObjectType(FD);
   std::unique_ptr Ctx{ItaniumMangleContext::create(
-  Context, Context.getDiagnostics(), ShouldMangleCallback, MangleCallback)};
+  Context, Context.getDiagnostics(), MangleCallback)};
   llvm::raw_null_ostream Out;
   Ctx->mangleTypeName(Ty, Out);
 }
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -191,12 +191,27 @@
   return ((Twine("__cuda") + Twine(FuncName)).str());
 }
 
+static std::unique_ptr InitDeviceMC(CodeGenModule ) {
+  // If the host and device have different C++ ABIs, mark it as the device
+  // mangle context so that the mangling needs to retrieve the additonal
+  // device lambda mangling number instead of the regular host one.
+  if (CGM.getContext().getAuxTargetInfo() &&
+  CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  CGM.getContext().getAuxTargetInfo()->getCXXABI().isItaniumFamily()) {
+return std::unique_ptr(
+CGM.getContext().createDeviceMangleContext(
+*CGM.getContext().getAuxTargetInfo()));
+  }
+
+  return std::unique_ptr(CGM.getContext().createMangleContext(
+  CGM.getContext().getAuxTargetInfo()));
+}
+
 CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule )
 : CGCUDARuntime(CGM), Context(CGM.getLLVMContext()),
   TheModule(CGM.getModule()),
   RelocatableDeviceCode(CGM.getLangOpts().GPURelocatableDeviceCode),
-  DeviceMC(CGM.getContext().createMangleContext(
-  CGM.getContext().getAuxTargetInfo())) {
+  DeviceMC(InitDeviceMC(CGM)) {
   CodeGen::CodeGenTypes  = CGM.getTypes();
   ASTContext  = CGM.getContext();
 
@@ -207,14 +222,6 @@
   CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
   VoidPtrTy = cast(Types.ConvertType(Ctx.VoidPtrTy));
   VoidPtrPtrTy = VoidPtrTy->getPointerTo();
-  if (CGM.getContext().getAuxTargetInfo()) {
-// If the host and device have different C++ ABIs, mark it as the device
-// mangle context so that the mangling needs to retrieve the additonal
-// device lambda mangling number instead of the regular host one.
-DeviceMC->setDeviceMangleContext(
-CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
-CGM.getContext().getAuxTargetInfo()->getCXXABI().isItaniumFamily());
-  }
 }
 
 llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const {
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -125,20 +125,15 @@
   typedef std::pair DiscriminatorKeyTy;
   llvm::DenseMap Discriminator;
   llvm::DenseMap Uniquifier;
-  const ShouldCallKernelCallbackTy ShouldCallKernelCallback = nullptr;
   const KernelMangleCallbackTy KernelMangleCallback = nullptr;
 
-  bool IsDevCtx = false;
   bool NeedsUniqueInternalLinkageNames = false;
 
 public:
-  explicit ItaniumMangleContextImpl(
-  ASTContext , DiagnosticsEngine ,
-  ShouldCallKernelCallbackTy ShouldCallKernelCB,
-  KernelMangleCallbackTy KernelCB)
-  : ItaniumMangleContext(Context, Diags),
-ShouldCallKernelCallback(ShouldCallKernelCB),
-KernelMangleCallback(KernelCB) {}
+  explicit ItaniumMangleContextImpl(ASTContext ,
+DiagnosticsEngine ,
+KernelMangleCallbackTy KernelCB)
+  : ItaniumMangleContext(Context, Diags), 

[PATCH] D103163: [Matrix] Skip matrix casts checks for class or struct types in C++.

2021-05-26 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 348106.
fhahn added a comment.

Fix IR checks, which broke after adding fields to the struct/class used in the 
tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103163

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp


Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -117,3 +117,33 @@
   m6 = static_cast>(m4);
   m4 = static_cast>(m6);
 }
+
+class Foo {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) 
not viable: no known conversion from 'matrix_4_4' (aka 'float 
__attribute__((matrix_type(4, 4)))') to 'const Foo' for 1st argument}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) 
not viable: no known conversion from 'matrix_4_4' (aka 'float 
__attribute__((matrix_type(4, 4)))') to 'Foo' for 1st argument}}
+
+  int x;
+
+public:
+  Foo();
+  // expected-note@-1 {{candidate constructor not viable: requires 0 
arguments, but 1 was provided}}
+  Foo(matrix_5_5 x);
+  // expected-note@-1 {{candidate constructor not viable: no known conversion 
from 'matrix_4_4' (aka 'float __attribute__((matrix_type(4, 4)))') to 
'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') for 1st 
argument}}
+};
+
+struct Bar {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) 
not viable: no known conversion from 'matrix_4_4' (aka 'unsigned 
int __attribute__((matrix_type(4, 4)))') to 'const Bar' for 1st argument}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) 
not viable: no known conversion from 'matrix_4_4' (aka 'unsigned 
int __attribute__((matrix_type(4, 4)))') to 'Bar' for 1st argument}}
+  // expected-note@-3 {{candidate constructor (the implicit default 
constructor) not viable: requires 0 arguments, but 1 was provided}}
+  float x;
+};
+
+void f5_constructors() {
+  matrix_4_4 m1;
+  matrix_4_4 m5;
+
+  Foo F = Foo(m1);
+  // expected-error@-1 {{no matching conversion for functional-style cast from 
'matrix_4_4' (aka 'float __attribute__((matrix_type(4, 4)))') to 'Foo'}}
+  Bar B = Bar(m5);
+  // expected-error@-1 {{no matching conversion for functional-style cast from 
'matrix_4_4' (aka 'unsigned int __attribute__((matrix_type(4, 
4)))') to 'Bar'}}
+}
Index: clang/test/CodeGenCXX/matrix-casts.cpp
===
--- clang/test/CodeGenCXX/matrix-casts.cpp
+++ clang/test/CodeGenCXX/matrix-casts.cpp
@@ -341,3 +341,33 @@
   matrix_5_5 u;
   u = static_cast>(i);
 }
+
+class Foo {
+  int x[10];
+
+public:
+  Foo(matrix_5_5 x);
+};
+
+Foo class_constructor_matrix_ty(matrix_5_5 m) {
+  // CHECK-LABEL: define void 
@_Z27class_constructor_matrix_tyu11matrix_typeILm5ELm5EiE(%class.Foo* noalias 
sret(%class.Foo) align 4 %agg.result, <25 x i32> %m)
+  // CHECK: [[M:%.*]]  = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:call void @_ZN3FooC1Eu11matrix_typeILm5ELm5EiE(%class.Foo* 
nonnull align 4 dereferenceable(40) %agg.result, <25 x i32> [[M]])
+  // CHECK-NEXT:ret void
+
+  return Foo(m);
+}
+
+struct Bar {
+  float x[10];
+  Bar(matrix_4_4 x);
+};
+
+Bar struct_constructor_matrix_ty(matrix_4_4 m) {
+  // CHECK-LABEL: define void 
@_Z28struct_constructor_matrix_tyu11matrix_typeILm4ELm4EfE(%struct.Bar* noalias 
sret(%struct.Bar) align 4 %agg.result, <16 x float> %m)
+  // CHECK: [[M:%.*]] = load <16 x float>, <16 x float>* {{.*}}, align 
4
+  // CHECK-NEXT:call void 
@_ZN3BarC1Eu11matrix_typeILm4ELm4EfE(%struct.Bar* nonnull align 4 
dereferenceable(40) %agg.result, <16 x float> [[M]])
+  // CHECK-NEXT:ret void
+
+  return Bar(m);
+}
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2665,8 +2665,13 @@
   return;
   }
 
-  if (DestType->getAs() ||
-  SrcExpr.get()->getType()->getAs()) {
+  // If the destination types is not a class or struct type and either the
+  // destination or source type is a matrix type, perform & check a matrix 
cast.
+  // If the destination type is a class or struct, check against their
+  // constructors later.
+  if (!DestType->isStructureOrClassType() &&
+  (DestType->getAs() ||
+   SrcExpr.get()->getType()->getAs())) {
 if (Self.CheckMatrixCast(OpRange, DestType, SrcExpr.get()->getType(), 
Kind))
   SrcExpr = ExprError();
 return;


Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -117,3 +117,33 @@
   m6 = static_cast>(m4);
   m4 = static_cast>(m6);
 }
+

[PATCH] D103163: [Matrix] Skip matrix casts checks for class or struct types in C++.

2021-05-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Thanks, this looks good to me! The existing tests are failing but seems like 
they are not difficult to fix. Once those are fixed, I will mark this as 
accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103163

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


[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Overall looks good, though I've got one more question.




Comment at: clang/test/SemaCUDA/device-use-host-var.cu:90
+  const int _const_var = global_const_var;
   const int _constexpr_var = global_constexpr_var;
   *out = ref_host_var;

What happens if we have  `const int _foo = 
something_we_cant_emit_on_device;`?
Both if ref_foo is and isn't used from device code.




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

https://reviews.llvm.org/D103108

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


[PATCH] D103195: Add matchers for gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL and EXPECT_CALL

2021-05-26 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo updated this revision to Diff 348095.

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

https://reviews.llvm.org/D103195

Files:
  clang/include/clang/ASTMatchers/GtestMatchers.h
  clang/lib/ASTMatchers/GtestMatchers.cpp
  clang/unittests/ASTMatchers/GtestMatchersTest.cpp

Index: clang/unittests/ASTMatchers/GtestMatchersTest.cpp
===
--- clang/unittests/ASTMatchers/GtestMatchersTest.cpp
+++ clang/unittests/ASTMatchers/GtestMatchersTest.cpp
@@ -42,6 +42,14 @@
 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
 
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
+  GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
+
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+
 #define EXPECT_EQ(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define EXPECT_NE(val1, val2) \
@@ -55,11 +63,29 @@
 #define EXPECT_LT(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
 
+#define ASSERT_THAT(value, matcher) \
+  ASSERT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) \
+  EXPECT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
 #define ASSERT_EQ(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define ASSERT_NE(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
 
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call)\
+  ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr)   \
+  .Setter(nullptr, 0, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
   namespace testing {
   namespace internal {
   class EqHelper {
@@ -96,8 +122,77 @@
   const T2& val2) {
 return 0;
   }
+
+  // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
+  // argument M must be a type that can be converted to a matcher.
+  template 
+  class PredicateFormatterFromMatcher {
+   public:
+explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {}
+
+// This template () operator allows a PredicateFormatterFromMatcher
+// object to act as a predicate-formatter suitable for using with
+// Google Test's EXPECT_PRED_FORMAT1() macro.
+template 
+int operator()(const char* value_text, const T& x) const {
+  return 0;
+}
+
+   private:
+const M matcher_;
+  };
+
+  template 
+  inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher(
+  M matcher) {
+return PredicateFormatterFromMatcher(matcher);
+  }
+
+  bool GetWithoutMatchers() { return false; }
+
+  template 
+  class MockSpec {
+   public:
+MockSpec() {}
+
+bool InternalDefaultActionSetAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+bool InternalExpectedAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+MockSpec operator()(bool, void*) {
+  return *this;
+}
+  };  // class MockSpec
+
   }  // namespace internal
+
+  template 
+  int StrEq(T val) {
+return 0;
+  }
+  template 
+  int Eq(T val) {
+return 0;
+  }
+
   }  // namespace testing
+
+  class Mock {
+public:
+Mock() {}
+testing::internal::MockSpec gmock_TwoArgsMethod(int, int) {
+  return testing::internal::MockSpec();
+}
+testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) {
+  return testing::internal::MockSpec();
+}
+  };  // class Mock
 )cc";
 
 static std::string wrapGtest(llvm::StringRef Input) {
@@ -187,5 +282,137 @@
   matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr(;
 }
 
+TEST(GtestExpectTest, ThatShouldMatchAssertThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { ASSERT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestAssertThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestExpectTest, ThatShouldMatchExpectThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { EXPECT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestExpectThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestOnCallTest, 

[PATCH] D103195: Add matchers for gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL and EXPECT_CALL

2021-05-26 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo updated this revision to Diff 348094.

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

https://reviews.llvm.org/D103195

Files:
  clang/include/clang/ASTMatchers/GtestMatchers.h
  clang/lib/ASTMatchers/GtestMatchers.cpp
  clang/unittests/ASTMatchers/GtestMatchersTest.cpp

Index: clang/unittests/ASTMatchers/GtestMatchersTest.cpp
===
--- clang/unittests/ASTMatchers/GtestMatchersTest.cpp
+++ clang/unittests/ASTMatchers/GtestMatchersTest.cpp
@@ -42,6 +42,14 @@
 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
 
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
+  GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
+
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+
 #define EXPECT_EQ(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define EXPECT_NE(val1, val2) \
@@ -55,11 +63,29 @@
 #define EXPECT_LT(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
 
+#define ASSERT_THAT(value, matcher) \
+  ASSERT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) \
+  EXPECT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
 #define ASSERT_EQ(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define ASSERT_NE(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
 
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call)\
+  ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr)   \
+  .Setter(nullptr, 0, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
   namespace testing {
   namespace internal {
   class EqHelper {
@@ -96,8 +122,77 @@
   const T2& val2) {
 return 0;
   }
+
+  // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
+  // argument M must be a type that can be converted to a matcher.
+  template 
+  class PredicateFormatterFromMatcher {
+   public:
+explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {}
+
+// This template () operator allows a PredicateFormatterFromMatcher
+// object to act as a predicate-formatter suitable for using with
+// Google Test's EXPECT_PRED_FORMAT1() macro.
+template 
+int operator()(const char* value_text, const T& x) const {
+  return 0;
+}
+
+   private:
+const M matcher_;
+  };
+
+  template 
+  inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher(
+  M matcher) {
+return PredicateFormatterFromMatcher(matcher);
+  }
+
+  bool GetWithoutMatchers() { return false; }
+
+  template 
+  class MockSpec {
+   public:
+MockSpec() {}
+
+bool InternalDefaultActionSetAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+bool InternalExpectedAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+MockSpec operator()(bool, void*) {
+  return *this;
+}
+  };  // class MockSpec
+
   }  // namespace internal
+
+  template 
+  int StrEq(T val) {
+return 0;
+  }
+  template 
+  int Eq(T val) {
+return 0;
+  }
+
   }  // namespace testing
+
+  class Mock {
+public:
+Mock() {}
+testing::internal::MockSpec gmock_TwoArgsMethod(int, int) {
+  return testing::internal::MockSpec();
+}
+testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) {
+  return testing::internal::MockSpec();
+}
+  };  // class Mock
 )cc";
 
 static std::string wrapGtest(llvm::StringRef Input) {
@@ -187,5 +282,137 @@
   matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr(;
 }
 
+TEST(GtestExpectTest, ThatShouldMatchAssertThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { ASSERT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestAssertThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestExpectTest, ThatShouldMatchExpectThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { EXPECT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestExpectThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestOnCallTest, 

[PATCH] D103195: Add matchers for gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL and EXPECT_CALL

2021-05-26 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo updated this revision to Diff 348093.

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

https://reviews.llvm.org/D103195

Files:
  clang/include/clang/ASTMatchers/GtestMatchers.h
  clang/lib/ASTMatchers/GtestMatchers.cpp
  clang/unittests/ASTMatchers/GtestMatchersTest.cpp

Index: clang/unittests/ASTMatchers/GtestMatchersTest.cpp
===
--- clang/unittests/ASTMatchers/GtestMatchersTest.cpp
+++ clang/unittests/ASTMatchers/GtestMatchersTest.cpp
@@ -42,6 +42,14 @@
 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
 
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
+  GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
+
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+
 #define EXPECT_EQ(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define EXPECT_NE(val1, val2) \
@@ -55,11 +63,29 @@
 #define EXPECT_LT(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
 
+#define ASSERT_THAT(value, matcher) \
+  ASSERT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) \
+  EXPECT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
 #define ASSERT_EQ(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define ASSERT_NE(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
 
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call)\
+  ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr)   \
+  .Setter(nullptr, 0, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
   namespace testing {
   namespace internal {
   class EqHelper {
@@ -96,8 +122,77 @@
   const T2& val2) {
 return 0;
   }
+
+  // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
+  // argument M must be a type that can be converted to a matcher.
+  template 
+  class PredicateFormatterFromMatcher {
+   public:
+explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {}
+
+// This template () operator allows a PredicateFormatterFromMatcher
+// object to act as a predicate-formatter suitable for using with
+// Google Test's EXPECT_PRED_FORMAT1() macro.
+template 
+int operator()(const char* value_text, const T& x) const {
+  return 0;
+}
+
+   private:
+const M matcher_;
+  };
+
+  template 
+  inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher(
+  M matcher) {
+return PredicateFormatterFromMatcher(matcher);
+  }
+
+  bool GetWithoutMatchers() { return false; }
+
+  template 
+  class MockSpec {
+   public:
+MockSpec() {}
+
+bool InternalDefaultActionSetAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+bool InternalExpectedAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+MockSpec operator()(bool, void*) {
+  return *this;
+}
+  };  // class MockSpec
+
   }  // namespace internal
+
+  template 
+  int StrEq(T val) {
+return 0;
+  }
+  template 
+  int Eq(T val) {
+return 0;
+  }
+
   }  // namespace testing
+
+  class Mock {
+public:
+Mock() {}
+testing::internal::MockSpec gmock_TwoArgsMethod(int, int) {
+  return testing::internal::MockSpec();
+}
+testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) {
+  return testing::internal::MockSpec();
+}
+  };  // class Mock
 )cc";
 
 static std::string wrapGtest(llvm::StringRef Input) {
@@ -187,5 +282,137 @@
   matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr(;
 }
 
+TEST(GtestExpectTest, ThatShouldMatchAssertThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { ASSERT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestAssertThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestExpectTest, ThatShouldMatchExpectThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { EXPECT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestExpectThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestOnCallTest, 

[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 348092.
lichray added a comment.

Fix typo in docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return true;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return false;
+  }
   if ((Left.is(tok::greater) && Right.is(tok::greater)) ||
   (Left.is(tok::less) && Right.is(tok::less)))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) 

[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:568
+}
+// Check whether a variable has an allowed initializer for a CUDA device side
+// variable with global storage. \p VD may be a host variable to be checked for

tra wrote:
> Nit: add an empty line to separate from the preceding function.
done



Comment at: clang/lib/Sema/SemaCUDA.cpp:718
+ *this, VD, CICK_DeviceOrConstant {
 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
   }

tra wrote:
> One of the issues with automatic promotion I've ran into in the past is that 
> `__constant__` is a very limited resource.
> 
> It would be nearly impossible for the end user to predict how much 
> `__constant__` space is available for their own use and if we use too much, 
> the failure would only manifest at runtime when we fail to load the GPU code. 
> That will be hard to troubleshoot.
> 
> We may need to add some sort of safeguard and report an error when we see too 
> much __constant__ data for a given GPU.
> That would have to be done somewhere at the end of the compilation pipeline.
> 
> It's not likely to affect any/many users yet so it can be done later. It's 
> probably worth a comment and a TODO here in case someone does run into this.
> 
added a TODO



Comment at: clang/test/CodeGenCUDA/device-use-host-var.cu:44
+const A const_array[] = {0, 0, 0, 6};
+const char const_str[] = "xyz";
 

tra wrote:
> It would be great to have a test which verifies that we only emit const 
> variables that we need.
> It would be bad if we'd end up with *all* host-side consts in the GPU binary.
> 
added test for that



Comment at: clang/test/SemaCUDA/device-use-host-var.cu:82
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in 
__device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in 
__device__ function}}

tra wrote:
> This diag is a bit misleading now. While it's technically true that we're not 
> allowed to refer to a host variables from device in general, the real reason 
> it's not allowed in *this* case is that the variable has a non-empty ctor.
> 
> I wonder if we could add a note pointing that out. Otherwise it would be 
> rather confusing why I can access other host vars few lines above, but not 
> here.
> 
done


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

https://reviews.llvm.org/D103108

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


[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-26 Thread Luís Marques via Phabricator via cfe-commits
luismarques added a comment.

In D102839#2782557 , @kito-cheng 
wrote:

> We have Zmmul extension in the ISA spec now, that's equivalent to `-mno-div` 
> , so I suggest we should go forward to implement that extension rather than 
> `-mno-div`.
> https://github.com/riscv/riscv-isa-manual/pull/648

Thanks for bringing that to our attention, Kito. I had missed that recent PR 
and its discussion.
If the GNU ecosystem intends to move away from `-mno-div` soonish then Zmmul is 
for sure the way to go. I don't see enough benefit for LLVM to add a stop-gap 
compatibility option.


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

https://reviews.llvm.org/D102839

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


[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 348089.
yaxunl marked 4 inline comments as done.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D103108

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCUDA/device-use-host-var.cu
  clang/test/SemaCUDA/device-use-host-var.cu

Index: clang/test/SemaCUDA/device-use-host-var.cu
===
--- clang/test/SemaCUDA/device-use-host-var.cu
+++ clang/test/SemaCUDA/device-use-host-var.cu
@@ -5,35 +5,61 @@
 
 #include "Inputs/cuda.h"
 
+int func();
+
 struct A {
   int x;
   static int host_var;
 };
 
-int A::host_var;
+int A::host_var; // dev-note {{host variable declared here}}
 
 namespace X {
-  int host_var;
+  int host_var; // dev-note {{host variable declared here}}
 }
 
-static int static_host_var;
+// struct with non-empty ctor.
+struct B1 {
+  int x;
+  B1() { x = 1; }
+};
+
+// struct with non-empty dtor.
+struct B2 {
+  int x;
+  B2() {}
+  ~B2() { x = 0; }
+};
+
+static int static_host_var; // dev-note {{host variable declared here}}
 
 __device__ int global_dev_var;
 __constant__ int global_constant_var;
 __shared__ int global_shared_var;
 
-int global_host_var;
+int global_host_var; // dev-note 8{{host variable declared here}}
 const int global_const_var = 1;
 constexpr int global_constexpr_var = 1;
 
-int global_host_array[2] = {1, 2};
+int global_host_array[2] = {1, 2}; // dev-note {{host variable declared here}}
 const int global_const_array[2] = {1, 2};
 constexpr int global_constexpr_array[2] = {1, 2};
 
-A global_host_struct_var{1};
+A global_host_struct_var{1}; // dev-note 2{{host variable declared here}}
 const A global_const_struct_var{1};
 constexpr A global_constexpr_struct_var{1};
 
+// Check const host var initialized with non-empty ctor is not allowed in
+// device function.
+const B1 b1; // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
+// Check const host var having non-empty dtor is not allowed in device function.
+const B2 b2; // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
+// Check const host var initialized by non-constant initializer is not allowed
+// in device function.
+const int b3 = func(); // dev-note {{const variable cannot be emitted on device side due to dynamic initialization}}
+
 template
 __global__ void kernel(F f) { f(); } // dev-note2 {{called by 'kernel<(lambda}}
 
@@ -53,11 +79,14 @@
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
   *out = global_const_var;
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in __device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in __device__ function}}
+  *out = b3; // dev-error {{reference to __host__ variable 'b3' in __device__ function}}
   global_host_var = 1; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
 
   // Check reference of non-constexpr host variables are not allowed.
   int _host_var = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int _const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int _const_var = global_const_var;
   const int _constexpr_var = global_constexpr_var;
   *out = ref_host_var;
   *out = ref_constexpr_var;
@@ -65,18 +94,18 @@
 
   // Check access member of non-constexpr struct type host variable is not allowed.
   *out = global_host_struct_var.x; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
-  *out = global_const_struct_var.x; // dev-error {{reference to __host__ variable 'global_const_struct_var' in __device__ function}}
+  *out = global_const_struct_var.x;
   *out = global_constexpr_struct_var.x;
   global_host_struct_var.x = 1; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
 
   // Check address taking of non-constexpr host variables is not allowed.
   int *p = _host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int *cp = _const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int *cp = _const_var;
   const int *cp2 = _constexpr_var;
 
   // Check access elements of non-constexpr host array is not allowed.
   *out = global_host_array[1]; // dev-error {{reference to __host__ variable 'global_host_array' in __device__ function}}
-  *out = global_const_array[1]; // dev-error {{reference to __host__ 

[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek updated this revision to Diff 348081.
eddy-geek added a comment.

*Trigger rebuild (windows failed to git clone)*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.AutoTypeNameLength, value: '22'}]}" \
+// RUN:   -- -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 6;
+
+void autotype() {
+  Val Teas[N];
+  for (int I = 0; I < N; ++I) {
+Teas[I].g();
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (Val & Tea : Teas)
+  // CHECK-FIXES-NEXT: Tea.g();
+
+  // NonTriviallyCopyable has length 21 < 22
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const NonTriviallyCopyable & I : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+
+  // TriviallyCopyableButBig has length 23 > 22
+  const TriviallyCopyableButBig Big[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & I : Big)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -121,23 +121,23 @@
 Reverse Iterator Support
 
 
-The converter is also capable of transforming iterator loops which use 
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box 
-this will automatically happen in C++20 mode using the ``ranges`` library, 
-however the check can be configured to work without C++20 by specifying a 
+The converter is also capable of transforming iterator loops which use
+``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the ``ranges`` library,
+however the check can be configured to work without C++20 by specifying a
 function to reverse a range and optionally the header file where that function
 lives.
 
 .. option:: UseCxx20ReverseRanges
-  
-   When set to true convert loops when in C++20 or later mode using 
+
+   When set to true convert loops when in C++20 or later mode using
``std::ranges::reverse_view``.
Default value is ``true``.
 
 .. option:: MakeReverseRangeFunction
 
-   Specify the function used to reverse an iterator pair, the function should 
-   accept a class with ``rbegin`` and ``rend`` methods and return a 
+   Specify the function used to reverse an iterator pair, the function should
+   accept a class with ``rbegin`` and ``rend`` methods and return a
class with ``begin`` and ``end`` methods methods that call the ``rbegin`` and
``rend`` methods respectively. Common examples are ``ranges::reverse_view``
and ``llvm::reverse``.
@@ -146,10 +146,10 @@
 .. option:: MakeReverseRangeHeader
 
Specifies the header file where :option:`MakeReverseRangeFunction` is
-   declared. For the previous examples this option would be set to 
+   declared. For the previous examples this option would be set to
``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
-   If this is an empty string and :option:`MakeReverseRangeFunction` is set, 
-   the check will proceed on the assumption that the function is already 
+   If this is an empty string and :option:`MakeReverseRangeFunction` is set,
+   the check will proceed on the assumption that the function is already
available in the translation unit.
This can be wrapped in angle brackets to signify to add the include as a
system include.
@@ -160,6 +160,13 @@
A string specifying which include-style is used, `llvm` or `google`. Default
is `llvm`.
 
+AutoTypeNameLength option
+
+
+If TypeName length is strictly above this threshold, `auto` will be used.
+
+The 

[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek updated this revision to Diff 348080.
eddy-geek added a comment.

*Trigger rebuild (windows failed to git clone)*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

Files:
  
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py


Index: 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -87,7 +87,7 @@
 
   # Load the database and extract all files.
   database = json.load(open(os.path.join(build_path, db_path)))
-  files = [entry['file'] for entry in database]
+  files = [os.path.join(entry['directory'], entry['file']) for entry in 
database]
 
   # Filter out .rc files on Windows. CMake includes them for some reason.
   files = [f for f in files if not f.endswith('.rc')]


Index: clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -87,7 +87,7 @@
 
   # Load the database and extract all files.
   database = json.load(open(os.path.join(build_path, db_path)))
-  files = [entry['file'] for entry in database]
+  files = [os.path.join(entry['directory'], entry['file']) for entry in database]
 
   # Filter out .rc files on Windows. CMake includes them for some reason.
   files = [f for f in files if not f.endswith('.rc')]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103204: [Format] New BreakInheritanceList style AfterComma

2021-05-26 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.
lichray requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This inheritance list style has been widely adopted by Symantec,
a division of Broadcom Inc. It breaks after the commas that
separate the base-specifiers:

  class Derived : public Base1,
  private Base2
  {
  };


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103204

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return false;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return true;
+  }
+  if (Right.is(TT_InheritanceComma)) {
+if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
+  return true;
+else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma)
+  return false;
+  }
   if ((Left.is(tok::greater) && Right.is(tok::greater)) ||
   (Left.is(tok::less) && Right.is(tok::less)))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma
   };
 
   /// The inheritance list style to use.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1999,6 +1999,15 @@
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after and commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the
@@ -4058,12 +4061,18 @@
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
-  if (Left.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return false;
-  if (Right.is(TT_InheritanceComma) &&
-  Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma)
-return true;
+  if (Left.is(TT_InheritanceComma)) {
+if 

[PATCH] D103131: support debug info for alias variable

2021-05-26 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In D103131#2780997 , @dblaikie wrote:

> Looks like GCC emits aliases as a `DW_TAG_variable` without a location, not 
> as a `DW_TAG_imported_declaration`

and marks it external; this works only because gdb will look up the ELF symbol 
when you say `p newname`.  I've known debuggers that wouldn't do that.  I think 
the `DW_TAG_imported_declaration` is making fewer assumptions about debugger 
behavior.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4954
+  llvm::DIScope *DContext = getDeclContextDescriptor(D);
+  if (llvm::DINode *Target = getDeclarationOrDefinition(D)) {
+auto Loc = D->getLocation();

The variables Unit and DContext are used only inside the `if` so I would put 
those two variables inside the `if` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103131

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348060.
erichkeane added a comment.

Remove 'expression' form per suggestion.  Still need to do the 
device-mangling-number removal/rewrite business.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,215 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(Func); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(Func); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F2{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function 

[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-05-26 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 348052.
mibintc retitled this revision from "[clang] RFC Support new builtin 
__arithmetic_fence to control floating point optimization, and new clang option 
fprotect-parens" to "[clang] Add support for new builtin __arithmetic_fence to 
control floating point optimization, and new clang option fprotect-parens".
mibintc edited the summary of this revision.
mibintc added a comment.

Rebased the patch.  The parent patch is updated and corrected as well, and 
tests can run end-to-end.

Ready for your code review, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/arithmetic-fence-builtin.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Sema/arithmetic-fence-builtin.c
  clang/tools/clang-import-test/clang-import-test.cpp

Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -208,7 +208,7 @@
   TargetInfo *TI = TargetInfo::CreateTargetInfo(
   Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
   Ins->setTarget(TI);
-  Ins->getTarget().adjust(Ins->getLangOpts());
+  Ins->getTarget().adjust(Ins->getDiagnostics(), Ins->getLangOpts());
   Ins->createFileManager();
   Ins->createSourceManager(Ins->getFileManager());
   Ins->createPreprocessor(TU_Complete);
Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- /dev/null
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
+// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
+// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
+// RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+#ifndef PPC
+int v;
+template  T addT(T a, T b) {
+  T *q = __arithmetic_fence();
+  // expected-error@-1 {{operand of type 'float *' where floating, complex or a vector of such types is required ('float *' invalid)}}
+  // expected-error@-2 {{operand of type 'int *' where floating, complex or a vector of such types is required ('int *' invalid)}}
+  return __arithmetic_fence(a + b);
+  // expected-error@-1 {{operand of type 'int' where floating, complex or a vector of such types is required ('int' invalid)}}
+}
+int addit(int a, int b) {
+  float x, y;
+  typedef struct {
+int a, b;
+  } stype;
+  stype s;
+  s = __arithmetic_fence(s);// expected-error {{operand of type 'stype' where floating, complex or a vector of such types is required ('stype' invalid)}}
+  x = __arithmetic_fence(x, y); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  // Complex is supported.
+  _Complex double cd, cd1;
+  cd = __arithmetic_fence(cd1);
+  // Vector is supported.
+  typedef float __v4hi __attribute__((__vector_size__(8)));
+  __v4hi vec1, vec2;
+  vec1 = __arithmetic_fence(vec2);
+
+  v = __arithmetic_fence(a + b); // expected-error {{operand of type 'int' where floating, complex or a vector of such types is required ('int' invalid)}}
+  float f = addT(a, b);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  int i = addT(1, 2);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  constexpr float d = 1.0 + 2.0;
+  constexpr float c = __arithmetic_fence(1.0 + 2.0);
+  // expected-error@-1 {{constexpr variable 'c' must be initialized by a constant expression}}
+  return 0;
+}
+// expected-error@+1 {{static_assert expression is not an integral constant expression}}
+static_assert( __arithmetic_fence(1.0 + 2.0), "message" );
+#else
+float addit(float a, float b) {
+  return __arithmetic_fence(a+b); // expected-error {{builtin is not supported on this target}}
+}
+#endif
+//PPC: 

[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-26 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

The issue I'm seeing seems more directly caused by SLP vectorization, as it 
goes away with `-fno-slp-vectorize`. This patch merely unblocks that bad 
optimization AFAICT.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[PATCH] D99675: [llvm][clang] Create new intrinsic llvm.arith.fence to control FP optimization at expression level

2021-05-26 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 348046.
mibintc retitled this revision from "RFC [llvm][clang] Create new intrinsic 
llvm.arith.fence to control FP optimization at expression level" to 
"[llvm][clang] Create new intrinsic llvm.arith.fence to control FP optimization 
at expression level".
mibintc edited the summary of this revision.
mibintc added a comment.

Rebased to ToT. It fixes the previous illegal type lowering problems. It also 
updates the tests to show the functionality in a better way as well as fixes a 
newly found problem.

Ready for your code review and +1

We think this patch provides basic functionality for the intrinsic, and 
enhancements can be added in future patches.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99675

Files:
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/CodeGen/SelectionDAGISel.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Support/TargetOpcodes.def
  llvm/include/llvm/Target/Target.td
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/test/CodeGen/X86/arithmetic_fence.ll

Index: llvm/test/CodeGen/X86/arithmetic_fence.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/arithmetic_fence.ll
@@ -0,0 +1,161 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+fma | FileCheck %s --check-prefix=X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+fma | FileCheck %s --check-prefix=X64
+
+define float @f1(float %a, float %b, float %c) {
+; X86-LABEL: f1:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %eax
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; X86-NEXT:vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; X86-NEXT:vfmadd213ss {{.*#+}} xmm1 = (xmm0 * xmm1) + mem
+; X86-NEXT:vmovss %xmm1, (%esp)
+; X86-NEXT:flds (%esp)
+; X86-NEXT:popl %eax
+; X86-NEXT:.cfi_def_cfa_offset 4
+; X86-NEXT:retl
+;
+; X64-LABEL: f1:
+; X64:   # %bb.0:
+; X64-NEXT:vfmadd213ss {{.*#+}} xmm0 = (xmm1 * xmm0) + xmm2
+; X64-NEXT:retq
+  %mul = fmul fast float %b, %a
+  %add = fadd fast float %mul, %c
+  ret float %add
+}
+
+define float @f2(float %a, float %b, float %c) {
+; X86-LABEL: f2:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %eax
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; X86-NEXT:vmulss {{[0-9]+}}(%esp), %xmm0, %xmm0
+; X86-NEXT:#ARITH_FENCE
+; X86-NEXT:vaddss {{[0-9]+}}(%esp), %xmm0, %xmm0
+; X86-NEXT:vmovss %xmm0, (%esp)
+; X86-NEXT:flds (%esp)
+; X86-NEXT:popl %eax
+; X86-NEXT:.cfi_def_cfa_offset 4
+; X86-NEXT:retl
+;
+; X64-LABEL: f2:
+; X64:   # %bb.0:
+; X64-NEXT:vmulss %xmm0, %xmm1, %xmm0
+; X64-NEXT:#ARITH_FENCE
+; X64-NEXT:vaddss %xmm2, %xmm0, %xmm0
+; X64-NEXT:retq
+  %mul = fmul fast float %b, %a
+  %tmp = call float @llvm.arithmetic.fence.f32(float %mul)
+  %add = fadd fast float %tmp, %c
+  ret float %add
+}
+
+define double @f3(double %a) {
+; X86-LABEL: f3:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %ebp
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:.cfi_offset %ebp, -8
+; X86-NEXT:movl %esp, %ebp
+; X86-NEXT:.cfi_def_cfa_register %ebp
+; X86-NEXT:andl $-8, %esp
+; X86-NEXT:subl $8, %esp
+; X86-NEXT:vmovsd {{.*#+}} xmm0 = mem[0],zero
+; X86-NEXT:vmulsd {{\.LCPI[0-9]+_[0-9]+}}, %xmm0, %xmm0
+; X86-NEXT:vmovsd %xmm0, (%esp)
+; X86-NEXT:fldl (%esp)
+; X86-NEXT:movl %ebp, %esp
+; X86-NEXT:popl %ebp
+; X86-NEXT:.cfi_def_cfa %esp, 4
+; X86-NEXT:retl
+;
+; X64-LABEL: f3:
+; X64:   # %bb.0:
+; X64-NEXT:vmulsd {{.*}}(%rip), %xmm0, %xmm0
+; X64-NEXT:retq
+  %1 = fadd fast double %a, %a
+  %2 = fadd fast double %a, %a
+  %3 = fadd fast double %1, %2
+  ret double %3
+}
+
+define double @f4(double %a) {
+; X86-LABEL: f4:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %ebp
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:.cfi_offset %ebp, -8
+; X86-NEXT:movl %esp, %ebp
+; X86-NEXT:.cfi_def_cfa_register %ebp
+; X86-NEXT:andl $-8, %esp
+; X86-NEXT:subl $8, %esp
+; X86-NEXT:vmovsd {{.*#+}} xmm0 = mem[0],zero
+; X86-NEXT:vaddsd %xmm0, %xmm0, %xmm0
+; X86-NEXT:vmovapd %xmm0, %xmm1
+; X86-NEXT:#ARITH_FENCE
+; X86-NEXT:vaddsd %xmm0, %xmm1, %xmm0
+; X86-NEXT:vmovsd %xmm0, (%esp)
+; X86-NEXT:fldl (%esp)
+; X86-NEXT:movl %ebp, %esp
+; X86-NEXT:popl %ebp
+; X86-NEXT:.cfi_def_cfa %esp, 4
+; X86-NEXT:retl
+;

[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek updated this revision to Diff 348047.
eddy-geek added a comment.

*Trigger rebuild (windows failed to git clone)*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.AutoTypeNameLength, value: '22'}]}" \
+// RUN:   -- -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 6;
+
+void autotype() {
+  Val Teas[N];
+  for (int I = 0; I < N; ++I) {
+Teas[I].g();
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (Val & Tea : Teas)
+  // CHECK-FIXES-NEXT: Tea.g();
+
+  // NonTriviallyCopyable has length 21 < 22
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const NonTriviallyCopyable & I : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+
+  // TriviallyCopyableButBig has length 23 > 22
+  const TriviallyCopyableButBig Big[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & I : Big)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -121,23 +121,23 @@
 Reverse Iterator Support
 
 
-The converter is also capable of transforming iterator loops which use 
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box 
-this will automatically happen in C++20 mode using the ``ranges`` library, 
-however the check can be configured to work without C++20 by specifying a 
+The converter is also capable of transforming iterator loops which use
+``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the ``ranges`` library,
+however the check can be configured to work without C++20 by specifying a
 function to reverse a range and optionally the header file where that function
 lives.
 
 .. option:: UseCxx20ReverseRanges
-  
-   When set to true convert loops when in C++20 or later mode using 
+
+   When set to true convert loops when in C++20 or later mode using
``std::ranges::reverse_view``.
Default value is ``true``.
 
 .. option:: MakeReverseRangeFunction
 
-   Specify the function used to reverse an iterator pair, the function should 
-   accept a class with ``rbegin`` and ``rend`` methods and return a 
+   Specify the function used to reverse an iterator pair, the function should
+   accept a class with ``rbegin`` and ``rend`` methods and return a
class with ``begin`` and ``end`` methods methods that call the ``rbegin`` and
``rend`` methods respectively. Common examples are ``ranges::reverse_view``
and ``llvm::reverse``.
@@ -146,10 +146,10 @@
 .. option:: MakeReverseRangeHeader
 
Specifies the header file where :option:`MakeReverseRangeFunction` is
-   declared. For the previous examples this option would be set to 
+   declared. For the previous examples this option would be set to
``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
-   If this is an empty string and :option:`MakeReverseRangeFunction` is set, 
-   the check will proceed on the assumption that the function is already 
+   If this is an empty string and :option:`MakeReverseRangeFunction` is set,
+   the check will proceed on the assumption that the function is already
available in the translation unit.
This can be wrapped in angle brackets to signify to add the include as a
system include.
@@ -160,6 +160,13 @@
A string specifying which include-style is used, `llvm` or `google`. Default
is `llvm`.
 
+AutoTypeNameLength option
+
+
+If TypeName length is strictly above this threshold, `auto` will be used.
+
+The 

[PATCH] D103195: Add matchers for gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL and EXPECT_CALL

2021-05-26 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo created this revision.
zhaomo added a reviewer: ymandel.
Herald added a subscriber: mstorsjo.
zhaomo requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds support for matching gtest's ASSERT_THAT, EXPECT_THAT, ON_CALL 
and EXPECT_CALL macros.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103195

Files:
  clang/include/clang/ASTMatchers/GtestMatchers.h
  clang/lib/ASTMatchers/GtestMatchers.cpp
  clang/unittests/ASTMatchers/GtestMatchersTest.cpp

Index: clang/unittests/ASTMatchers/GtestMatchersTest.cpp
===
--- clang/unittests/ASTMatchers/GtestMatchersTest.cpp
+++ clang/unittests/ASTMatchers/GtestMatchersTest.cpp
@@ -42,6 +42,14 @@
 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
 
+#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
+  GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
+
+#define EXPECT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
+#define ASSERT_PRED_FORMAT1(pred_format, v1) \
+  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
+
 #define EXPECT_EQ(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define EXPECT_NE(val1, val2) \
@@ -55,11 +63,29 @@
 #define EXPECT_LT(val1, val2) \
 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
 
+#define ASSERT_THAT(value, matcher) \
+  ASSERT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+#define EXPECT_THAT(value, matcher) \
+  EXPECT_PRED_FORMAT1(  \
+  ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
+
 #define ASSERT_EQ(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
 #define ASSERT_NE(val1, val2) \
 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
 
+#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call)\
+  ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
+ nullptr)   \
+  .Setter(nullptr, 0, #mock_expr, #call)
+
+#define ON_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
+
+#define EXPECT_CALL(obj, call) \
+  GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
+
   namespace testing {
   namespace internal {
   class EqHelper {
@@ -96,8 +122,77 @@
   const T2& val2) {
 return 0;
   }
+
+  // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
+  // argument M must be a type that can be converted to a matcher.
+  template 
+  class PredicateFormatterFromMatcher {
+   public:
+explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {}
+
+// This template () operator allows a PredicateFormatterFromMatcher
+// object to act as a predicate-formatter suitable for using with
+// Google Test's EXPECT_PRED_FORMAT1() macro.
+template 
+int operator()(const char* value_text, const T& x) const {
+  return 0;
+}
+
+   private:
+const M matcher_;
+  };
+
+  template 
+  inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher(
+  M matcher) {
+return PredicateFormatterFromMatcher(matcher);
+  }
+
+  bool GetWithoutMatchers() { return false; }
+
+  template 
+  class MockSpec {
+   public:
+MockSpec() {}
+
+bool InternalDefaultActionSetAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+bool InternalExpectedAt(
+const char* file, int line, const char* obj, const char* call) {
+  return false;
+}
+
+MockSpec operator()(bool, void*) {
+  return *this;
+}
+  };  // class MockSpec
+
   }  // namespace internal
+
+  template 
+  int StrEq(T val) {
+return 0;
+  }
+  template 
+  int Eq(T val) {
+return 0;
+  }
+
   }  // namespace testing
+
+  class Mock {
+public:
+Mock() {}
+testing::internal::MockSpec gmock_TwoArgsMethod(int, int) {
+  return testing::internal::MockSpec();
+}
+testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) {
+  return testing::internal::MockSpec();
+}
+  };  // class Mock
 )cc";
 
 static std::string wrapGtest(llvm::StringRef Input) {
@@ -187,5 +282,137 @@
   matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr(;
 }
 
+TEST(GtestExpectTest, ThatShouldMatchAssertThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;
+void Test() { ASSERT_THAT(2, Eq(2)); }
+  )cc";
+  EXPECT_TRUE(matches(
+  wrapGtest(Input),
+  gtestAssertThat(
+  expr(), callExpr(callee(functionDecl(hasName("::testing::Eq")));
+}
+
+TEST(GtestExpectTest, ThatShouldMatchExpectThat) {
+  std::string Input = R"cc(
+using ::testing::Eq;

[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2443
+  // Computes a unique stable name for the type of the given expression.
+  constexpr const char * __builtin_unique_stable_name( expression );
+

rjmccall wrote:
> These need to be updated for the rename.  You should just grep the patch for 
> the old name.
Looks like there was 1 more in addition to this that Aaron hadn't found! It'll 
be fixed in the next version.



Comment at: clang/include/clang/AST/Expr.h:2045
+// representation of the type (or type of the expression) in a way that permits
+// us to properly encode information about the SYCL kernels.
+class UniqueStableNameExpr final

rjmccall wrote:
> rjmccall wrote:
> > Since this is really just for internal use in system headers (right?), is 
> > there a need for it to be as flexible as this about whether it takes an 
> > expression or a type?
> That said, I don't really have a strong objection to supporting either a type 
> or an expression operand.
I had responded to this I thought?  I found no good reason to do expression, we 
can sprinkle decltype around to deal with that, I'll prep a patch to remove the 
expr bits.



Comment at: clang/lib/AST/ItaniumMangle.cpp:1977
+  if (Context.getShouldCallKernelCallback()(Context.getASTContext(), Lambda)) {
+Context.getKernelMangleCallback()(Context.getASTContext(), Lambda, Out);
+Out << '_';

rjmccall wrote:
> erichkeane wrote:
> > rjmccall wrote:
> > > This basically assumes that the callback is only changing the 
> > > discriminator.  And in fact, we already have this "device lambda mangling 
> > > number" concept that we use in different modes with similar problems to 
> > > SYCL.  Can we unify these and just provide one way for the context to opt 
> > > in to overriding discriminators?
> > I was unable to find a way to get the device lambda mangling number to work 
> > in this situation unfortunately, it seems to have significantly different 
> > needs from what we need here.  
> > 
> > Part of what SYCL needs is the ability to 'recalculate' this number as we 
> > discover that a lambda is participating in naming a SYCL kernel. The 
> > DeviceLambdaMangling mechanism requires that it be evaluated as we are 
> > generating the lambdas.  I couldn't find a mechanism to update them after 
> > the fact that wasn't messier than the callback mechanism.
> > 
> > As far as assuming that we are changing only the discriminator, that ends 
> > up being required since this is the only location where a lambda mangling 
> > is 'customizable', and we want it to remain demanglable.
> > 
> Sorry, I didn't mean that you should try to make the SYCL logic just set a 
> device mangling number; in fact, I meant almost the reverse.  The device 
> mangling number is ultimately a MangleContext-driven override of the 
> discriminator choice, just like you're trying to add for SYCL.  For SYCL, 
> you're adding a generalized callback mechanism, which seems good.  What I'm 
> asking is that you go ahead and move  the existing device-mangling logic in 
> the mangler over to that callback mechanism, so that instead of setting an 
> `isDeviceMangleContext()` bit on the MangleContext, that code will install an 
> discriminator-override callback that returns the device lambda mangling 
> number.  Then we have one mechanism instead of two.
> 
> I think the right API for that callback is just to have it return an 
> `Optional`, and then you use the normal discriminator if it returns 
> `None`.  And it should take an arbitrary `Decl*` so that it can override 
> discriminators on non-lambda local declarations if it wants.
I think that should work... I'll look into it, thanks for the clarification!


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

https://reviews.llvm.org/D103112

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


[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Miguel Ojeda via Phabricator via cfe-commits
ojeda added inline comments.



Comment at: clang/include/clang/Basic/Features.def:52
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)

melver wrote:
> ojeda wrote:
> > melver wrote:
> > > aaron.ballman wrote:
> > > > I think this is likely fine, but wanted to call it out explicitly in 
> > > > case others had opinions.
> > > > 
> > > > `FEATURE` is supposed to be used for standard features and `EXTENSION` 
> > > > used for Clang extensions. This is an extension, not a standard 
> > > > feature, so it's wrong in that way. However, it's following the same 
> > > > pattern as the other sanitizers which is consistent. I think 
> > > > consistently wrong is better than inconsistently right for this case, 
> > > > but I have no idea how others feel.
> > > Yes, you are correct of course, and I was pondering the same thing.
> > > 
> > > In the end I'd like all sanitizers be queryable via `__has_feature()` and 
> > > not have this be the odd one out requiring `__has_extension()` as that's 
> > > also going to lead to confusion/errors on the user side. 
> > Perhaps add both, deprecate `__has_feature()` for non-standard features 
> > like these ones, and remove them after a couple releases? :)
> > 
> > Regardless of the way, //any// is better than a version check, so thanks!
> I think realistically we have to pick one, and that's the one we keep for all 
> eternity. :-)
> 
> Because if we deprecate/remove something, some codebases would require 
> version checks, which is a non-starter again. Not every project is on top of 
> what their compilers deprecates/removes. (And, unlike the Linux kernel, some 
> codebases just never upgrade their compiler requirements, but still expect 
> newer compilers to work.)
> 
> So if we want consistency with other sanitizers, it has to be 
> `__has_feature()`.
Agreed, any friction on updates is bad for users and will annoy someone 
somewhere.

Having said that, any serious project migrating to a new toolchain needs to 
revalidate regardless. And, after all, these are non-standard features. So in 
practice I do not think it would matter too much if the deprecation notice is 
long enough (several years).

But I may be saying something completely stupid, since I do not even know if 
Clang promises forever-stability for options, like `rustc` does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

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


[PATCH] D102663: Bug 49633 - Added warning for static inline global and namespaced declarations for c++17+

2021-05-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Should we also warn about `inline` variables in anonymous namespaces?




Comment at: clang/lib/Sema/SemaDecl.cpp:7127
 << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
+} else if (SC == SC_Static && DC->isFileContext() &&
+   getLangOpts().CPlusPlus17) {

serberoth wrote:
> erichkeane wrote:
> > First, what about this is C++17 specific?  The inline and static 
> > relationship is older than C++17, right?
> > 
> > Also, are you sure that the warning/stuff in the 'else' isn't still 
> > valuable?
> Perhaps I misunderstood something in the bug write-up, the component for the 
> ticket is C++17.  Also there is the warning that `inline variables are a 
> C++17 extension` that appears when you use the inline keyword on a variable 
> (regardless of the appearance of the static keyword).  I suppose that does 
> not necessarily mean we cannot simply show both warnings, and maybe that is 
> the right thing to do.  I felt that was not really necessary because of the 
> other warning.
> 
> As for the other warnings in the else the one is the warning that I mentioned 
> (which only applies when the C++17 standard is not applied, and the other is 
> a C++14 compatibility warning which states:
> "inline variables are incompatible with C++ standards before C++17"
> 
> You can see the messages for those diagnostic message here:
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L1467
> 
> Please let me know if I am still missing something with how this diagnostic 
> was supposed to apply and where.  Thank you.
This diagnostic should be independent of the ext / compat diagnostic below. 
This patch currently removes the `-Wc++14-compat` warning for `static inline 
int n;`, which would be a behavior regression for that warning.

Moving this check inside the `else` block a few lines below, and removing the 
check for `CPlusPlus17`, would seem reasonable. We accept `inline` variables in 
earlier language modes as an extension, and  we should still warn in that case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102663

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2443
+  // Computes a unique stable name for the type of the given expression.
+  constexpr const char * __builtin_unique_stable_name( expression );
+

These need to be updated for the rename.  You should just grep the patch for 
the old name.



Comment at: clang/include/clang/AST/Expr.h:2045
+// representation of the type (or type of the expression) in a way that permits
+// us to properly encode information about the SYCL kernels.
+class UniqueStableNameExpr final

rjmccall wrote:
> Since this is really just for internal use in system headers (right?), is 
> there a need for it to be as flexible as this about whether it takes an 
> expression or a type?
That said, I don't really have a strong objection to supporting either a type 
or an expression operand.



Comment at: clang/lib/AST/ItaniumMangle.cpp:1977
+  if (Context.getShouldCallKernelCallback()(Context.getASTContext(), Lambda)) {
+Context.getKernelMangleCallback()(Context.getASTContext(), Lambda, Out);
+Out << '_';

erichkeane wrote:
> rjmccall wrote:
> > This basically assumes that the callback is only changing the 
> > discriminator.  And in fact, we already have this "device lambda mangling 
> > number" concept that we use in different modes with similar problems to 
> > SYCL.  Can we unify these and just provide one way for the context to opt 
> > in to overriding discriminators?
> I was unable to find a way to get the device lambda mangling number to work 
> in this situation unfortunately, it seems to have significantly different 
> needs from what we need here.  
> 
> Part of what SYCL needs is the ability to 'recalculate' this number as we 
> discover that a lambda is participating in naming a SYCL kernel. The 
> DeviceLambdaMangling mechanism requires that it be evaluated as we are 
> generating the lambdas.  I couldn't find a mechanism to update them after the 
> fact that wasn't messier than the callback mechanism.
> 
> As far as assuming that we are changing only the discriminator, that ends up 
> being required since this is the only location where a lambda mangling is 
> 'customizable', and we want it to remain demanglable.
> 
Sorry, I didn't mean that you should try to make the SYCL logic just set a 
device mangling number; in fact, I meant almost the reverse.  The device 
mangling number is ultimately a MangleContext-driven override of the 
discriminator choice, just like you're trying to add for SYCL.  For SYCL, 
you're adding a generalized callback mechanism, which seems good.  What I'm 
asking is that you go ahead and move  the existing device-mangling logic in the 
mangler over to that callback mechanism, so that instead of setting an 
`isDeviceMangleContext()` bit on the MangleContext, that code will install an 
discriminator-override callback that returns the device lambda mangling number. 
 Then we have one mechanism instead of two.

I think the right API for that callback is just to have it return an 
`Optional`, and then you use the normal discriminator if it returns 
`None`.  And it should take an arbitrary `Decl*` so that it can override 
discriminators on non-lambda local declarations if it wants.


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

https://reviews.llvm.org/D103112

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


[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek updated this revision to Diff 348038.
eddy-geek added a comment.

Fix test output


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.AutoTypeNameLength, value: '22'}]}" \
+// RUN:   -- -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 6;
+
+void autotype() {
+  Val Teas[N];
+  for (int I = 0; I < N; ++I) {
+Teas[I].g();
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (Val & Tea : Teas)
+  // CHECK-FIXES-NEXT: Tea.g();
+
+  // NonTriviallyCopyable has length 21 < 22
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const NonTriviallyCopyable & I : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+
+  // TriviallyCopyableButBig has length 23 > 22
+  const TriviallyCopyableButBig Big[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & I : Big)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -121,23 +121,23 @@
 Reverse Iterator Support
 
 
-The converter is also capable of transforming iterator loops which use 
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box 
-this will automatically happen in C++20 mode using the ``ranges`` library, 
-however the check can be configured to work without C++20 by specifying a 
+The converter is also capable of transforming iterator loops which use
+``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the ``ranges`` library,
+however the check can be configured to work without C++20 by specifying a
 function to reverse a range and optionally the header file where that function
 lives.
 
 .. option:: UseCxx20ReverseRanges
-  
-   When set to true convert loops when in C++20 or later mode using 
+
+   When set to true convert loops when in C++20 or later mode using
``std::ranges::reverse_view``.
Default value is ``true``.
 
 .. option:: MakeReverseRangeFunction
 
-   Specify the function used to reverse an iterator pair, the function should 
-   accept a class with ``rbegin`` and ``rend`` methods and return a 
+   Specify the function used to reverse an iterator pair, the function should
+   accept a class with ``rbegin`` and ``rend`` methods and return a
class with ``begin`` and ``end`` methods methods that call the ``rbegin`` and
``rend`` methods respectively. Common examples are ``ranges::reverse_view``
and ``llvm::reverse``.
@@ -146,10 +146,10 @@
 .. option:: MakeReverseRangeHeader
 
Specifies the header file where :option:`MakeReverseRangeFunction` is
-   declared. For the previous examples this option would be set to 
+   declared. For the previous examples this option would be set to
``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
-   If this is an empty string and :option:`MakeReverseRangeFunction` is set, 
-   the check will proceed on the assumption that the function is already 
+   If this is an empty string and :option:`MakeReverseRangeFunction` is set,
+   the check will proceed on the assumption that the function is already
available in the translation unit.
This can be wrapped in angle brackets to signify to add the include as a
system include.
@@ -160,6 +160,13 @@
A string specifying which include-style is used, `llvm` or `google`. Default
is `llvm`.
 
+AutoTypeNameLength option
+
+
+If TypeName length is strictly above this threshold, `auto` will be used.
+
+The default is 0, so `auto` will be 

[PATCH] D102820: [Clang] Check for returns_nonnull when deciding to add allocation null checks

2021-05-26 Thread Di Mo via Phabricator via cfe-commits
modimo added a comment.

@rsmith @lebedev.ri thoughts on adding this directly to FE generation? As 
mentioned this isn't strictly needed and the BE can elide the check but we can 
also not emit it to save on AST/IR processing cost.


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

https://reviews.llvm.org/D102820

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


[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek updated this revision to Diff 348028.
eddy-geek added a comment.

Fix test build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.AutoTypeNameLength, value: '22'}]}" \
+// RUN:   -- -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 6;
+
+void autotype() {
+  Val Teas[N];
+  for (int I = 0; I < N; ++I) {
+Teas[I].g();
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (Tea & Tea : Teas)
+  // CHECK-FIXES-NEXT: Tea.g();
+
+  // NonTriviallyCopyable has length 21 < 22
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const NonTriviallyCopyable & I : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+
+  // TriviallyCopyableButBig has length 23 > 22
+  const TriviallyCopyableButBig Big[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & I : Big)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -121,23 +121,23 @@
 Reverse Iterator Support
 
 
-The converter is also capable of transforming iterator loops which use 
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box 
-this will automatically happen in C++20 mode using the ``ranges`` library, 
-however the check can be configured to work without C++20 by specifying a 
+The converter is also capable of transforming iterator loops which use
+``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the ``ranges`` library,
+however the check can be configured to work without C++20 by specifying a
 function to reverse a range and optionally the header file where that function
 lives.
 
 .. option:: UseCxx20ReverseRanges
-  
-   When set to true convert loops when in C++20 or later mode using 
+
+   When set to true convert loops when in C++20 or later mode using
``std::ranges::reverse_view``.
Default value is ``true``.
 
 .. option:: MakeReverseRangeFunction
 
-   Specify the function used to reverse an iterator pair, the function should 
-   accept a class with ``rbegin`` and ``rend`` methods and return a 
+   Specify the function used to reverse an iterator pair, the function should
+   accept a class with ``rbegin`` and ``rend`` methods and return a
class with ``begin`` and ``end`` methods methods that call the ``rbegin`` and
``rend`` methods respectively. Common examples are ``ranges::reverse_view``
and ``llvm::reverse``.
@@ -146,10 +146,10 @@
 .. option:: MakeReverseRangeHeader
 
Specifies the header file where :option:`MakeReverseRangeFunction` is
-   declared. For the previous examples this option would be set to 
+   declared. For the previous examples this option would be set to
``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
-   If this is an empty string and :option:`MakeReverseRangeFunction` is set, 
-   the check will proceed on the assumption that the function is already 
+   If this is an empty string and :option:`MakeReverseRangeFunction` is set,
+   the check will proceed on the assumption that the function is already
available in the translation unit.
This can be wrapped in angle brackets to signify to add the include as a
system include.
@@ -160,6 +160,13 @@
A string specifying which include-style is used, `llvm` or `google`. Default
is `llvm`.
 
+AutoTypeNameLength option
+
+
+If TypeName length is strictly above this threshold, `auto` will be used.
+
+The default is 0, so `auto` will be 

[PATCH] D103191: [OpenCL] Add support of __opencl_c_program_scope_global_variables feature macro

2021-05-26 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov 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/D103191

Files:
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,46 +1,77 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables -DNO_GENERIC_AS
 static constant int G1 = 0;
 constant int G2 = 0;
-int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
-global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
+int G3 = 0;
+global int G4 = 0;
 
-static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+static float g_implicit_static_var = 0;
 static constant float g_constant_static_var = 0;
-static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static global float g_global_static_var = 0;
+static local float g_local_static_var = 0;
+static private float g_private_static_var = 0;
+static generic float g_generic_static_var = 0;
 
-extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
+extern float g_implicit_extern_var;
 extern constant float g_constant_extern_var;
-extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
-extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
+extern global float g_global_extern_var;
+extern local float g_local_extern_var;
+extern private float g_private_extern_var;
+extern generic float g_generic_extern_var;
+#ifndef __opencl_c_program_scope_global_variables
+// expected-error@-17 {{program scope variable must reside in constant address space}}
+// expected-error@-17 {{program scope variable must reside in constant address space}}
+// expected-error@-16 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{program scope variable must reside in constant address space}}
+// expected-error-re@-15 {{OpenCL C version {{1.2|3.0}} does not support the 'generic' type qualifier}}
+// expected-error@-16 {{program scope variable must reside in constant address space}}
+// expected-error@-15 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error@-14 {{extern variable must reside in constant address space}}
+// expected-error-re@-14 {{OpenCL C version {{1.2|3.0}} does not support the 'generic' type qualifier}}
+// expected-error@-15 {{extern variable must reside in constant address space}}
+#else
+// expected-error@-26 {{program scope variable must reside in global or constant address space}}
+// expected-error@-26 {{program scope variable must reside in global or constant address space}}
+// expected-error@-26 {{OpenCL C version 3.0 does not support the 'generic' type qualifier}}
+// expected-error@-22 {{extern variable must reside in global or constant address space}}
+// expected-error@-22 {{extern variable must 

[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: clang/include/clang/Basic/Features.def:52
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)

ojeda wrote:
> melver wrote:
> > aaron.ballman wrote:
> > > I think this is likely fine, but wanted to call it out explicitly in case 
> > > others had opinions.
> > > 
> > > `FEATURE` is supposed to be used for standard features and `EXTENSION` 
> > > used for Clang extensions. This is an extension, not a standard feature, 
> > > so it's wrong in that way. However, it's following the same pattern as 
> > > the other sanitizers which is consistent. I think consistently wrong is 
> > > better than inconsistently right for this case, but I have no idea how 
> > > others feel.
> > Yes, you are correct of course, and I was pondering the same thing.
> > 
> > In the end I'd like all sanitizers be queryable via `__has_feature()` and 
> > not have this be the odd one out requiring `__has_extension()` as that's 
> > also going to lead to confusion/errors on the user side. 
> Perhaps add both, deprecate `__has_feature()` for non-standard features like 
> these ones, and remove them after a couple releases? :)
> 
> Regardless of the way, //any// is better than a version check, so thanks!
I think realistically we have to pick one, and that's the one we keep for all 
eternity. :-)

Because if we deprecate/remove something, some codebases would require version 
checks, which is a non-starter again. Not every project is on top of what their 
compilers deprecates/removes. (And, unlike the Linux kernel, some codebases 
just never upgrade their compiler requirements, but still expect newer 
compilers to work.)

So if we want consistency with other sanitizers, it has to be `__has_feature()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 348025.
erichkeane marked 7 inline comments as done.
erichkeane added a comment.

Fix comments from aaron.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(F1); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(F2); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F2{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  

[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2413
+(or type of the expression) that is stable across split compilations, mainly to
+support SYCL/Data Parallel C++ language.
+

rjmccall wrote:
> The semantics here seem specific to SYCL.  In fact, if this feature were used 
> in normal code, it would arguably be weird that it changed behavior 
> significantly in SYCL.  I think we should just acknowledge that and make it a 
> feature that's only enabled when SYCL is enabled.  That probably also means 
> renaming it to `__builtin_sycl_unique_stable_name`.
We can live with that, that makes sense to me. 



Comment at: clang/lib/AST/ItaniumMangle.cpp:1977
+  if (Context.getShouldCallKernelCallback()(Context.getASTContext(), Lambda)) {
+Context.getKernelMangleCallback()(Context.getASTContext(), Lambda, Out);
+Out << '_';

rjmccall wrote:
> This basically assumes that the callback is only changing the discriminator.  
> And in fact, we already have this "device lambda mangling number" concept 
> that we use in different modes with similar problems to SYCL.  Can we unify 
> these and just provide one way for the context to opt in to overriding 
> discriminators?
I was unable to find a way to get the device lambda mangling number to work in 
this situation unfortunately, it seems to have significantly different needs 
from what we need here.  

Part of what SYCL needs is the ability to 'recalculate' this number as we 
discover that a lambda is participating in naming a SYCL kernel. The 
DeviceLambdaMangling mechanism requires that it be evaluated as we are 
generating the lambdas.  I couldn't find a mechanism to update them after the 
fact that wasn't messier than the callback mechanism.

As far as assuming that we are changing only the discriminator, that ends up 
being required since this is the only location where a lambda mangling is 
'customizable', and we want it to remain demanglable.




Comment at: clang/lib/Basic/IdentifierTable.cpp:85
 
-  enum {
-KEYC99= 0x1,
-KEYCXX= 0x2,
-KEYCXX11  = 0x4,
-KEYGNU= 0x8,
-KEYMS = 0x10,
-BOOLSUPPORT   = 0x20,
-KEYALTIVEC= 0x40,
-KEYNOCXX  = 0x80,
-KEYBORLAND= 0x100,
-KEYOPENCLC= 0x200,
-KEYC11= 0x400,
-KEYNOMS18 = 0x800,
-KEYNOOPENCL   = 0x1000,
-WCHARSUPPORT  = 0x2000,
-HALFSUPPORT   = 0x4000,
-CHAR8SUPPORT  = 0x8000,
-KEYCONCEPTS   = 0x1,
-KEYOBJC   = 0x2,
-KEYZVECTOR= 0x4,
-KEYCOROUTINES = 0x8,
-KEYMODULES= 0x10,
-KEYCXX20  = 0x20,
-KEYOPENCLCXX  = 0x40,
-KEYMSCOMPAT   = 0x80,
-KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
-KEYALL = (0xff & ~KEYNOMS18 &
-  ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
-  };
-
-  /// How a keyword is treated in the selected standard.
-  enum KeywordStatus {
-KS_Disabled,// Disabled
-KS_Extension,   // Is an extension
-KS_Enabled, // Enabled
-KS_Future   // Is a keyword in future standard
-  };
+enum {
+  KEYC99 = 0x1,

aaron.ballman wrote:
> It looks like you formatted a bit more than you intended to.
Ugh... tis what I get for running clang-format on the whole patch :/


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

https://reviews.llvm.org/D103112

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


[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Miguel Ojeda via Phabricator via cfe-commits
ojeda added inline comments.



Comment at: clang/include/clang/Basic/Features.def:52
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)

melver wrote:
> aaron.ballman wrote:
> > I think this is likely fine, but wanted to call it out explicitly in case 
> > others had opinions.
> > 
> > `FEATURE` is supposed to be used for standard features and `EXTENSION` used 
> > for Clang extensions. This is an extension, not a standard feature, so it's 
> > wrong in that way. However, it's following the same pattern as the other 
> > sanitizers which is consistent. I think consistently wrong is better than 
> > inconsistently right for this case, but I have no idea how others feel.
> Yes, you are correct of course, and I was pondering the same thing.
> 
> In the end I'd like all sanitizers be queryable via `__has_feature()` and not 
> have this be the odd one out requiring `__has_extension()` as that's also 
> going to lead to confusion/errors on the user side. 
Perhaps add both, deprecate `__has_feature()` for non-standard features like 
these ones, and remove them after a couple releases? :)

Regardless of the way, //any// is better than a version check, so thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

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


[PATCH] D103157: Disable misc-no-recursion checking in Clang

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

I like this, since the entire CFE does a ton of recursion on purpose for all 
AST related things.  Please give others time to disagree however :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103157

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


[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Marco Elver via Phabricator via cfe-commits
melver updated this revision to Diff 348021.
melver marked an inline comment as done.
melver added a comment.

s/Since/Because/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Lexer/has_feature_coverage_sanitizer.cpp


Index: clang/test/Lexer/has_feature_coverage_sanitizer.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_coverage_sanitizer.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang -E -fsanitize-coverage=indirect-calls %s -o - | FileCheck 
--check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=inline-8bit-counters %s -o - | FileCheck 
--check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-cmp %s -o - | FileCheck 
--check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-pc %s -o - | FileCheck 
--check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-pc-guard %s -o - | FileCheck 
--check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E  %s -o - | FileCheck --check-prefix=CHECK-NO-SANCOV %s
+
+#if __has_feature(coverage_sanitizer)
+int SancovEnabled();
+#else
+int SancovDisabled();
+#endif
+
+// CHECK-SANCOV: SancovEnabled
+// CHECK-NO-SANCOV: SancovDisabled
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -453,7 +453,7 @@
   CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
   CodeGenOpts.DisableFree = FrontendOpts.DisableFree;
   FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex;
-
+  LangOpts.SanitizeCoverage = CodeGenOpts.hasSanitizeCoverage();
   LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
   LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
   LangOpts.CurrentModule = LangOpts.ModuleName;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -280,6 +280,8 @@
 
   /// Set of enabled sanitizers.
   SanitizerSet Sanitize;
+  /// Is at least one coverage instrumentation type enabled.
+  bool SanitizeCoverage = false;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,7 @@
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
 FEATURE(attribute_availability, true)
Index: clang/docs/SanitizerCoverage.rst
===
--- clang/docs/SanitizerCoverage.rst
+++ clang/docs/SanitizerCoverage.rst
@@ -316,7 +316,9 @@
 ===
 
 It is possible to disable coverage instrumentation for select functions via the
-function attribute ``__attribute__((no_sanitize("coverage")))``.
+function attribute ``__attribute__((no_sanitize("coverage")))``. Because this
+attribute may not be supported by other compilers, it is recommended to use it
+together with ``__has_feature(coverage_sanitizer)``.
 
 Disabling instrumentation without source modification
 =


Index: clang/test/Lexer/has_feature_coverage_sanitizer.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_coverage_sanitizer.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang -E -fsanitize-coverage=indirect-calls %s -o - | FileCheck --check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=inline-8bit-counters %s -o - | FileCheck --check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-cmp %s -o - | FileCheck --check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-pc %s -o - | FileCheck --check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E -fsanitize-coverage=trace-pc-guard %s -o - | FileCheck --check-prefix=CHECK-SANCOV %s
+// RUN: %clang -E  %s -o - | FileCheck --check-prefix=CHECK-NO-SANCOV %s
+
+#if __has_feature(coverage_sanitizer)
+int SancovEnabled();
+#else
+int SancovDisabled();
+#endif
+
+// CHECK-SANCOV: SancovEnabled
+// CHECK-NO-SANCOV: SancovDisabled
Index: clang/lib/Frontend/CompilerInvocation.cpp

[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: clang/include/clang/Basic/Features.def:52
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)

aaron.ballman wrote:
> I think this is likely fine, but wanted to call it out explicitly in case 
> others had opinions.
> 
> `FEATURE` is supposed to be used for standard features and `EXTENSION` used 
> for Clang extensions. This is an extension, not a standard feature, so it's 
> wrong in that way. However, it's following the same pattern as the other 
> sanitizers which is consistent. I think consistently wrong is better than 
> inconsistently right for this case, but I have no idea how others feel.
Yes, you are correct of course, and I was pondering the same thing.

In the end I'd like all sanitizers be queryable via `__has_feature()` and not 
have this be the odd one out requiring `__has_extension()` as that's also going 
to lead to confusion/errors on the user side. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

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


[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-05-26 Thread Fred Grim via Phabricator via cfe-commits
feg208 updated this revision to Diff 348020.
feg208 added a comment.

Still need to fix and added the tests I said I would but the comment tests are 
added


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16367,6 +16367,176 @@
getLLVMStyle());
 }
 
+TEST_F(FormatTest, CatchAlignArrayOfStructures) {
+  auto Style = getLLVMStyle();
+  Style.AlignArrayOfStructures = true;
+  Style.AlignConsecutiveAssignments =
+  FormatStyle::AlignConsecutiveStyle::ACS_Consecutive;
+  Style.AlignConsecutiveDeclarations =
+  FormatStyle::AlignConsecutiveStyle::ACS_Consecutive;
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" }, // first line\n"
+   "{-1, 93463, \"world\" }, // second line\n"
+   "{ 7, 5,\"!!\" }  // third line\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[4] = {\n"
+   "{ 56,23, 21,   \"oh\" }, // first line\n"
+   "{ -1, 93463, 22,   \"my\" }, // second line\n"
+   "{  7, 5,  1, \"goodness\" }  // third line\n"
+   "{234, 5,  1, \"gracious\" }  // fourth line\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[3] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+  verifyFormat("struct test demo[3] = {\n"
+   "{int{56},23, \"hello\" },\n"
+   "{int{-1}, 93463, \"world\" },\n"
+   "{ int{7}, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("demo = std::array{\n"
+   "test{56,23, \"hello\" },\n"
+   "test{-1, 93463, \"world\" },\n"
+   "test{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "#if X\n"
+   "{-1, 93463, \"world\" },\n"
+   "#endif\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("test demo[] = {\n"
+   "{ 7,23,\n"
+   "\"hello world i am a very long line that really, in any\"\n"
+   "\"just world, ought to be split over multiple lines\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{56, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("return GradForUnaryCwise(g, {\n"
+   "{{\"sign\"}, \"Sign\",  "
+   "{\"x\", \"dy\"} },\n"
+   "{  {\"dx\"},  \"Mul\", {\"dy\""
+   ", \"sign\"} },\n"
+   "});\n",
+   Style);
+
+  Style.ColumnLimit = 0;
+  EXPECT_EQ(
+  "test demo[] = {\n"
+  "{56,23, \"hello world i am a very long line that really, "
+  "in any just world, ought to be split over multiple lines\" },\n"
+  "{-1, 93463,  "
+  " \"world\" },\n"
+  "{ 7, 5,  "
+  "\"!!\" 

[clang] f7c5c0d - Revert "[Scudo] Make -fsanitize=scudo use standalone. Migrate tests."

2021-05-26 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2021-05-26T10:50:26-07:00
New Revision: f7c5c0d87b8ae5e55006fd3a31994cd68d64f102

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

LOG: Revert "[Scudo] Make -fsanitize=scudo use standalone. Migrate tests."

This reverts commit 694d8cbed06a8a809c34ae07f4e3e89ab252.

Broke the QEMU sanitizer bots due to a missing header dependency. This
actually needs to be fixed on the bot-side, but for now reverting this
patch until I can fix up the bot.

Added: 

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
compiler-rt/test/scudo/aligned-new.cpp
compiler-rt/test/scudo/alignment.c
compiler-rt/test/scudo/dealloc-race.c
compiler-rt/test/scudo/double-free.cpp
compiler-rt/test/scudo/fsanitize.c
compiler-rt/test/scudo/interface.cpp
compiler-rt/test/scudo/lit.cfg.py
compiler-rt/test/scudo/lit.site.cfg.py.in
compiler-rt/test/scudo/malloc.cpp
compiler-rt/test/scudo/memalign.c
compiler-rt/test/scudo/mismatch.cpp
compiler-rt/test/scudo/options.cpp
compiler-rt/test/scudo/overflow.c
compiler-rt/test/scudo/preinit.c
compiler-rt/test/scudo/preload.cpp
compiler-rt/test/scudo/quarantine.c
compiler-rt/test/scudo/random_shuffle.cpp
compiler-rt/test/scudo/realloc.cpp
compiler-rt/test/scudo/rss.c
compiler-rt/test/scudo/secondary.c
compiler-rt/test/scudo/sized-delete.cpp
compiler-rt/test/scudo/sizes.cpp
compiler-rt/test/scudo/stats.c
compiler-rt/test/scudo/symbols.test
compiler-rt/test/scudo/threads.c
compiler-rt/test/scudo/tsd_destruction.c
compiler-rt/test/scudo/valloc.c

Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/fuchsia.c
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
compiler-rt/test/scudo/CMakeLists.txt
compiler-rt/test/scudo/standalone/CMakeLists.txt

Removed: 

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
compiler-rt/test/scudo/standalone/aligned-new.cpp
compiler-rt/test/scudo/standalone/alignment.c
compiler-rt/test/scudo/standalone/dealloc-race.c
compiler-rt/test/scudo/standalone/double-free.cpp
compiler-rt/test/scudo/standalone/fsanitize.c
compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
compiler-rt/test/scudo/standalone/lit.cfg.py
compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
compiler-rt/test/scudo/standalone/malloc.cpp
compiler-rt/test/scudo/standalone/memalign.c
compiler-rt/test/scudo/standalone/mismatch.cpp
compiler-rt/test/scudo/standalone/options.cpp
compiler-rt/test/scudo/standalone/preinit.c
compiler-rt/test/scudo/standalone/preload.cpp
compiler-rt/test/scudo/standalone/random_shuffle.cpp
compiler-rt/test/scudo/standalone/sized-delete.cpp
compiler-rt/test/scudo/standalone/stats.c
compiler-rt/test/scudo/standalone/tsd_destruction.c



diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 79779052418ad..b74a9fe3eb927 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -809,7 +809,10 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
 SharedRuntimes.push_back("ubsan_standalone");
 }
 if (SanArgs.needsScudoRt() && SanArgs.linkRuntimes()) {
-  SharedRuntimes.push_back("scudo_standalone");
+  if (SanArgs.requiresMinimalRuntime())
+SharedRuntimes.push_back("scudo_minimal");
+  else
+SharedRuntimes.push_back("scudo");
 }
 if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes())
   SharedRuntimes.push_back("tsan");
@@ -900,9 +903,15 @@ collectSanitizerRuntimes(const ToolChain , const 
ArgList ,
 RequiredSymbols.push_back("__sanitizer_stats_register");
   }
   if (!SanArgs.needsSharedRt() && SanArgs.needsScudoRt() && 
SanArgs.linkRuntimes()) {
-StaticRuntimes.push_back("scudo_standalone");
-if 

[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:568
+}
+// Check whether a variable has an allowed initializer for a CUDA device side
+// variable with global storage. \p VD may be a host variable to be checked for

Nit: add an empty line to separate from the preceding function.



Comment at: clang/lib/Sema/SemaCUDA.cpp:718
+ *this, VD, CICK_DeviceOrConstant {
 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
   }

One of the issues with automatic promotion I've ran into in the past is that 
`__constant__` is a very limited resource.

It would be nearly impossible for the end user to predict how much 
`__constant__` space is available for their own use and if we use too much, the 
failure would only manifest at runtime when we fail to load the GPU code. That 
will be hard to troubleshoot.

We may need to add some sort of safeguard and report an error when we see too 
much __constant__ data for a given GPU.
That would have to be done somewhere at the end of the compilation pipeline.

It's not likely to affect any/many users yet so it can be done later. It's 
probably worth a comment and a TODO here in case someone does run into this.




Comment at: clang/test/CodeGenCUDA/device-use-host-var.cu:44
+const A const_array[] = {0, 0, 0, 6};
+const char const_str[] = "xyz";
 

It would be great to have a test which verifies that we only emit const 
variables that we need.
It would be bad if we'd end up with *all* host-side consts in the GPU binary.




Comment at: clang/test/SemaCUDA/device-use-host-var.cu:82
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in 
__device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in 
__device__ function}}

This diag is a bit misleading now. While it's technically true that we're not 
allowed to refer to a host variables from device in general, the real reason 
it's not allowed in *this* case is that the variable has a non-empty ctor.

I wonder if we could add a note pointing that out. Otherwise it would be rather 
confusing why I can access other host vars few lines above, but not here.



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

https://reviews.llvm.org/D103108

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


[PATCH] D103159: [Clang] Enable __has_feature(coverage_sanitizer)

2021-05-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added inline comments.



Comment at: clang/docs/SanitizerCoverage.rst:319
 It is possible to disable coverage instrumentation for select functions via the
-function attribute ``__attribute__((no_sanitize("coverage")))``.
+function attribute ``__attribute__((no_sanitize("coverage")))``. Since this
+attribute may not be supported by other compilers, it is recommended to use it





Comment at: clang/include/clang/Basic/Features.def:52
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)

I think this is likely fine, but wanted to call it out explicitly in case 
others had opinions.

`FEATURE` is supposed to be used for standard features and `EXTENSION` used for 
Clang extensions. This is an extension, not a standard feature, so it's wrong 
in that way. However, it's following the same pattern as the other sanitizers 
which is consistent. I think consistently wrong is better than inconsistently 
right for this case, but I have no idea how others feel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103159

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name as __builtin_sycl_unique_stable_name

2021-05-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2408
+``__builtin_sycl_unique_stable_name``
+
+

Underlines look off now, so this likely causes Sphinx warnings.



Comment at: clang/docs/LanguageExtensions.rst:2440-2443
+  constexpr const char * __builtin_unique_stable_name( type-id );
+
+  // Computes a unique stable name for the type of the given expression.
+  constexpr const char * __builtin_unique_stable_name( expression );





Comment at: clang/include/clang/AST/ASTContext.h:3177
+  /// name all the SYCL kernels in the translation unit, so that we can get the
+  /// correct kernel name, as well as implement __builtin_unique_stable_name.
+  llvm::DenseMaphttps://reviews.llvm.org/D103112/new/

https://reviews.llvm.org/D103112

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


[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek added a comment.

I haven't been able to build locally so far -- OOM on my machine, not sure if I 
can do something lighter than:

  cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang\;clang-tools-extra 
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD 
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../llvm
  ninja check-clang-tools

but I 'm still looking for feedback in the meantime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103188

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


[PATCH] D103188: [clang-tidy] modernize-loop-convert: limit use of auto

2021-05-26 Thread Edward O via Phabricator via cfe-commits
eddy-geek created this revision.
Herald added a subscriber: xazax.hun.
eddy-geek requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixes bug 35694 
Adds option AutoTypeNameLength, default 0 (keep current behaviour).
Note that the default could be set to 5 in the future
(like for modernize-use-auto.MinTypeNameLength).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103188

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-auto.cpp
@@ -0,0 +1,37 @@
+// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.AutoTypeNameLength, value: '22'}]}" \
+// RUN:   -- -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int n = 10;
+int arr[n];
+int nums[n];
+
+void autotype() {
+  Val Teas[N];
+  for (int I = 0; I < N; ++I) {
+Teas[I].g();
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (Tea & Tea : Teas)
+  // CHECK-FIXES-NEXT: Tea.g();
+
+  // NonTriviallyCopyable has length 21 < 22
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const NonTriviallyCopyable & I : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+
+  // TriviallyCopyableButBig has length 23 > 22
+  const TriviallyCopyableButBig Big[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & I : Big)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -121,23 +121,23 @@
 Reverse Iterator Support
 
 
-The converter is also capable of transforming iterator loops which use 
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box 
-this will automatically happen in C++20 mode using the ``ranges`` library, 
-however the check can be configured to work without C++20 by specifying a 
+The converter is also capable of transforming iterator loops which use
+``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the ``ranges`` library,
+however the check can be configured to work without C++20 by specifying a
 function to reverse a range and optionally the header file where that function
 lives.
 
 .. option:: UseCxx20ReverseRanges
-  
-   When set to true convert loops when in C++20 or later mode using 
+
+   When set to true convert loops when in C++20 or later mode using
``std::ranges::reverse_view``.
Default value is ``true``.
 
 .. option:: MakeReverseRangeFunction
 
-   Specify the function used to reverse an iterator pair, the function should 
-   accept a class with ``rbegin`` and ``rend`` methods and return a 
+   Specify the function used to reverse an iterator pair, the function should
+   accept a class with ``rbegin`` and ``rend`` methods and return a
class with ``begin`` and ``end`` methods methods that call the ``rbegin`` and
``rend`` methods respectively. Common examples are ``ranges::reverse_view``
and ``llvm::reverse``.
@@ -146,10 +146,10 @@
 .. option:: MakeReverseRangeHeader
 
Specifies the header file where :option:`MakeReverseRangeFunction` is
-   declared. For the previous examples this option would be set to 
+   declared. For the previous examples this option would be set to
``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
-   If this is an empty string and :option:`MakeReverseRangeFunction` is set, 
-   the check will proceed on the assumption that the function is already 
+   If this is an empty string and :option:`MakeReverseRangeFunction` is set,
+   the check will proceed on the assumption that the function is already
available in the translation unit.
This can be wrapped in angle brackets to signify to add the include as a

[PATCH] D102779: [clang-tidy] cppcoreguidelines-explicit-constructor-and-conversion: new alias

2021-05-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:28-30
+  std::string FullOperatorName =
+  Node.getParent()->getNameAsString().append("::").append(
+  Node.getNameAsString());

Rather than trying to do this by hand, does `Decl::print()` give you the 
functionality you need? For example, this will likely not work well for classes 
defined within a namespace (it may ignore the wrong class due to not checking 
the namespace). Another thing to consider are templates and how to handle 
those. e.g.,
```
struct Foo {
  template 
  operator Ty() const; // How to silence the diagnostic here?
};
```
Thankfully, specializations can't differ in their explicitness, so you don't 
have to also worry about:
```
struct Foo {
  template 
  explicit operator Ty() const; // This one's explicit
};

template <>
Foo::operator int() const; // Thankfully, this inherits the explicit from the 
primary template.
```



Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:33
+  return llvm::any_of(IgnoredConversionOps,
+  [FullOperatorName](std::string NameInOptions) {
+return NameInOptions == FullOperatorName;





Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:102
   if (const auto *Conversion =
-  Result.Nodes.getNodeAs("conversion")) {
+  Result.Nodes.getNodeAs("conversion")) {
 if (Conversion->isOutOfLine())

mgartmann wrote:
> aaron.ballman wrote:
> > Unintended formatting change?
> This formatting change was done by `clang-format` when `git clang-format 
> HEAD~1` was run. Therefore, I assumed that it is now correctly formatted. 
> 
> Am I wrong?
I've never used the integrated git clang-format before, but I sort of wonder if 
it is getting extra context lines and that's why this one changed? I usually do 
`git diff -U0 --no-color HEAD^ | clang-format-diff.py -i -p1` and then I know 
exactly what range of lines are being touched.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/google-explicit-constructor.rst:74-75
+ignored and will not trigger a warning. The list to ignore conversion
+operator `operator B()` in class ``A`` would look as follows:
+``"A::operator B"``. The default list is empty.

We should probably document other identifiers that contribute to the name of 
the operator, like namespaces, template ids, etc. Using code examples for 
anything you think is tricky would be helpful.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-ignoredconversionoperators-option.cpp:84
+
+  operator A() const;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator A' must be 
marked explicit to avoid unintentional implicit conversions 
[google-explicit-constructor]

Can you also add an example that an explicit conversion operator does not 
diagnose?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102779

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-26 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG694d8cbe: [Scudo] Make -fsanitize=scudo use standalone. 
Migrate tests. (authored by hctim).

Changed prior to commit:
  https://reviews.llvm.org/D102543?vs=347814=348011#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/standalone/stats.c
===
--- compiler-rt/test/scudo/standalone/stats.c
+++ compiler-rt/test/scudo/standalone/stats.c
@@ -9,7 +9,7 @@
 
 #include 
 
-#include 
+void __scudo_print_stats();
 
 int main(int argc, char **argv) {
   free(malloc(1U));
Index: compiler-rt/test/scudo/standalone/sized-delete.cpp
===
--- compiler-rt/test/scudo/standalone/sized-delete.cpp
+++ compiler-rt/test/scudo/standalone/sized-delete.cpp
@@ -1,10 +1,10 @@
 // RUN: %clangxx_scudo -fsized-deallocation %s -o %t
-// RUN: %env_scudo_opts=DeleteSizeMismatch=1 %run %t gooddel2>&1
-// RUN: %env_scudo_opts=DeleteSizeMismatch=1 not %run %t baddel 2>&1 | FileCheck %s
-// RUN: %env_scudo_opts=DeleteSizeMismatch=0 %run %t baddel 2>&1
-// RUN: %env_scudo_opts=DeleteSizeMismatch=1 %run %t gooddelarr 2>&1
-// RUN: 

[clang] 6911114 - [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-26 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2021-05-26T10:03:17-07:00
New Revision: 694d8cbed06a8a809c34ae07f4e3e89ab252

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

LOG: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

This patch moves -fsanitize=scudo to link the standalone scudo library,
rather than the original compiler-rt based library. This is one of the
major remaining roadblocks to deleting the compiler-rt based scudo,
which should not be used any more. The standalone Scudo is better in
pretty much every way and is much more suitable for production usage.

As well as patching the litmus tests for checking that the
scudo_standalone lib is linked instead of the scudo lib, this patch also
ports all the scudo lit tests to run under scudo standalone.

This patch also adds a feature to scudo standalone that was under test
in the original scudo - that arguments passed to an aligned operator new
were checked that the alignment was a power of two.

Some lit tests could not be migrated, due to the following issues:
 1. Features that aren't supported in scudo standalone, like the rss
 limit.
 2. Different quarantine implementation where the test needs some more
 thought.
 3. Small bugs in scudo standalone that should probably be fixed, like
 the Secondary allocator having a full page on the LHS of an allocation
 that only contains the chunk header, so underflows by <= a page aren't
 caught.
 4. Slight differences in behaviour that's technically correct, like
 'realloc(malloc(1), 0)' returns nullptr in standalone, but a real
 pointer in old scudo.
 5. Some tests that might be migratable, but not easily.

Tests that are obviously not applicable to scudo standalone (like
testing that no sanitizer symbols made it into the DSO) have been
deleted.

After this patch, the remaining work is:
 1. Update the Scudo documentation. The flags have changed, etc.
 2. Delete the old version of scudo.
 3. Patch up the tests in lit-unmigrated, or fix Scudo standalone.

Reviewed By: cryptoad, vitalybuka

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

Added: 

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
compiler-rt/test/scudo/standalone/aligned-new.cpp
compiler-rt/test/scudo/standalone/alignment.c
compiler-rt/test/scudo/standalone/dealloc-race.c
compiler-rt/test/scudo/standalone/double-free.cpp
compiler-rt/test/scudo/standalone/fsanitize.c
compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
compiler-rt/test/scudo/standalone/lit.cfg.py
compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
compiler-rt/test/scudo/standalone/malloc.cpp
compiler-rt/test/scudo/standalone/memalign.c
compiler-rt/test/scudo/standalone/mismatch.cpp
compiler-rt/test/scudo/standalone/options.cpp
compiler-rt/test/scudo/standalone/preinit.c
compiler-rt/test/scudo/standalone/preload.cpp
compiler-rt/test/scudo/standalone/random_shuffle.cpp
compiler-rt/test/scudo/standalone/sized-delete.cpp
compiler-rt/test/scudo/standalone/stats.c
compiler-rt/test/scudo/standalone/tsd_destruction.c

Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/fuchsia.c
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
compiler-rt/test/scudo/CMakeLists.txt
compiler-rt/test/scudo/standalone/CMakeLists.txt

Removed: 

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so

clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
compiler-rt/test/scudo/aligned-new.cpp
compiler-rt/test/scudo/alignment.c
compiler-rt/test/scudo/dealloc-race.c
compiler-rt/test/scudo/double-free.cpp
compiler-rt/test/scudo/fsanitize.c
compiler-rt/test/scudo/interface.cpp
compiler-rt/test/scudo/lit.cfg.py
compiler-rt/test/scudo/lit.site.cfg.py.in
compiler-rt/test/scudo/malloc.cpp
compiler-rt/test/scudo/memalign.c
compiler-rt/test/scudo/mismatch.cpp
compiler-rt/test/scudo/options.cpp
compiler-rt/test/scudo/overflow.c
compiler-rt/test/scudo/preinit.c
compiler-rt/test/scudo/preload.cpp

[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-26 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D102839#2782557 , @kito-cheng 
wrote:

> We have Zmmul extension in the ISA spec now, that's equivalent to `-mno-div` 
> , so I suggest we should go forward to implement that extension rather than 
> `-mno-div`.
>
> https://github.com/riscv/riscv-isa-manual/pull/648

Yes, if people want subsets of extensions, that's the way to do it.


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

https://reviews.llvm.org/D102839

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


[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-26 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

We have Zmmul extension in the ISA spec now, that's equivalent to `-mno-div` , 
so I suggest we should go forward to implement that extension rather than 
`-mno-div`.

https://github.com/riscv/riscv-isa-manual/pull/648


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

https://reviews.llvm.org/D102839

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


[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-26 Thread Luís Marques via Phabricator via cfe-commits
luismarques added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3149-3152
+def mno_div : Flag<["-"], "mno-div">, Group,
+  HelpText<"Disable hardware integral division instructions in M extension">;
+def mdiv : Flag<["-"], "mdiv">, Group,
+  HelpText<"Enable hardware integral division instructions in M extension">;

Remove the redundant "hardware".

BTW, is "integral" actually correct, or should it be "integer division"?



Comment at: clang/lib/Basic/Targets/RISCV.h:49
   bool HasZvlsseg = false;
+  bool DisableHardwareIntDiv = false;
 

`DisableHardwareIntDiv` -> `DisableIntDiv`

Also, in general it would be best for the feature to be positive rather than 
negative, but I'm not sure whether it makes sense to make an exception here, 
since the option that toggles the feature is also negative.



Comment at: clang/test/Driver/riscv-no-div.c:1-17
+// RUN: %clang -target riscv32-unknown-elf %s -mno-div -S -o - 2>&1 \
+// RUN:   | not FileCheck -check-prefix=CHECK-NOERROR %s
+
+// RUN: %clang -target riscv64-unknown-elf %s -mno-div -S -o - 2>&1 \
+// RUN:   | not FileCheck -check-prefix=CHECK-NOERROR %s
+
+// RUN: %clang -target riscv32-unknown-elf %s -mno-div -S -o - 2>&1 \

Is `not FileCheck` the only way to check these do not occur?



Comment at: clang/test/Driver/riscv-no-div.c:33-35
+  // CHECK-DIV: div{{w?}} a{{[0-9]}}, a{{[0-9]}}, a{{[0-9]}}
+  // CHECK-REM: rem{{w?}} a{{[0-9]}}, a{{[0-9]}}, a{{[0-9]}}
+  // CHECK-MUL: mul{{w?}} a{{[0-9]}}, a{{[0-9]}}, a{{[0-9]}}

Should we be checking the actual instructions in a Clang test?



Comment at: llvm/test/CodeGen/RISCV/no-div.ll:29-31
+; This test makes sure even when both M extension no-div option enabled,
+; the compile would not fail. Instead, it will use a fallback solution like
+; calling builtin library functions.

I'm not sure it makes sense to refer to the possibility of the compilation 
failing. It's just that we shouldn't emit divide instructions.



Comment at: llvm/test/CodeGen/RISCV/no-div.ll:34-44
+; CHECK-UDIV: divu{{w?}} {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}, 
{{[as]}}{{[0-9]}}
+  %1 = udiv i32 %a, %b
+; CHECK-DIV: div{{w?}} {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}
+  %2 = sdiv i32 %a, %1
+; CHECK-MUL: mul{{w?}} {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}
+  %3 = mul i32 %b, %2
+; CHECK-UREM: remu{{w?}} {{[as]}}{{[0-9]}}, {{[as]}}{{[0-9]}}, 
{{[as]}}{{[0-9]}}

@jrtc27 should we use update_llc_test_checks.py instead here?


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

https://reviews.llvm.org/D102839

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


[PATCH] D103184: [AArch64] handle -Wa,-march=

2021-05-26 Thread Jian Cai via Phabricator via cfe-commits
jcai19 created this revision.
Herald added subscribers: danielkiss, kristof.beyls.
jcai19 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixed PR#48894 for AArch64. The issue has been fixed for Arm in
https://reviews.llvm.org/D95872


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103184

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-target-as-march.s


Index: clang/test/Driver/aarch64-target-as-march.s
===
--- /dev/null
+++ clang/test/Driver/aarch64-target-as-march.s
@@ -0,0 +1,8 @@
+/// These tests make sure that options passed to the assembler
+/// via -Wa or -Xassembler are applied correctly to assembler inputs.
+
+/// The last -march wins, and is handled before -Wa,march. All the values of 
-Wa,march options are added.
+// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.1-a 
-march=armv8.2-a -Wa,-march=armv8.3-a -Wa,-march=armv8.4-a %s 2>&1 | \
+// RUN: FileCheck --check-prefix=TRIPLE-AARCH64 %s
+
+// TRIPLE-AARCH64: "-target-feature" "+v8.2a" "-target-feature" "+v8.1a" 
"-target-feature" "+v8.3a" "-target-feature" "+v8.4a"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -209,6 +209,22 @@
 success = getAArch64MicroArchFeaturesFromMcpu(
 D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 
+  if (!success)
+D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+
+  // This matches GNU AArch64 assembler's behavior, which handles -Wa,-march
+  // after -march. And while only using the the value of last -march, it
+  // includes all the options passed via -Wa,-march.
+  success = true;
+  if ((A = Args.getLastArg(options::OPT_Wa_COMMA, options::OPT_Xassembler))) {
+for (const Arg *A :
+ Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
+  for (StringRef Value : A->getValues())
+if (Value.startswith("-march="))
+  success = getAArch64ArchFeaturesFromMarch(D, Value.substr(7), Args,
+Features);
+  }
+
   if (!success)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 


Index: clang/test/Driver/aarch64-target-as-march.s
===
--- /dev/null
+++ clang/test/Driver/aarch64-target-as-march.s
@@ -0,0 +1,8 @@
+/// These tests make sure that options passed to the assembler
+/// via -Wa or -Xassembler are applied correctly to assembler inputs.
+
+/// The last -march wins, and is handled before -Wa,march. All the values of -Wa,march options are added.
+// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.1-a -march=armv8.2-a -Wa,-march=armv8.3-a -Wa,-march=armv8.4-a %s 2>&1 | \
+// RUN: FileCheck --check-prefix=TRIPLE-AARCH64 %s
+
+// TRIPLE-AARCH64: "-target-feature" "+v8.2a" "-target-feature" "+v8.1a" "-target-feature" "+v8.3a" "-target-feature" "+v8.4a"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -209,6 +209,22 @@
 success = getAArch64MicroArchFeaturesFromMcpu(
 D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 
+  if (!success)
+D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+
+  // This matches GNU AArch64 assembler's behavior, which handles -Wa,-march
+  // after -march. And while only using the the value of last -march, it
+  // includes all the options passed via -Wa,-march.
+  success = true;
+  if ((A = Args.getLastArg(options::OPT_Wa_COMMA, options::OPT_Xassembler))) {
+for (const Arg *A :
+ Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
+  for (StringRef Value : A->getValues())
+if (Value.startswith("-march="))
+  success = getAArch64ArchFeaturesFromMarch(D, Value.substr(7), Args,
+Features);
+  }
+
   if (!success)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-26 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

FYI, I'm seeing what I think is a miscompile that bisects to this patch. 
Greatly simplified, the problematic snippet is this:

  struct Stats {
int a;
int b;
int a_or_b;
  };
  
  bool x = ...
  bool y = ...
  Stats stats;
  stats.a = x ? 1 : 0;
  stats.b = y ? 1 : 0;
  stats.a_or_b = (x || y) ? 1 : 0;

What we see is that when x is false and y is true, a is 0 (expected), b is 1 
(expected), but a_or_b is 0 (unexpected).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[libunwind] adf1561 - [libunwind] Inform ASan that resumption is noreturn

2021-05-26 Thread Shoaib Meenai via cfe-commits

Author: Shoaib Meenai
Date: 2021-05-26T09:31:39-07:00
New Revision: adf1561d6ce8af057127c65af863b3f0e1c77e60

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

LOG: [libunwind] Inform ASan that resumption is noreturn

If you're building libunwind instrumented with ASan, `_Unwind_RaiseException`
will poison the stack and then transfer control in a manner which isn't
understood by ASan, so the stack will remain poisoned. This can cause
false positives, e.g. if you call an uninstrumented function (so it
doesn't re-poison the stack) after catching an exception. Add a call to
`__asan_handle_no_return` inside `__unw_resume` to get ASan to unpoison
the stack and avoid this.

`__unw_resume` seems like the appropriate place to make this call, since
it's used for resumption by all unwind implementations except SJLJ. SJLJ
uses `__builtin_longjmp` to handle resumption, which is already
recognized as noreturn (and therefore ASan adds the `__asan_handle_no_return`
call itself), so it doesn't need any special handling.

PR32434 is somewhat similar (in particular needing a component built
without ASan to trigger the bug), and rG781ef03e1012, the fix for that
bug, adds an interceptor for `_Unwind_RaiseException`. This interceptor
won't always be triggered though, e.g. if you statically link the
unwinder into libc++abi in a way that prevents interposing the unwinder
functions (e.g. marking the symbols as hidden, using `--exclude-libs`,
or using `-Bsymbolic`). rG53335d6d86d5 makes `__cxa_throw` call
`__asan_handle_no_return` explicitly, to similarly avoid relying on
interception.

Reviewed By: #libunwind, compnerd

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

Added: 


Modified: 
libunwind/src/libunwind.cpp

Removed: 




diff  --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index eb2623e56430d..9b3b92bdff099 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -16,6 +16,9 @@
 
 #include 
 
+#if __has_feature(address_sanitizer)
+#include 
+#endif
 
 #if !defined(__USING_SJLJ_EXCEPTIONS__)
 #include "AddressSpace.hpp"
@@ -184,6 +187,10 @@ _LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, 
unw_get_proc_info)
 /// Resume execution at cursor position (aka longjump).
 _LIBUNWIND_HIDDEN int __unw_resume(unw_cursor_t *cursor) {
   _LIBUNWIND_TRACE_API("__unw_resume(cursor=%p)", static_cast(cursor));
+#if __has_feature(address_sanitizer)
+  // Inform the ASan runtime that now might be a good time to clean stuff up.
+  __asan_handle_no_return();
+#endif
   AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
   co->jumpto();
   return UNW_EUNSPEC;



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


[PATCH] D103112: Reimplement __builtin_unique_stable_name-

2021-05-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 347993.
erichkeane marked 6 inline comments as done.
erichkeane added a comment.

Do all the things requested by @aaron.ballman and @rjmccall  except for 
limiting the syntax to 'types only'.  Currently evaluating whether this is 
something we can accept.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-print-sycl-unique-stable-name.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name_sycl_only.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::SYCLUniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func ) {
+  constexpr const char *F1_output = __builtin_sycl_unique_stable_name(F1); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func ) {
+  constexpr const char *F2_output = __builtin_sycl_unique_stable_name(F2); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // 

[PATCH] D103179: [clangd] Handle queries without an originating file in ProjectAwareIndex

2021-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Note that I don't feel strongly about making use of `Context` to figure out 
config::Params vs moving the `Params` into the `Config`. But I'd rather not 
only store `Path` in the `Config` since we might end up needing other 
environment variables in future.

I didn't go with the Context option as it is hard to find a place to fetch it. 
Maybe we can just forward declare it in Config.h and have a `Config::Params` 
similar to `Config::Current`. (but this would decouple the Config and  Params 
that generated it :/)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103179

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


[PATCH] D103179: [clangd] Handle queries without an originating file in ProjectAwareIndex

2021-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, kbobyrev.
Herald added subscribers: usaxena95, jfb, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This enables handling of queries like workspaceSymbols by the last used
external index, which might be null when the query comes from a file specific
context but that file doesn't have any ExternalIndex set (existing behaviour).

This also moves config::Params into Config, rather than just having a file path
inside the Config struct or deducing the environment from Context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103179

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigProvider.cpp
  clang-tools-extra/clangd/ConfigProvider.h
  clang-tools-extra/clangd/index/ProjectAware.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
  clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
@@ -82,5 +82,44 @@
   EXPECT_EQ(InvocationCount, 1U);
   return;
 }
+
+TEST(ProjectAware, LastIndex) {
+  IndexFactory Gen = [&](const Config::ExternalIndexSpec ,
+ AsyncTaskRunner *) { return createIndex(); };
+
+  auto Idx = createProjectAwareIndex(std::move(Gen), true);
+  FuzzyFindRequest Req;
+  Req.Query = "1";
+  Req.AnyScope = true;
+
+  auto QueryWithoutPath = [&] {
+Config C;
+WithContextValue With(Config::Key, std::move(C));
+return match(*Idx, Req);
+  };
+
+  // Empty without any external index before hand.
+  EXPECT_THAT(QueryWithoutPath(), IsEmpty());
+  // Now issue a request that will dispatch to an external index.
+  {
+Config C;
+C.Index.External.emplace();
+C.Index.External->Location = "test";
+WithContextValue With(Config::Key, std::move(C));
+EXPECT_THAT(match(*Idx, Req), ElementsAre("1"));
+  }
+  // Should use the same external index.
+  EXPECT_THAT(QueryWithoutPath(), ElementsAre("1"));
+  // Issue a query without an external index.
+  {
+Config C;
+C.Parm.Path = "path";
+WithContextValue With(Config::Key, std::move(C));
+EXPECT_THAT(match(*Idx, Req), IsEmpty());
+  }
+  // Should use the last index, which was none.
+  EXPECT_THAT(QueryWithoutPath(), IsEmpty());
+  return;
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigProviderTests.cpp
@@ -24,6 +24,8 @@
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 
+using Params = Config::Params;
+
 // Provider that appends an arg to compile flags.
 // The arg is prefix, where N is the times getFragments() was called.
 // It also yields a diagnostic each time it's called.
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -38,7 +38,7 @@
   CapturedDiags Diags;
   Config Conf;
   Fragment Frag;
-  Params Parm;
+  Config::Params Parm;
 
   bool compileAndApply() {
 Conf = Config();
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -338,7 +338,7 @@
   // Provide conditional config that defines FOO for foo.cc.
   class ConfigProvider : public config::Provider {
 std::vector
-getFragments(const config::Params &,
+getFragments(const Config::Params &,
  config::DiagnosticCallback DC) const override {
   config::Fragment F;
   F.If.PathMatch.emplace_back(".*foo.cc");
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -593,7 +593,7 @@
   config::CompiledFragment Frag;
 
   std::vector
-  getFragments(const config::Params &,
+  getFragments(const Config::Params &,
config::DiagnosticCallback) const override {
 return {Frag};
   }
@@ -647,7 +647,7 @@
   BGPolicy = 

[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-26 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for implementing this. The redundant pseudo can be removed when 
committing.




Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.td:2572
+  [(int_ppc_eieio)]>;
+def PseudoIOSPACEEIEIO : PPCEmitTimePseudo<(outs), (ins), "#PPCIOSPACEEIEIO",
+ [(int_ppc_iospace_eieio)]>;

These two are identical. Please only define one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

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


[PATCH] D103175: [C++4OpenCL] Fix ICE with invalid use of half

2021-05-26 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm created this revision.
olestrohm added reviewers: Anastasia, svenvh.
olestrohm added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
olestrohm requested review of this revision.
Herald added a subscriber: cfe-commits.

Because half is limited to the `cl_khr_fp16` extension being enabled, 
`DefaultLvalueConversion` can fail when it's not enabled.
Because of this the original assumption that it will never return an error is 
wrong.

This is fixed by checking for an error and returning early if there is one, 
instead of assuming that `DefaultLvalueConversion` is infallible.

Fixes: PR47976


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103175

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaOpenCLCXX/half.clcpp


Index: clang/test/SemaOpenCLCXX/half.clcpp
===
--- /dev/null
+++ clang/test/SemaOpenCLCXX/half.clcpp
@@ -0,0 +1,15 @@
+//RUN: %clang_cc1 %s -triple spir -verify -fsyntax-only
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+typedef half half2 __attribute__((ext_vector_type(2)));
+
+half f(half2 h2) { // expected-error{{declaring function return value of type 
'half' is not allowed ; did you forget * ?}}
+return h2.s0; // expected-error{{loading directly from pointer to type 
'__private half' requires cl_khr_fp16. Use vector data load builtin functions 
instead}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+half f(half2 h2) {
+return h2.s0;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4193,7 +4193,9 @@
   case ICK_Lvalue_To_Rvalue: {
 assert(From->getObjectKind() != OK_ObjCProperty);
 ExprResult FromRes = DefaultLvalueConversion(From);
-assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!");
+if (FromRes.isInvalid())
+  return ExprError();
+
 From = FromRes.get();
 FromType = From->getType();
 break;


Index: clang/test/SemaOpenCLCXX/half.clcpp
===
--- /dev/null
+++ clang/test/SemaOpenCLCXX/half.clcpp
@@ -0,0 +1,15 @@
+//RUN: %clang_cc1 %s -triple spir -verify -fsyntax-only
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+typedef half half2 __attribute__((ext_vector_type(2)));
+
+half f(half2 h2) { // expected-error{{declaring function return value of type 'half' is not allowed ; did you forget * ?}}
+return h2.s0; // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+half f(half2 h2) {
+return h2.s0;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4193,7 +4193,9 @@
   case ICK_Lvalue_To_Rvalue: {
 assert(From->getObjectKind() != OK_ObjCProperty);
 ExprResult FromRes = DefaultLvalueConversion(From);
-assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!");
+if (FromRes.isInvalid())
+  return ExprError();
+
 From = FromRes.get();
 FromType = From->getType();
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97869: [OpenCL][Draft] Add OpenCL builtin test generator

2021-05-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

I think this is a very good starting point for the testing of built-in 
functions. Btw should we now remove '[Draft]' from the title?




Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:242
+  // functions.
+  void Emit();
+

Should be `emit` to adhere to coding style?



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:969
+
+void OpenCLBuiltinTestEmitter::getTypeLists(
+Record *Type, TypeFlags , std::vector ,

I would add a documentation for this function, it is not very obvious.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:1004
+SmallVectorImpl> ) {
+  // Find out if there are any GenTypes in this signature, and if so, calculate
+  // into how many signatures they will expand.

Maybe this should be lifted as documentation of the header of this function?



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:1033
+for (unsigned ArgNum = 0; ArgNum < Signature.size(); ArgNum++) {
+  // For differently-sized GenTypes in a parameter list, the smaller
+  // GenTypes just repeat.

I don't get this comment and its exact reference to the code.


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

https://reviews.llvm.org/D97869

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


[PATCH] D102779: [clang-tidy] cppcoreguidelines-explicit-constructor-and-conversion: new alias

2021-05-26 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann added a comment.

@aaron.ballman Thanks a lot for your valuable feedback! I incorporated it 
accordingly.

Is there anything else that should be improved?




Comment at: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp:102
   if (const auto *Conversion =
-  Result.Nodes.getNodeAs("conversion")) {
+  Result.Nodes.getNodeAs("conversion")) {
 if (Conversion->isOutOfLine())

aaron.ballman wrote:
> Unintended formatting change?
This formatting change was done by `clang-format` when `git clang-format 
HEAD~1` was run. Therefore, I assumed that it is now correctly formatted. 

Am I wrong?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102779

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


[PATCH] D90835: [clang-tidy] Ignore diagnostics due to macro expansion from not-interested headers

2021-05-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

@alexfh, @njames93 and @thakis please take a look! I added all tests cases and 
put new logic behind a flag to make it as safe as possible.
Issue with diagnostics from macro expansion from third-party headers is the one 
of the biggest problem with deployment that we have and it cannot be properly 
fixed with wrappers around clang-tidy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90835

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


[PATCH] D102779: [clang-tidy] cppcoreguidelines-explicit-constructor-and-conversion: new alias

2021-05-26 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 347970.
mgartmann marked 5 inline comments as done.
mgartmann added a comment.

- added option to ignore conversion operators
- added tests for new and existing options
- renamed options to `Ignore...`
- ensured that option's strings only get parsed once


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102779

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
  clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-explicit-constructor-and-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/google-explicit-constructor.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-ignoredconstructors-option.cpp
  
clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-ignoredconversionoperators-option.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-ignoredconversionoperators-option.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google-explicit-constructor-ignoredconversionoperators-option.cpp
@@ -0,0 +1,88 @@
+// RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
+// RUN: google-explicit-constructor %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: ]}'
+
+// RUN: %check_clang_tidy -check-suffix=IGNORED %s \
+// RUN: google-explicit-constructor %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN:   {key: google-explicit-constructor.IgnoredConversionOperators, value: "A::operator bool;B::operator double;B::operator A"} \
+// RUN: ]}'
+
+struct A {
+  A() {}
+  A(int x, int y) {}
+
+  explicit A(void *x) {}
+  explicit A(void *x, void *y) {}
+
+  A(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-MESSAGES-IGNORED: :[[@LINE-2]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}explicit A(int x1);
+
+  operator bool() const { return true; }
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator bool' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit operator bool() const { return true; }
+
+  operator double() const;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator double' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-MESSAGES-IGNORED: :[[@LINE-2]]:3: warning: 'operator double' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}explicit operator double() const;
+};
+
+inline A::A(int x1) {}
+
+struct B {
+  B() {}
+  B(int x, int y) {}
+
+  explicit B(void *x) {}
+  explicit B(void *x, void *y) {}
+
+  B(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-MESSAGES-IGNORED: :[[@LINE-2]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}explicit B(int x1);
+
+  operator bool() const { return true; }
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator bool' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-MESSAGES-IGNORED: :[[@LINE-2]]:3: warning: 'operator bool' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}explicit operator bool() const { return true; }
+
+  operator double() const;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator double' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit operator double() const;
+
+  operator A() const;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: 'operator A' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES-DEFAULT: {{^  }}explicit operator A() const;
+};
+
+struct C {
+  C() {}
+  C(int x, int y) {}
+
+  explicit C(void *x) {}
+  explicit C(void *x, void *y) {}
+
+  C(int x1);
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions 

[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-05-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:257
+  // BoundCounter is 0 for outer `)`.
+  // BoundCounter is 1 for outer '(' or inner `)`.
+  // BoundCounter is 2 for inner `(`.

vsavchenko wrote:
> ASDenysPetrov wrote:
> > vsavchenko wrote:
> > > nit: it has different ticks than you use in all other places
> > I'm sorry. I didn't get it. What do you mean?
> This is a super duper tiny thing: you usually write `)` or `(`, but here 
> wrote '('.
Oh! :-) Sharp eye!


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

https://reviews.llvm.org/D99797

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


[PATCH] D90835: [clang-tidy] Ignore diagnostics due to macro expansion from not-interested headers

2021-05-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 347968.
DmitryPolukhin added a comment.
Herald added a subscriber: dexonsmith.

Added test for system like object macro


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90835

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/macros.h
  clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/macros_filter.h
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/system/sysmacros.h
  clang-tools-extra/test/clang-tidy/infrastructure/macros.cpp
  clang/include/clang/Basic/SourceManager.h

Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -397,6 +397,11 @@
getExpansionLocStart() != getExpansionLocEnd();
   }
 
+  bool isObjectMacroExpansion() const {
+return getExpansionLocStart().isValid() &&
+   getExpansionLocStart() == getExpansionLocEnd();
+  }
+
   /// Return a ExpansionInfo for an expansion.
   ///
   /// Start and End specify the expansion range (where the macro is
Index: clang-tools-extra/test/clang-tidy/infrastructure/macros.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/macros.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/macros.cpp
@@ -1,7 +1,50 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor,modernize-avoid-c-arrays' --header-filter='macros_filter.h' --filter-macro-from-headers %s -- -isystem %S/Inputs/macros/system -I %S/Inputs/macros | FileCheck %s
+// RUN: clang-tidy --config='{"Checks": "-*,google-explicit-constructor,modernize-avoid-c-arrays", "HeaderFilterRegex": "macros_filter.h", "FilterMacroFromHeaders": true}' %s -- -isystem %S/Inputs/macros/system -I %S/Inputs/macros | FileCheck %s
+
+#include "macros.h"
+#include "macros_filter.h"
+#include 
 
 #define Q(name) class name { name(int i); }
 
 Q(A);
 // CHECK: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit
-// CHECK: :3:30: note: expanded from macro 'Q'
+// CHECK: :[[@LINE-4]]:30: note: expanded from macro 'Q'
+
+#define MAIN_MACRO_DIAG_IN_ARG(a) a
+MAIN_MACRO_DIAG_IN_ARG(int var_A[10]);
+// CHECK: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use std::array<> instead
+
+#define MAIN_MACRO_DIAG_IN_BODY int var_A1[10]
+MAIN_MACRO_DIAG_IN_BODY;
+// CHECK: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
+// CHECK: :[[@LINE-3]]:33: note: expanded from macro 'MAIN_MACRO_DIAG_IN_BODY'
+
+HEADER_FILTER_MACRO_DIAG_IN_ARG(int var_B[10]);
+// CHECK: :[[@LINE-1]]:33: warning: do not declare C-style arrays, use std::array<> instead
+
+HEADER_FILTER_MACRO_DIAG_IN_BODY;
+// CHECK: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
+// CHECK: note: expanded from macro 'HEADER_FILTER_MACRO_DIAG_IN_BODY'
+
+#define MAIN_MACRO_WRAPPER HEADER_FILTER_MACRO_DIAG_IN_BODY2
+MAIN_MACRO_WRAPPER;
+// CHECK: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
+// CHECK: note: expanded from macro 'MAIN_MACRO_WRAPPER'
+// CHECK: note: expanded from macro 'HEADER_FILTER_MACRO_DIAG_IN_BODY2'
+
+// CHECK-NOT: warning:
+HEADER_MACRO_DIAG_IN_ARG(int var_C[10]);
+HEADER_MACRO_DIAG_IN_BODY;
+
+#define MAIN_MACRO_WRAPPER2 HEADER_MACRO_DIAG_IN_BODY2
+MAIN_MACRO_WRAPPER2;
+
+SYS_HEADER_MACRO_FUNCTION(int var_D[10]);
+
+SYS_HEADER_MACRO_OBJECT var_D1[10];
+// CHECK: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
+// CHECK: note: expanded from macro 'SYS_HEADER_MACRO_OBJECT'
+
+DEFINE_bool(test, false);
+// CHECK-NOT: warning:
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/system/sysmacros.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/system/sysmacros.h
@@ -0,0 +1,2 @@
+#define SYS_HEADER_MACRO_FUNCTION(a) a
+#define SYS_HEADER_MACRO_OBJECT int
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/macros_filter.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/macros/macros_filter.h
@@ -0,0 +1,3 @@
+#define HEADER_FILTER_MACRO_DIAG_IN_ARG(a) a
+#define HEADER_FILTER_MACRO_DIAG_IN_BODY int var_B1[10]
+#define HEADER_FILTER_MACRO_DIAG_IN_BODY2 int var_B2[10]
Index: 

[clang-tools-extra] 8f79203 - [clangd] New ParsingCallback for semantics changes

2021-05-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-05-26T16:57:30+02:00
New Revision: 8f79203a22d8e04086f4cc9a58bb365148852a09

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

LOG: [clangd] New ParsingCallback for semantics changes

Previously notification of the Server about semantic happened strictly
before notification of the AST thread.
Hence a racy Server could make a request (like semantic tokens) after
the notification, with the assumption that it'll be served fresh
content. But it wasn't true if AST thread wasn't notified about the
change yet.

This change reverses the order of those notifications to prevent racy
interactions.

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 3f8b95b9104ce..0f525f3b9a0a4 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -75,8 +75,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
  const CanonicalIncludes ) override {
 if (FIndex)
   FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
-if (ServerCallbacks)
-  ServerCallbacks->onSemanticsMaybeChanged(Path);
   }
 
   void onMainAST(PathRef Path, ParsedAST , PublishFn Publish) override {
@@ -105,6 +103,11 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
   ServerCallbacks->onFileUpdated(File, Status);
   }
 
+  void onPreamblePublished(PathRef File) override {
+if (ServerCallbacks)
+  ServerCallbacks->onSemanticsMaybeChanged(File);
+  }
+
 private:
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 435deb6ec162a..7498598f124fb 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -909,6 +909,7 @@ void PreambleThread::build(Request Req) {
 ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
LatestBuild, std::move(Req.CIDiags),
std::move(Req.WantDiags));
+Callbacks.onPreamblePublished(FileName);
   });
 
   if (!LatestBuild || Inputs.ForceRebuild) {

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index 8df2c019053e0..4731443d3d51b 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -169,6 +169,11 @@ class ParsingCallbacks {
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus ) {}
+
+  /// Preamble for the TU have changed. This might imply new semantics (e.g.
+  /// 
diff erent highlightings). Any actions on the file are guranteed to see new
+  /// preamble after the callback.
+  virtual void onPreamblePublished(PathRef File) {}
 };
 
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,



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


[PATCH] D102761: [clangd] New ParsingCallback for semantics changes

2021-05-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8f79203a22d8: [clangd] New ParsingCallback for semantics 
changes (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102761

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -169,6 +169,11 @@
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus ) {}
+
+  /// Preamble for the TU have changed. This might imply new semantics (e.g.
+  /// different highlightings). Any actions on the file are guranteed to see 
new
+  /// preamble after the callback.
+  virtual void onPreamblePublished(PathRef File) {}
 };
 
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -909,6 +909,7 @@
 ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
LatestBuild, std::move(Req.CIDiags),
std::move(Req.WantDiags));
+Callbacks.onPreamblePublished(FileName);
   });
 
   if (!LatestBuild || Inputs.ForceRebuild) {
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -75,8 +75,6 @@
  const CanonicalIncludes ) override {
 if (FIndex)
   FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
-if (ServerCallbacks)
-  ServerCallbacks->onSemanticsMaybeChanged(Path);
   }
 
   void onMainAST(PathRef Path, ParsedAST , PublishFn Publish) override {
@@ -105,6 +103,11 @@
   ServerCallbacks->onFileUpdated(File, Status);
   }
 
+  void onPreamblePublished(PathRef File) override {
+if (ServerCallbacks)
+  ServerCallbacks->onSemanticsMaybeChanged(File);
+  }
+
 private:
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -169,6 +169,11 @@
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus ) {}
+
+  /// Preamble for the TU have changed. This might imply new semantics (e.g.
+  /// different highlightings). Any actions on the file are guranteed to see new
+  /// preamble after the callback.
+  virtual void onPreamblePublished(PathRef File) {}
 };
 
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -909,6 +909,7 @@
 ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
LatestBuild, std::move(Req.CIDiags),
std::move(Req.WantDiags));
+Callbacks.onPreamblePublished(FileName);
   });
 
   if (!LatestBuild || Inputs.ForceRebuild) {
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -75,8 +75,6 @@
  const CanonicalIncludes ) override {
 if (FIndex)
   FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
-if (ServerCallbacks)
-  ServerCallbacks->onSemanticsMaybeChanged(Path);
   }
 
   void onMainAST(PathRef Path, ParsedAST , PublishFn Publish) override {
@@ -105,6 +103,11 @@
   ServerCallbacks->onFileUpdated(File, Status);
   }
 
+  void onPreamblePublished(PathRef File) override {
+if (ServerCallbacks)
+  ServerCallbacks->onSemanticsMaybeChanged(File);
+  }
+
 private:
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103125: [Clang][WIP] Allow renaming of "clang"

2021-05-26 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

I'm also not a fan of this change. From a project perspective the binary is 
clang and while people may wish to change the name for their own product teams 
it seems like that onus should be on them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103125

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


[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 347958.
yaxunl added a comment.

do not promote or check dependent variables since their ctor/dtor/initializers 
are not determined yet


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

https://reviews.llvm.org/D103108

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCUDA/device-use-host-var.cu
  clang/test/SemaCUDA/device-use-host-var.cu

Index: clang/test/SemaCUDA/device-use-host-var.cu
===
--- clang/test/SemaCUDA/device-use-host-var.cu
+++ clang/test/SemaCUDA/device-use-host-var.cu
@@ -5,6 +5,8 @@
 
 #include "Inputs/cuda.h"
 
+int func();
+
 struct A {
   int x;
   static int host_var;
@@ -16,6 +18,19 @@
   int host_var;
 }
 
+// struct with non-empty ctor.
+struct B1 {
+  int x;
+  B1() { x = 1; }
+};
+
+// struct with non-empty dtor.
+struct B2 {
+  int x;
+  B2() {}
+  ~B2() { x = 0; }
+};
+
 static int static_host_var;
 
 __device__ int global_dev_var;
@@ -34,6 +49,17 @@
 const A global_const_struct_var{1};
 constexpr A global_constexpr_struct_var{1};
 
+// Check const host var initialized with non-empty ctor is not allowed in
+// device function.
+const B1 b1;
+
+// Check const host var having non-empty dtor is not allowed in device function.
+const B2 b2;
+
+// Check const host var initialized by non-constant initializer is not allowed
+// in device function.
+const int b3 = func();
+
 template
 __global__ void kernel(F f) { f(); } // dev-note2 {{called by 'kernel<(lambda}}
 
@@ -53,11 +79,14 @@
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
   *out = global_const_var;
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in __device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in __device__ function}}
+  *out = b3; // dev-error {{reference to __host__ variable 'b3' in __device__ function}}
   global_host_var = 1; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
 
   // Check reference of non-constexpr host variables are not allowed.
   int _host_var = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int _const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int _const_var = global_const_var;
   const int _constexpr_var = global_constexpr_var;
   *out = ref_host_var;
   *out = ref_constexpr_var;
@@ -65,18 +94,18 @@
 
   // Check access member of non-constexpr struct type host variable is not allowed.
   *out = global_host_struct_var.x; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
-  *out = global_const_struct_var.x; // dev-error {{reference to __host__ variable 'global_const_struct_var' in __device__ function}}
+  *out = global_const_struct_var.x;
   *out = global_constexpr_struct_var.x;
   global_host_struct_var.x = 1; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
 
   // Check address taking of non-constexpr host variables is not allowed.
   int *p = _host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int *cp = _const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int *cp = _const_var;
   const int *cp2 = _constexpr_var;
 
   // Check access elements of non-constexpr host array is not allowed.
   *out = global_host_array[1]; // dev-error {{reference to __host__ variable 'global_host_array' in __device__ function}}
-  *out = global_const_array[1]; // dev-error {{reference to __host__ variable 'global_const_array' in __device__ function}}
+  *out = global_const_array[1];
   *out = global_constexpr_array[1];
 
   // Check ODR-use of host variables in namespace is not allowed.
@@ -103,7 +132,7 @@
   int _constant_var = global_constant_var;
   int _shared_var = global_shared_var;
   const int _constexpr_var = global_constexpr_var;
-  const int _const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __global__ function}}
+  const int _const_var = global_const_var;
 
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __global__ function}}
   *out = global_dev_var;
@@ -126,7 +155,7 @@
   int _constant_var = global_constant_var;
   int _shared_var = global_shared_var;
   const int _constexpr_var = global_constexpr_var;
-  const int _const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __host__ __device__ function}}
+  const int _const_var = global_const_var;
 
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __host__ __device__ function}}
 

[PATCH] D102517: [clang] Add support for the "abstract" contextual keyword of MSVC

2021-05-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Looks good to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102517

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


[PATCH] D102517: [clang] Add support for the "abstract" contextual keyword of MSVC

2021-05-26 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra updated this revision to Diff 347955.
AbbasSabra added a comment.

Updating D102517 : [clang] Apply code review: 
while loop instead of for loop


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102517

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp

Index: clang/test/SemaCXX/MicrosoftExtensions.cpp
===
--- clang/test/SemaCXX/MicrosoftExtensions.cpp
+++ clang/test/SemaCXX/MicrosoftExtensions.cpp
@@ -462,6 +462,77 @@
 virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
 };
 
+// expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
+class AbstractClass abstract {
+  int i;
+};
+
+// expected-error@+1 {{variable type 'AbstractClass' is an abstract class}}
+AbstractClass abstractInstance;
+
+// expected-warning@+4 {{abstract class is marked 'sealed'}}
+// expected-note@+3 {{'AbstractAndSealedClass' declared here}}
+// expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
+// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
+class AbstractAndSealedClass abstract sealed {}; // Does no really make sense, but allowed
+
+// expected-error@+1 {{variable type 'AbstractAndSealedClass' is an abstract class}}
+AbstractAndSealedClass abstractAndSealedInstance;
+// expected-error@+1 {{base 'AbstractAndSealedClass' is marked 'sealed'}}
+class InheritFromAbstractAndSealed : AbstractAndSealedClass {};
+
+#if __cplusplus <= 199711L
+// expected-warning@+4 {{'final' keyword is a C++11 extension}}
+// expected-warning@+3 {{'final' keyword is a C++11 extension}}
+#endif
+// expected-error@+1 {{class already marked 'final'}}
+class TooManyVirtSpecifiers1 final final {};
+#if __cplusplus <= 199711L
+// expected-warning@+4 {{'final' keyword is a C++11 extension}}
+#endif
+// expected-warning@+2 {{'sealed' keyword is a Microsoft extension}}
+// expected-error@+1 {{class already marked 'sealed'}}
+class TooManyVirtSpecifiers2 final sealed {};
+#if __cplusplus <= 199711L
+// expected-warning@+6 {{'final' keyword is a C++11 extension}}
+// expected-warning@+5 {{'final' keyword is a C++11 extension}}
+#endif
+// expected-warning@+3 {{abstract class is marked 'final'}}
+// expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
+// expected-error@+1 {{class already marked 'final'}}
+class TooManyVirtSpecifiers3 final abstract final {};
+#if __cplusplus <= 199711L
+// expected-warning@+6 {{'final' keyword is a C++11 extension}}
+#endif
+// expected-warning@+4 {{abstract class is marked 'final'}}
+// expected-warning@+3 {{'abstract' keyword is a Microsoft extension}}
+// expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
+// expected-error@+1 {{class already marked 'abstract'}}
+class TooManyVirtSpecifiers4 abstract final abstract {};
+
+class Base {
+  virtual void i();
+};
+class AbstractFunctionInClass : public Base {
+  // expected-note@+2 {{unimplemented pure virtual method 'f' in 'AbstractFunctionInClass'}}
+  // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
+  virtual void f() abstract;
+  // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
+  void g() abstract; // expected-error {{'g' is not virtual and cannot be declared pure}}
+  // expected-note@+2 {{unimplemented pure virtual method 'h' in 'AbstractFunctionInClass'}}
+  // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
+  virtual void h() abstract = 0; // expected-error {{class member already marked 'abstract'}}
+#if __cplusplus <= 199711L
+  // expected-warning@+4 {{'override' keyword is a C++11 extension}}
+#endif
+  // expected-note@+2 {{unimplemented pure virtual method 'i' in 'AbstractFunctionInClass'}}
+  // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
+  virtual void i() abstract override;
+};
+
+// expected-error@+1 {{variable type 'AbstractFunctionInClass' is an abstract class}}
+AbstractFunctionInClass abstractFunctionInClassInstance;
+
 void AfterClassBody() {
   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
   struct D {} __declspec(deprecated);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16436,6 +16436,7 @@
 void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD,
 

[PATCH] D103155: [clang-cl] Add driver support for /std:c++20 and bump /std:c++latest (PR50465)

2021-05-26 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8f75d497daa: [clang-cl] Add driver support for /std:c++20 
and bump /std:c++latest (PR50465) (authored by hans).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103155

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -594,8 +594,11 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++17 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX17 %s
 // STDCXX17: -std=c++17
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
+// STDCXX20: -std=c++20
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
-// STDCXXLATEST: -std=c++20
+// STDCXXLATEST: -std=c++2b
 
 // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck 
-check-prefix=ENV-CL %s
 // ENV-CL: "-ffunction-sections"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6080,7 +6080,8 @@
   LanguageStandard = llvm::StringSwitch(StdArg->getValue())
  .Case("c++14", "-std=c++14")
  .Case("c++17", "-std=c++17")
- .Case("c++latest", "-std=c++20")
+ .Case("c++20", "-std=c++20")
+ .Case("c++latest", "-std=c++2b")
  .Default("");
   if (LanguageStandard.empty())
 D.Diag(clang::diag::warn_drv_unused_argument)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5934,7 +5934,7 @@
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++latest,c11,c17)">;
+  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -594,8 +594,11 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX17 %s
 // STDCXX17: -std=c++17
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX20 %s
+// STDCXX20: -std=c++20
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s
-// STDCXXLATEST: -std=c++20
+// STDCXXLATEST: -std=c++2b
 
 // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
 // ENV-CL: "-ffunction-sections"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6080,7 +6080,8 @@
   LanguageStandard = llvm::StringSwitch(StdArg->getValue())
  .Case("c++14", "-std=c++14")
  .Case("c++17", "-std=c++17")
- .Case("c++latest", "-std=c++20")
+ .Case("c++20", "-std=c++20")
+ .Case("c++latest", "-std=c++2b")
  .Default("");
   if (LanguageStandard.empty())
 D.Diag(clang::diag::warn_drv_unused_argument)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5934,7 +5934,7 @@
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++latest,c11,c17)">;
+  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >