[PATCH] D61545: [analyzer] Fix a crash in RVO from within blocks.

2019-05-04 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

I think the entire `LocationContext` stuff is a huge design issue, and you used 
its functionality without any hack. If you would rename the `getStackFrame` to 
`getNextStackFrame` or something, it is clear it is not a getter and traversing 
every frame until the top-frame.




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:203
+cast(SFC->getCallSite()), State, CallerSFC,
 RTC->getConstructionContext(), CallOpts);
   } else {

The smallest the scope between the definition and its usage, the better the 
code. Could you put the new code immediately before the return statement?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61545



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


[PATCH] D36527: Implemented P0428R2 - Familiar template syntax for generic lambdas

2019-05-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith marked an inline comment as done.
rsmith added a comment.
This revision is now accepted and ready to land.

Thank you, please go ahead and land this! (We'll need to parse and handle 
//requires-clause//s here too, but that can wait for another patch.)

(Please feel free to send ~weekly pings if you're not getting code review 
feedback; it's easy for things to get missed.)




Comment at: lib/AST/DeclPrinter.cpp:107-108
 
-void printTemplateParameters(const TemplateParameterList *Params);
+void printTemplateParameters(const TemplateParameterList *Params,
+ bool OmitTemplateKW = false);
 void printTemplateArguments(const TemplateArgumentList &Args,

hamzasood wrote:
> rsmith wrote:
> > Nit: I'd prefer splitting this into two functions (one that prints 
> > 'template', calls the other, then prints a space, and the other to print 
> > the actual template parameters) rather than passing a boolean flag.
> Do you reckon that the boolean flag is okay for 
> `TemplateParameterList::print`? I've left this change for now until that has 
> been decided.
This seems fine.


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

https://reviews.llvm.org/D36527



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


[PATCH] D61537: [clangd] Boost code completion results that were named in the last few lines.

2019-05-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 198129.
sammccall added a comment.

Tune magic numbers


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61537

Files:
  clangd/CodeComplete.cpp
  clangd/FindSymbols.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/test/completion-auto-trigger.test
  clangd/unittests/CodeCompleteTests.cpp
  clangd/unittests/QualityTests.cpp
  clangd/unittests/SourceCodeTests.cpp

Index: clangd/unittests/SourceCodeTests.cpp
===
--- clangd/unittests/SourceCodeTests.cpp
+++ clangd/unittests/SourceCodeTests.cpp
@@ -22,6 +22,7 @@
 
 using llvm::Failed;
 using llvm::HasValue;
+using testing::UnorderedElementsAreArray;
 
 MATCHER_P2(Pos, Line, Col, "") {
   return arg.line == int(Line) && arg.character == int(Col);
@@ -322,6 +323,19 @@
   EXPECT_EQ(IDs["foo"], 2u);
 }
 
+TEST(SourceCodeTests, CollectWords) {
+  auto Words = collectWords(R"cpp(
+  #define FOO_BAR
+  // this is a comment
+  std::string getSomeText() { return "magic word"; }
+  )cpp");
+  std::set ActualWords(Words.keys().begin(), Words.keys().end());
+  std::set ExpectedWords = {"define",  "foo","bar",  "this",
+ "comment", "string", "some", "text",
+ "return",  "magic",  "word"};
+  EXPECT_EQ(ActualWords, ExpectedWords);
+}
+
 TEST(SourceCodeTests, VisibleNamespaces) {
   std::vector>> Cases = {
   {
Index: clangd/unittests/QualityTests.cpp
===
--- clangd/unittests/QualityTests.cpp
+++ clangd/unittests/QualityTests.cpp
@@ -292,6 +292,16 @@
   SymbolRelevanceSignals InBaseClass;
   InBaseClass.InBaseClass = true;
   EXPECT_LT(InBaseClass.evaluate(), Default.evaluate());
+
+  llvm::StringSet<> Words = {"one", "two", "three"};
+  SymbolRelevanceSignals WithoutMatchingWord;
+  WithoutMatchingWord.ContextWords = &Words;
+  WithoutMatchingWord.Name = "four";
+  EXPECT_EQ(WithoutMatchingWord.evaluate(), Default.evaluate());
+  SymbolRelevanceSignals WithMatchingWord;
+  WithMatchingWord.ContextWords = &Words;
+  WithMatchingWord.Name = "TheTwoTowers";
+  EXPECT_GT(WithMatchingWord.evaluate(), Default.evaluate());
 }
 
 TEST(QualityTests, ScopeProximity) {
Index: clangd/unittests/CodeCompleteTests.cpp
===
--- clangd/unittests/CodeCompleteTests.cpp
+++ clangd/unittests/CodeCompleteTests.cpp
@@ -22,9 +22,11 @@
 #include "index/MemIndex.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/AtomicOrdering.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock-generated-matchers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -174,6 +176,7 @@
   int BBB();
   int CCC();
 };
+
 int main() { ClassWithMembers().^ }
   )cpp",
  /*IndexSymbols=*/{}, Opts);
@@ -324,7 +327,7 @@
   }
 }
 
-TEST(CompletionTest, Priorities) {
+TEST(CompletionTest, Accessible) {
   auto Internal = completions(R"cpp(
   class Foo {
 public: void pub();
@@ -334,7 +337,7 @@
   void Foo::pub() { this->^ }
   )cpp");
   EXPECT_THAT(Internal.Completions,
-  HasSubsequence(Named("priv"), Named("prot"), Named("pub")));
+  AllOf(Has("priv"), Has("prot"), Has("pub")));
 
   auto External = completions(R"cpp(
   class Foo {
@@ -502,6 +505,21 @@
   HasSubsequence(Named("absl"), Named("absb")));
 }
 
+TEST(CompletionTest, ContextWords) {
+  auto Results = completions(R"cpp(
+  enum class Color { RED, YELLOW, BLUE };
+
+  // (blank lines so the definition above isn't "context")
+
+  // "It was a yellow car," he said. "Big yellow car, new."
+  auto Finish = Color::^
+  )cpp");
+  // Yellow would normally sort last (alphabetic).
+  // But the recent mention shuold bump it up.
+  ASSERT_THAT(Results.Completions,
+  HasSubsequence(Named("YELLOW"), Named("BLUE")));
+}
+
 TEST(CompletionTest, GlobalQualified) {
   auto Results = completions(
   R"cpp(
Index: clangd/test/completion-auto-trigger.test
===
--- clangd/test/completion-auto-trigger.test
+++ clangd/test/completion-auto-trigger.test
@@ -23,7 +23,7 @@
 # CHECK-NEXT:"insertTextFormat": 1,
 # CHECK-NEXT:"kind": 5,
 # CHECK-NEXT:"label": " size",
-# CHECK-NEXT:"sortText": "3eacsize",
+# CHECK-NEXT:"sortText": "{{.*}}size",
 # CHECK-NEXT:"textEdit": {
 # CHECK-NEXT:  "newText": "size",
 # CHECK-NEXT:  "range": {
@@ -45,7 +45,7 @@
 # CHECK-NEXT: "insertTextFormat": 1,
 # CHECK-NEXT: "kind": 10,
 # CHECK-NEXT: "label": " 

[PATCH] D61549: Fix use of 'is' operator for comparison

2019-05-04 Thread Raul Tambre via Phabricator via cfe-commits
tambre created this revision.
tambre added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The 'is' operator is not meant to be used for comparisons. It currently working 
is an implementation detail of CPython.
CPython 3.8 has added a SyntaxWarning for this.


Repository:
  rC Clang

https://reviews.llvm.org/D61549

Files:
  clang/tools/clang-format/clang-format.py


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -118,7 +118,7 @@
 lines = lines[1:]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
-  if op[0] is not 'equal':
+  if op[0] != 'equal':
 vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]]
 if output.get('IncompleteFormat'):
   print('clang-format: incomplete (syntax errors)')


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -118,7 +118,7 @@
 lines = lines[1:]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
-  if op[0] is not 'equal':
+  if op[0] != 'equal':
 vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]]
 if output.get('IncompleteFormat'):
   print('clang-format: incomplete (syntax errors)')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-05-04 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added a comment.
This revision is now accepted and ready to land.

Hello Gabor!
This looks good to me, but let's wait for LLDB guys to take a look at the 
patch. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61333



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


[PATCH] D59692: [ASTImporter] Fix name conflict handling

2019-05-04 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D59692



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


[PATCH] D61424: [ASTImporter] Fix inequivalence of unresolved exception spec

2019-05-04 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added a comment.
This revision is now accepted and ready to land.

Looks good!




Comment at: clang/lib/AST/ASTImporter.cpp:3107
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.
   }

This looks to be true -  a call `adjustExceptionSpec()` on the imported decl 
and its redeclarations can be required. Thank you for noticing this!



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:325
 
+/// Check the eqeuivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,

equivalence


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61424



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


r359967 - [c++20] Implement P0428R2 - Familiar template syntax for generic lambdas

2019-05-04 Thread Hamza Sood via cfe-commits
Author: hamzasood
Date: Sat May  4 03:49:46 2019
New Revision: 359967

URL: http://llvm.org/viewvc/llvm-project?rev=359967&view=rev
Log:
[c++20] Implement P0428R2 - Familiar template syntax for generic lambdas

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

Added:
cfe/trunk/test/CodeGenCXX/mangle-lambda-explicit-template-params.cpp
cfe/trunk/test/PCH/cxx2a-template-lambdas.cpp
cfe/trunk/test/Parser/cxx2a-template-lambdas.cpp
cfe/trunk/test/SemaCXX/cxx2a-template-lambdas.cpp

cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
cfe/trunk/test/Index/print-display-names.cpp
cfe/trunk/test/PCH/cxx11-lambdas.mm
cfe/trunk/test/PCH/cxx1y-lambdas.mm
cfe/trunk/unittests/AST/StmtPrinterTest.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=359967&r1=359966&r2=359967&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat May  4 03:49:46 2019
@@ -1221,6 +1221,9 @@ public:
   /// lambda.
   TemplateParameterList *getGenericLambdaTemplateParameterList() const;
 
+  /// Retrieve the lambda template parameters that were specified explicitly.
+  ArrayRef getLambdaExplicitTemplateParameters() const;
+
   LambdaCaptureDefault getLambdaCaptureDefault() const {
 assert(isLambda());
 return static_cast(getLambdaData().CaptureDefault);

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=359967&r1=359966&r2=359967&view=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Sat May  4 03:49:46 2019
@@ -176,6 +176,11 @@ public:
 return SourceRange(TemplateLoc, RAngleLoc);
   }
 
+  void print(raw_ostream &Out, const ASTContext &Context,
+ bool OmitTemplateKW = false) const;
+  void print(raw_ostream &Out, const ASTContext &Context,
+ const PrintingPolicy &Policy, bool OmitTemplateKW = false) const;
+
 public:
   // FIXME: workaround for MSVC 2013; remove when no longer needed
   using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner;

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=359967&r1=359966&r2=359967&view=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sat May  4 03:49:46 2019
@@ -1899,6 +1899,10 @@ public:
   /// parameter list associated with it, or else return null.
   TemplateParameterList *getTemplateParameterList() const;
 
+  /// Get the template parameters were explicitly specified (as opposed to 
being
+  /// invented by use of an auto parameter).
+  ArrayRef getExplicitTemplateParameters() const;
+
   /// Whether this is a generic lambda.
   bool isGenericLambda() const { return getTemplateParameterList(); }
 

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=359967&r1=359966&r2=359967&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Sat May  4 03:49:46 2019
@@ -2423,6 +2423,10 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
 FunctionProtoTypeLoc Proto = TL.getAsAdjusted();
 
+for (Decl *D : S->getExplicitTemplateParameters()) {
+  // Visit explicit template parameters.
+  TRY_TO(TraverseDecl(D));
+}
 if (S->hasExplicitParameters()) {
   // Visit parameters.
   for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)

Modified: cfe/trunk/include/clang/Basic/Diagnost

[PATCH] D61464: [RiscV] Typo in register aliases

2019-05-04 Thread John LLVM via Phabricator via cfe-commits
JohnLLVM added a comment.

What should I do now? I do not have rights to commit.


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

https://reviews.llvm.org/D61464



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


[PATCH] D36527: Implemented P0428R2 - Familiar template syntax for generic lambdas

2019-05-04 Thread Hamza Sood via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359967: [c++20] Implement P0428R2 - Familiar template syntax 
for generic lambdas (authored by hamzasood, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D36527?vs=177221&id=198134#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D36527

Files:
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/AST/DeclTemplate.h
  cfe/trunk/include/clang/AST/ExprCXX.h
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/lib/AST/ExprCXX.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/StmtPrinter.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Parse/ParseExprCXX.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  cfe/trunk/test/CodeGenCXX/mangle-lambda-explicit-template-params.cpp
  cfe/trunk/test/Index/print-display-names.cpp
  cfe/trunk/test/PCH/cxx11-lambdas.mm
  cfe/trunk/test/PCH/cxx1y-lambdas.mm
  cfe/trunk/test/PCH/cxx2a-template-lambdas.cpp
  cfe/trunk/test/Parser/cxx2a-template-lambdas.cpp
  cfe/trunk/test/SemaCXX/cxx2a-template-lambdas.cpp
  cfe/trunk/unittests/AST/StmtPrinterTest.cpp
  cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp
  cfe/trunk/www/cxx_status.html

Index: cfe/trunk/test/PCH/cxx2a-template-lambdas.cpp
===
--- cfe/trunk/test/PCH/cxx2a-template-lambdas.cpp
+++ cfe/trunk/test/PCH/cxx2a-template-lambdas.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t
+// RUN: %clang_cc1 -std=c++2a -include-pch %t -verify %s
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+auto l1 = []() constexpr -> int {
+return I;
+};
+
+auto l2 = []() constexpr -> decltype(I) {
+return I;
+};
+
+auto l3 = [](auto i) constexpr -> T {
+  return T(i);
+};
+
+auto l4 = [] class T, class U>(T, auto i) constexpr -> U {
+  return U(i);
+};
+
+#else /*included pch*/
+
+static_assert(l1.operator()<5>() == 5);
+static_assert(l1.operator()<6>() == 6);
+
+static_assert(l2.operator()<7>() == 7);
+static_assert(l2.operator()() == nullptr);
+
+static_assert(l3.operator()(8.4) == 8);
+static_assert(l3.operator()(9.9) == 9);
+
+template
+struct DummyTemplate { };
+
+static_assert(l4(DummyTemplate(), 12) == 12.0);
+static_assert(l4(DummyTemplate(), 19.8) == 19);
+
+#endif // HEADER
Index: cfe/trunk/test/PCH/cxx11-lambdas.mm
===
--- cfe/trunk/test/PCH/cxx11-lambdas.mm
+++ cfe/trunk/test/PCH/cxx11-lambdas.mm
@@ -54,7 +54,7 @@
 }
 
 // CHECK-PRINT: inline int add_int_slowly_twice 
-// CHECK-PRINT: lambda = [&] (int z)
+// CHECK-PRINT: lambda = [&](int z)
 
 // CHECK-PRINT: init_capture
 // CHECK-PRINT: [&, x(t)]
Index: cfe/trunk/test/PCH/cxx1y-lambdas.mm
===
--- cfe/trunk/test/PCH/cxx1y-lambdas.mm
+++ cfe/trunk/test/PCH/cxx1y-lambdas.mm
@@ -50,7 +50,7 @@
 }
 
 // CHECK-PRINT: inline int add_int_slowly_twice 
-// CHECK-PRINT: lambda = [] (type-parameter-0-0 z
+// CHECK-PRINT: lambda = [](auto z
 
 // CHECK-PRINT: init_capture
 // CHECK-PRINT: [&, x(t)]
Index: cfe/trunk/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- cfe/trunk/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ cfe/trunk/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+template
+constexpr bool is_same = false;
+
+template
+constexpr bool is_same = true;
+
+template
+struct DummyTemplate { };
+
+void func() {
+  auto L0 = [](T arg) {
+static_assert(is_same); // expected-error {{static_assert failed}}
+  };
+  L0(0);
+  L0(0.0); // expected-note {{in instantiation}}
+
+  auto L1 = [] {
+static_assert(I == 5); // expected-error {{static_assert failed}}
+  };
+  L1.operator()<5>();
+  L1.operator()<6>(); // expected-note {{in instantiation}}
+
+  auto L2 = [] class T, class U>(T &&arg) {
+static_assert(is_same, DummyTemplate>); // // expected-error {{static_assert failed}}
+  };
+  L2(DummyTemplate());
+  L2(DummyTemplate()); // expected-note {{in instantiation}}
+}
+
+template // expected-note {{declared here}}
+struct ShadowMe {
+  void member_func() {
+auto L = [] { }; // expected-error {{'T' shadows template parameter}}
+  }
+};
+
+template
+constexpr T outer() {
+  return []() { return x; }.template operator()<123>(); // expected-error {{no matching 

[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-04 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added a comment.
This revision is now accepted and ready to land.

đź‘Ť




Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:277
   merger.RemoveSources(importer_source);
-  return ret;
+  if (ret_or_error)
+return *ret_or_error;

'true' body needs to be surrounded by braces as well. Same below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438



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


r359968 - [NFC] Add parentheses to avoid -Wparentheses.

2019-05-04 Thread Nicolas Lesser via cfe-commits
Author: rakete
Date: Sat May  4 04:28:11 2019
New Revision: 359968

URL: http://llvm.org/viewvc/llvm-project?rev=359968&view=rev
Log:
[NFC] Add parentheses to avoid -Wparentheses.

Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=359968&r1=359967&r2=359968&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat May  4 04:28:11 2019
@@ -3891,7 +3891,7 @@ void Parser::ParseDeclarationSpecifiers(
   continue;
 }
 
-assert(!isAlreadyConsumed || RangeEnd != SourceLocation() &&
+assert((!isAlreadyConsumed || RangeEnd != SourceLocation()) &&
  "both or neither of isAlreadyConsumed and 
"
  "RangeEnd needs to be set");
 DS.SetRangeEnd(isAlreadyConsumed ? RangeEnd : Tok.getLocation());


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


[PATCH] D61552: [clang] Adapt ASTMatcher to explicit(bool) specifier

2019-05-04 Thread Tyker via Phabricator via cfe-commits
Tyker created this revision.
Tyker added a reviewer: klimek.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changes:

- add an ast matcher for deductiong guide.
- allow isExplicit matcher for deductiong guide.
- add hasExplicitSpecifier matcher which matches for declarations that have an 
explicit specifier even if it is unresolved or resolved to false.
- added test for all of the above.


Repository:
  rC Clang

https://reviews.llvm.org/D61552

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -810,6 +810,31 @@
   cxxConversionDecl(isExplicit(;
   EXPECT_TRUE(notMatches("struct S { operator int(); };",
  cxxConversionDecl(isExplicit(;
+  EXPECT_TRUE(matchesConditionally(
+  "template struct S { explicit(b) operator int(); };",
+  cxxConversionDecl(isExplicit()), false, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally(
+  "struct S { explicit(true) operator int(); };",
+  cxxConversionDecl(isExplicit()), true, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally(
+  "struct S { explicit(false) operator int(); };",
+  cxxConversionDecl(isExplicit()), false, "-std=c++2a"));
+}
+
+TEST(ConversionDeclaration, HasExplicitSpecifier) {
+  EXPECT_TRUE(matches("struct S { explicit operator int(); };",
+  cxxConversionDecl(hasExplicitSpecifier(;
+  EXPECT_TRUE(notMatches("struct S { operator int(); };",
+ cxxConversionDecl(hasExplicitSpecifier(;
+  EXPECT_TRUE(matchesConditionally(
+  "template struct S { explicit(b) operator int(); };",
+  cxxConversionDecl(hasExplicitSpecifier()), true, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally(
+  "struct S { explicit(true) operator int(); };",
+  cxxConversionDecl(hasExplicitSpecifier()), true, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally(
+  "struct S { explicit(false) operator int(); };",
+  cxxConversionDecl(hasExplicitSpecifier()), true, "-std=c++2a"));
 }
 
 TEST(Matcher, ArgumentCount) {
@@ -1129,6 +1154,77 @@
   cxxConstructorDecl(isExplicit(;
   EXPECT_TRUE(notMatches("struct S { S(int); };",
  cxxConstructorDecl(isExplicit(;
+  EXPECT_TRUE(matchesConditionally(
+  "template struct S { explicit(b) S(int);};",
+  cxxConstructorDecl(isExplicit()), false, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally("struct S { explicit(true) S(int);};",
+   cxxConstructorDecl(isExplicit()), true,
+   "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally("struct S { explicit(false) S(int);};",
+   cxxConstructorDecl(isExplicit()), false,
+   "-std=c++2a"));
+}
+
+TEST(ConstructorDeclaration, HasExplicitSpecifier) {
+  EXPECT_TRUE(matches("struct S { explicit S(int); };",
+  cxxConstructorDecl(hasExplicitSpecifier(;
+  EXPECT_TRUE(notMatches("struct S { S(int); };",
+ cxxConstructorDecl(hasExplicitSpecifier(;
+  EXPECT_TRUE(matchesConditionally(
+  "template struct S { explicit(b) S(int);};",
+  cxxConstructorDecl(hasExplicitSpecifier()), true, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally("struct S { explicit(true) S(int);};",
+   cxxConstructorDecl(hasExplicitSpecifier()),
+   true, "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally("struct S { explicit(false) S(int);};",
+   cxxConstructorDecl(hasExplicitSpecifier()),
+   true, "-std=c++2a"));
+}
+
+TEST(DeductionGuideDeclaration, IsExplicit) {
+  EXPECT_TRUE(matchesConditionally("template struct S { S(int);};"
+   "S(int) -> S;",
+   cxxDeductionGuideDecl(isExplicit()), false,
+   "-std=c++17"));
+  EXPECT_TRUE(matchesConditionally("template struct S { S(int);};"
+   "explicit S(int) -> S;",
+   cxxDeductionGuideDecl(isExplicit()), true,
+   "-std=c++17"));
+  EXPECT_TRUE(matchesConditionally("template struct S { S(int);};"
+   "explicit(true) S(int) -> S;",
+   cxxDeductionGuideDecl(isExplicit()), true,
+   "-std=c++2a"));
+  EXPECT_TRUE(matchesConditionally("template struct S { S(int);};"
+   

[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-04 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added inline comments.



Comment at: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp:1980
+  }
+  return *type_or_error;
 }

>>! In D61438#1490102, @jingham wrote:
> [...] include the contents of that error n the log message?
e.g:
```
if (auto type_owner = merger.ImporterForOrigin(from_context).Import(type)) {
  return *type_owner;
} else {
  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
  LLDB_LOG_ERROR(log, type_owner.takeError(), "Couldn't import type: {0}")
  return QualType();
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438



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


[PATCH] D58573: [analyzer] Move UninitializedObjectChecker out of alpha

2019-05-04 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

Thank you for the fixes!  Another crash: 
https://bugs.llvm.org/show_bug.cgi?id=41741


Repository:
  rC Clang

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

https://reviews.llvm.org/D58573



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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2019-05-04 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 198139.
Rakete added a comment.

Don't leak memory and friendly ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/test/CXX/drs/dr5xx.cpp
  clang/test/CXX/temp/temp.res/p5.cpp
  clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-member-initializers.cpp
  clang/test/Parser/editor-placeholder-recovery.cpp
  clang/test/SemaCXX/MicrosoftCompatibility.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/MicrosoftSuper.cpp
  clang/test/SemaCXX/unknown-type-name.cpp

Index: clang/test/SemaCXX/unknown-type-name.cpp
===
--- clang/test/SemaCXX/unknown-type-name.cpp
+++ clang/test/SemaCXX/unknown-type-name.cpp
@@ -36,15 +36,15 @@
 
   static int n;
   static type m;
-  static int h(T::type, int); // expected-error{{missing 'typename'}}
-  static int h(T::type x, char); // expected-error{{missing 'typename'}}
+  static int h(T::type, int); // expected-warning{{implicit 'typename' is a C++2a extension}}
+  static int h(T::type x, char); // expected-warning{{implicit 'typename' is a C++2a extension}}
 };
 
 template
-A::type g(T t) { return t; } // expected-error{{missing 'typename'}}
+A::type g(T t) { return t; } // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template
-A::type A::f() { return type(); } // expected-error{{missing 'typename'}}
+A::type A::f() { return type(); } // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template
 void f(T::type) { } // expected-error{{missing 'typename'}}
@@ -72,9 +72,7 @@
 
 int *p;
 
-// FIXME: We should assume that 'undeclared' is a type, not a parameter name
-//here, and produce an 'unknown type name' diagnostic instead.
-int f1(undeclared, int); // expected-error{{requires a type specifier}}
+int f1(undeclared, int); // expected-error{{unknown type name 'undeclared'}}
 
 int f2(undeclared, 0); // expected-error{{undeclared identifier}}
 
@@ -86,11 +84,11 @@
 
 template int A::n(T::value); // ok
 template
-A::type // expected-error{{missing 'typename'}}
+A::type // expected-warning {{implicit 'typename' is a C++2a extension}}
 A::m(T::value, 0); // ok
 
-template int A::h(T::type, int) {} // expected-error{{missing 'typename'}}
-template int A::h(T::type x, char) {} // expected-error{{missing 'typename'}}
+template int A::h(T::type, int) {} // expected-warning{{implicit 'typename' is a C++2a extension}}
+template int A::h(T::type x, char) {} // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template int h(T::type, int); // expected-error{{missing 'typename'}}
 template int h(T::type x, char); // expected-error{{missing 'typename'}}
@@ -118,4 +116,5 @@
 // FIXME: We know which type specifier should have been specified here. Provide
 //a fix-it to add 'typename A::type'
 template
-A::g() { } // expected-error{{requires a type specifier}}
+A::g() { } // expected-error{{expected unqualified-id}}
+// expected-warning@-1{{implicit 'typename' is a C++2a extension}}
Index: clang/test/SemaCXX/MicrosoftSuper.cpp
===
--- clang/test/SemaCXX/MicrosoftSuper.cpp
+++ clang/test/SemaCXX/MicrosoftSuper.cpp
@@ -108,8 +108,8 @@
   typename __super::XXX a;
   typedef typename __super::XXX b;
 
-  __super::XXX c; // expected-error {{missing 'typename'}}
-  typedef __super::XXX d; // expected-error {{missing 'typename'}}
+  __super::XXX c; // expected-warning {{implicit 'typename' is a C++2a extension}}
+  typedef __super::XXX d; // expected-warning {{implicit 'typename' is a C++2a extension}}
 
   void foo() {
 typename __super::XXX e;
@@ -127,8 +127,8 @@
   typename __super::XXX a;
   typedef typename __super::XXX b;
 
-  __super::XXX c; // expected-error {{missing 'typename'}}
-  typedef __super::XXX d; // expected-error {{missing 'typename'}}
+  __super::XXX c; // expected-warning {{implicit 'typename' is a C++2a extension}}
+  typedef __super::XXX d; // expected-warning {{implicit 'typename' is a C++2a extension}}
 
   void foo() {
 typename __super::XXX e;
Index: clang/test/SemaCXX/MicrosoftExtensions.cpp
===

[PATCH] D36357: Added a better diagnostic when using the delete operator with lambdas

2019-05-04 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 198142.
Rakete added a comment.

friendly ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36357

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/FixIt/fixit-cxx0x.cpp
  clang/test/Parser/cxx0x-lambda-expressions.cpp
  clang/test/SemaCXX/new-delete-0x.cpp

Index: clang/test/SemaCXX/new-delete-0x.cpp
===
--- clang/test/SemaCXX/new-delete-0x.cpp
+++ clang/test/SemaCXX/new-delete-0x.cpp
@@ -34,6 +34,6 @@
 void bad_deletes()
 {
   // 'delete []' is always array delete, per [expr.delete]p1.
-  // FIXME: Give a better diagnostic.
-  delete []{ return (int*)0; }(); // expected-error {{expected expression}}
+  delete []{ return (int*)0; }(); // expected-error {{'[]' after delete interpreted as 'delete[]'}}
 }
+
Index: clang/test/Parser/cxx0x-lambda-expressions.cpp
===
--- clang/test/Parser/cxx0x-lambda-expressions.cpp
+++ clang/test/Parser/cxx0x-lambda-expressions.cpp
@@ -53,8 +53,11 @@
   void delete_lambda(int *p) {
 delete [] p;
 delete [] (int*) { new int }; // ok, compound-literal, not lambda
-delete [] { return new int; } (); // expected-error{{expected expression}}
+delete [] { return new int; } (); // expected-error {{'[]' after delete interpreted as 'delete[]'}}
 delete [&] { return new int; } (); // ok, lambda
+
+delete []() { return new int; }(); // expected-error{{'[]' after delete interpreted as 'delete[]'}}
+delete [](E Enum) { return new int((int)Enum); }(e); // expected-error{{'[]' after delete interpreted as 'delete[]'}}
   }
 
   // We support init-captures in C++11 as an extension.
Index: clang/test/FixIt/fixit-cxx0x.cpp
===
--- clang/test/FixIt/fixit-cxx0x.cpp
+++ clang/test/FixIt/fixit-cxx0x.cpp
@@ -58,6 +58,9 @@
   (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
   (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
   (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}}
+
+  delete []() { return new int; }(); // expected-error{{'[]' after delete interpreted as 'delete[]'}}
+  delete [] { return new int; }(); // expected-error{{'[]' after delete interpreted as 'delete[]'}}
 }
 
 #define bar "bar"
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2984,8 +2984,38 @@
 //   [Footnote: A lambda expression with a lambda-introducer that consists
 //  of empty square brackets can follow the delete keyword if
 //  the lambda expression is enclosed in parentheses.]
-// FIXME: Produce a better diagnostic if the '[]' is unambiguously a
-//lambda-introducer.
+
+const Token Next = GetLookAheadToken(2);
+
+// Basic lookahead to check if we have a lambda expression.
+if (Next.isOneOf(tok::l_brace, tok::less) ||
+(Next.is(tok::l_paren) &&
+ (GetLookAheadToken(3).is(tok::r_paren) ||
+  (GetLookAheadToken(3).is(tok::identifier) &&
+   GetLookAheadToken(4).is(tok::identifier) {
+  SourceLocation RightBracketLock = NextToken().getLocation();
+  // Warn if the non-capturing lambda isn't surrounded by parenthesis
+  // to disambiguate it from 'delete[]'.
+  ExprResult Lambda = ParseLambdaExpression();
+  if (Lambda.isInvalid())
+return ExprError();
+
+  SourceLocation StartLoc = Lambda.get()->getBeginLoc();
+  Diag(Start, diag::err_lambda_after_delete)
+  << SourceRange(Start, RightBracketLock)
+  << FixItHint::CreateInsertion(StartLoc, "(")
+  << FixItHint::CreateInsertion(
+ Lexer::getLocForEndOfToken(Lambda.get()->getEndLoc(), 0,
+Actions.getSourceManager(),
+getLangOpts()),
+ ")");
+
+  // Evaluate any postfix expressions used on the lambda.
+  Lambda = ParsePostfixExpressionSuffix(Lambda);
+  return Actions.ActOnCXXDelete(Start, UseGlobal, /*ArrayForm=*/false,
+Lambda.get());
+}
+
 ArrayDelete = true;
 BalancedDelimiterTracker T(*this, tok::l_square);
 
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -105,6 +105,8 @@
   InGroup, DefaultIgnore;
 def ext_alignof_expr : ExtWarn<
   "%0 applied to an expression is a GNU extension">, InGroup;
+def err_lambda_after

[PATCH] D56160: [clang-tidy] modernize-use-trailing-return-type check

2019-05-04 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added inline comments.



Comment at: clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:274
+
+  if (F->getLocation().isInvalid())
+return;

aaron.ballman wrote:
> bernhardmgruber wrote:
> > aaron.ballman wrote:
> > > bernhardmgruber wrote:
> > > > aaron.ballman wrote:
> > > > > Should this also bail out if the function is `main()`?
> > > > How strange does
> > > > 
> > > > ```
> > > > auto main(int argc, const char* argv[]) -> int {
> > > > return 0;
> > > > }
> > > > ```
> > > > look to you?
> > > > 
> > > > I think the transformation is valid here. But I can understand that 
> > > > people feel uneasy after typing `int main ...` for decades. Should we 
> > > > also create an option here to turn it off for main? Or just not 
> > > > transform it? I do not mind. If I want `main` to start with `auto` I 
> > > > could also do this transformation manually.
> > > This comment was marked as done, but I don't see any changes or mention 
> > > of what should happen. I suppose the more general question is: should 
> > > there be a list of functions that should not have this transformation 
> > > applied, like program entrypoints? Or do you want to see this check 
> > > diagnose those functions as well?
> > I am sorry for marking it as done. I do not know how people work here 
> > exactly and how phabricator behaves. I thought the check boxes are handled 
> > for everyone individually. Also, if I add a new comment, it is checked by 
> > default.
> > 
> > How are you/most people going to use clang-tidy? Do you run it regularly 
> > and automatic? Do you expect it to find zero issues once you applied the 
> > check?
> > In other words, if you do not want to transform some functions, do you need 
> > an option to disable the check for these, so it runs clean on the full 
> > source code?
> > 
> > Personally, I do not need this behavior, as I run clang-tidy manually once 
> > in a while and revert transformations I do not want before checking in the 
> > changes.
> > I am sorry for marking it as done. I do not know how people work here 
> > exactly and how phabricator behaves. I thought the check boxes are handled 
> > for everyone individually. Also, if I add a new comment, it is checked by 
> > default.
> 
> No worries -- that new comments are automatically marked done by default is 
> certainly a surprise to me!
> 
> > How are you/most people going to use clang-tidy? Do you run it regularly 
> > and automatic? Do you expect it to find zero issues once you applied the 
> > check? In other words, if you do not want to transform some functions, do 
> > you need an option to disable the check for these, so it runs clean on the 
> > full source code?
> 
> I think it's hard to gauge how most people do anything, really. However, I 
> think there are people who enable certain clang-tidy checks and have them run 
> automatically as part of CI, etc. Those kind of folks may need the ability to 
> silence the diagnostics. We could do this in a few ways (options to control 
> methods not to diagnose, NOLINT comments, etc).
> 
> I kind of think we don't need an option for the user to list functions not to 
> transform. They can use NOLINT to cover those situations as a one-off. The 
> only situation where I wonder if everyone is going to want to write NOLINT is 
> for `main()`. It might make sense to have an option to not check program 
> entrypoints, but there is technically nothing stopping someone from using a 
> trailing return type with a program entrypoint so maybe this option isn't 
> needed at all.
> 
> How about we not add any options and if someone files a bug report, we can 
> address it then?
> How about we not add any options and if someone files a bug report, we can 
> address it then?

Sounds good to me!



Comment at: clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp:180-184
+  if (Info.hasMacroDefinition()) {
+// The CV qualifiers of the return type are inside macros.
+diag(F.getLocation(), Message);
+return {};
+  }

aaron.ballman wrote:
> bernhardmgruber wrote:
> > aaron.ballman wrote:
> > > Perhaps I'm a bit dense on a Monday morning, but why should this be a 
> > > diagnostic? I am worried this will diagnose situations like (untested 
> > > guesses):
> > > ```
> > > #define const const
> > > const int f(void); // Why no fixit?
> > > 
> > > #define attr __attribute__((frobble))
> > > attr void g(void); // Why diagnosed as needing a trailing return type?
> > > ```
> > Because I would also like to rewrite functions which contain macros in the 
> > return type. However, I cannot provide a fixit in all cases. Clang can give 
> > me a `SourceRange` without CV qualifiers which seems to work in all my 
> > tests so far. But to include CV qualifiers I have to do some manual lexing 
> > left and right of the return type `SourceRange`. If I encounter macros 
> > along this way, I bail out because 

[PATCH] D56160: [clang-tidy] modernize-use-trailing-return-type check

2019-05-04 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber updated this revision to Diff 198143.
bernhardmgruber marked 9 inline comments as done.
bernhardmgruber added a comment.

It took a long while to figure out how to handle certain macro cases. Here is 
what I came up with:

When tokenizing the source code from the beginning of the function to the 
function name, I now use clang's `Preprocessor` to lex these tokens again and 
expand macros on the way. I analyse the top-level macros if they just contain 
specifiers or qualifiers and store this information in a `ClassifiedToken`. 
When I later try to expand the return type location to include qualifiers, or 
when I want to remove specifiers from the return type range, I can use this 
information to also include/reprosition macros which I can regard as qualifiers 
or specifiers. This currently solves a lot of cases where macros are part of 
the return type.

Function style macros as part of the return type are not supported, as they are 
harder to lex and expand. The check currently provides no fixit in these cases.

Other changes:

- `expandIfMacroId()` now expands recursively because the `SourceLocation` 
might be inside nested macros
- renamed `nonMacroTokensBeforeFunctionName()` into 
`classifyTokensBeforeFunctionName()`
- improved some comments
- overriding `registerPPCallbacks` to hijack a reference to the preprocessor
- expanding macro ids in the initial return type source range gotten from the 
`FunctionDecl`


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

https://reviews.llvm.org/D56160

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-trailing-return-type.rst
  test/clang-tidy/modernize-use-trailing-return-type.cpp

Index: test/clang-tidy/modernize-use-trailing-return-type.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-trailing-return-type.cpp
@@ -0,0 +1,563 @@
+// RUN: %check_clang_tidy %s modernize-use-trailing-return-type %t -- -- --std=c++14 -fdeclspec
+
+namespace std {
+template 
+class vector;
+
+template 
+class array;
+
+class string;
+
+template 
+auto declval() -> T;
+}
+
+//
+// Functions
+//
+
+int f();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f() -> int;{{$}}
+int ((f))();
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto ((f))() -> int;{{$}}
+int f(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int) -> int;{{$}}
+int f(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg) -> int;{{$}}
+int f(int arg1, int arg2, int arg3);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg1, int arg2, int arg3) -> int;{{$}}
+int f(int arg1, int arg2, int arg3, ...);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg1, int arg2, int arg3, ...) -> int;{{$}}
+template  int f(T t);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}template  auto f(T t) -> int;{{$}}
+
+//
+// Functions with formatting
+//
+
+int a1() { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a1() -> int { return 42; }{{$}}
+int a2() {
+return 42;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a2() -> int {{{$}}
+int a3()
+{
+return 42;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a3() -> int{{$}}
+int a4(int   arg   )   ;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a4(int   arg   ) -> int   ;{{$}}
+int a5
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a5{{$}}
+(int arg);
+// CHECK-FIXES: {{^}}(int arg) -> int;{{$}}
+const
+int
+*
+a7
+// CH

Re: r359960 - Reduce amount of work ODR hashing does.

2019-05-04 Thread David Blaikie via cfe-commits
Does the ODR hashing have some sort of cycle breaking infrastructure -
so that if the same type is seen more than once (eg: classes have
members that have pointers back to the outer class type, etc) they
don't cause indefinite cycles? Should that infrastructure have caught
these cases & avoided the redundant work?

I'm curious to understand better how these things work/overlap/or don't.

On Fri, May 3, 2019 at 9:20 PM Richard Trieu via cfe-commits
 wrote:
>
> Author: rtrieu
> Date: Fri May  3 21:22:33 2019
> New Revision: 359960
>
> URL: http://llvm.org/viewvc/llvm-project?rev=359960&view=rev
> Log:
> Reduce amount of work ODR hashing does.
>
> When a FunctionProtoType is in the original type in a DecayedType, the decayed
> type is a PointerType which points back the original FunctionProtoType.  The
> visitor for ODRHashing will attempt to process both Type's, doing double work.
> By chaining together multiple DecayedType's and FunctionProtoType's, this 
> would
> result in 2^N Type's visited only N DecayedType's and N FunctionProtoType's
> exsit.  Another bug where VisitDecayedType and VisitAdjustedType did
> redundant work doubled the work at each level, giving 4^N Type's visited.  
> This
> patch removed the double work and detects when a FunctionProtoType decays to
> itself to only check the Type once.  This lowers the exponential runtime to
> linear runtime.  Fixes https://bugs.llvm.org/show_bug.cgi?id=41625
>
> Modified:
> cfe/trunk/lib/AST/ODRHash.cpp
> cfe/trunk/test/Modules/odr_hash.cpp
>
> Modified: cfe/trunk/lib/AST/ODRHash.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=359960&r1=359959&r2=359960&view=diff
> ==
> --- cfe/trunk/lib/AST/ODRHash.cpp (original)
> +++ cfe/trunk/lib/AST/ODRHash.cpp Fri May  3 21:22:33 2019
> @@ -703,14 +703,36 @@ public:
>void VisitType(const Type *T) {}
>
>void VisitAdjustedType(const AdjustedType *T) {
> -AddQualType(T->getOriginalType());
> -AddQualType(T->getAdjustedType());
> +QualType Original = T->getOriginalType();
> +QualType Adjusted = T->getAdjustedType();
> +
> +// The original type and pointee type can be the same, as in the case of
> +// function pointers decaying to themselves.  Set a bool and only process
> +// the type once, to prevent doubling the work.
> +SplitQualType split = Adjusted.split();
> +if (auto Pointer = dyn_cast(split.Ty)) {
> +  if (Pointer->getPointeeType() == Original) {
> +Hash.AddBoolean(true);
> +ID.AddInteger(split.Quals.getAsOpaqueValue());
> +AddQualType(Original);
> +VisitType(T);
> +return;
> +  }
> +}
> +
> +// The original type and pointee type are different, such as in the case
> +// of a array decaying to an element pointer.  Set a bool to false and
> +// process both types.
> +Hash.AddBoolean(false);
> +AddQualType(Original);
> +AddQualType(Adjusted);
> +
>  VisitType(T);
>}
>
>void VisitDecayedType(const DecayedType *T) {
> -AddQualType(T->getDecayedType());
> -AddQualType(T->getPointeeType());
> +// getDecayedType and getPointeeType are derived from getAdjustedType
> +// and don't need to be separately processed.
>  VisitAdjustedType(T);
>}
>
>
> Modified: cfe/trunk/test/Modules/odr_hash.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=359960&r1=359959&r2=359960&view=diff
> ==
> --- cfe/trunk/test/Modules/odr_hash.cpp (original)
> +++ cfe/trunk/test/Modules/odr_hash.cpp Fri May  3 21:22:33 2019
> @@ -4587,6 +4587,43 @@ int num = bar();
>  #endif
>  }
>
> +namespace FunctionProtoTypeDecay {
> +#if defined(FIRST)
> +struct S1 {
> +  struct X {};
> +  using Y = X(X());
> +};
> +#elif defined(SECOND)
> +struct S1 {
> +  struct X {};
> +  using Y = X(X(X()));
> +};
> +#else
> +S1 s1;
> +// expected-error@first.h:* {{'FunctionProtoTypeDecay::S1::Y' from module 
> 'FirstModule' is not present in definition of 'FunctionProtoTypeDecay::S1' in 
> module 'SecondModule'}}
> +// expected-note@second.h:* {{declaration of 'Y' does not match}}
> +#endif
> +
> +#if defined(FIRST)
> +struct S2 {
> +  struct X {};
> +  using Y =
> +  X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
> +  X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
> +  X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
> +  X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
> +  
> +  
> +  
> +  ;
> +};
> +#elif defined(SECOND)
> +#else
> +S2 s2;
> +#endif
> +
> +}
> +
>  // Keep macros contained to one file.
>  #ifdef FIRST
>  #undef FIRST
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___

[PATCH] D40381: Parse concept definition

2019-05-04 Thread Saar Raz via Phabricator via cfe-commits
saar.raz added a comment.

@rsmith are we done with CR on this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D40381



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


[PATCH] D61508: [clang-tidy] misc-header-guard : a simple version of llvm-header-guard

2019-05-04 Thread Tom Rix via Phabricator via cfe-commits
trixirt updated this revision to Diff 198146.
trixirt edited the summary of this revision.
trixirt added a comment.

Addressed issue with returning early and using backtick in doc.
Since misc-header-guard doc was a cut-n-paste of llvm-header-guard, that and 
other similar docs were changed.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61508

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/HeaderGuardCheck.cpp
  clang-tidy/misc/HeaderGuardCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-build-namespaces.rst
  docs/clang-tidy/checks/google-global-names-in-headers.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/llvm-header-guard.rst
  docs/clang-tidy/checks/misc-definitions-in-headers.rst
  docs/clang-tidy/checks/misc-header-guard.rst
  test/clang-tidy/misc-header-guard.cpp

Index: test/clang-tidy/misc-header-guard.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-header-guard.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s misc-header-guard %t -- \
+// RUN:   -config="{CheckOptions: [{key: misc-header-guard.HeaderFileExtensions, value: 'cpp'}]}" \
+// RUN:   -header-filter=.* -- 
+
+// CHECK-MESSAGES: 1:1: warning:  header is missing header guard
+
+// CHECK-FIXES: #ifndef MISC_HEADER_GUARD_CPP_TMP_CPP
+// CHECK-FIXES-NEXT: #define MISC_HEADER_GUARD_CPP_TMP_CPP
+// CHECK-FIXES: #endif
Index: docs/clang-tidy/checks/misc-header-guard.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-header-guard.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - misc-header-guard
+
+misc-header-guard
+=
+
+Finds and fixes missing header guards and does not enforce any style.
+
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not include "." prefix). Default is `h,hh,hpp,hxx`.
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. e.g.,
+   `h,hh,hpp,hxx,` (note the trailing comma).
+
Index: docs/clang-tidy/checks/misc-definitions-in-headers.rst
===
--- docs/clang-tidy/checks/misc-definitions-in-headers.rst
+++ docs/clang-tidy/checks/misc-definitions-in-headers.rst
@@ -89,10 +89,10 @@
 .. option:: HeaderFileExtensions
 
A comma-separated list of filename extensions of header files (the filename
-   extensions should not include "." prefix). Default is "h,hh,hpp,hxx".
+   extensions should not include "." prefix). Default is `h,hh,hpp,hxx`.
For header files without an extension, use an empty string (if there are no
other desired extensions) or leave an empty element in the list. e.g.,
-   "h,hh,hpp,hxx," (note the trailing comma).
+   `h,hh,hpp,hxx,` (note the trailing comma).
 
 .. option:: UseHeaderFileExtension
 
Index: docs/clang-tidy/checks/llvm-header-guard.rst
===
--- docs/clang-tidy/checks/llvm-header-guard.rst
+++ docs/clang-tidy/checks/llvm-header-guard.rst
@@ -11,7 +11,7 @@
 .. option:: HeaderFileExtensions
 
A comma-separated list of filename extensions of header files (the filename
-   extensions should not include "." prefix). Default is "h,hh,hpp,hxx".
+   extensions should not include "." prefix). Default is `h,hh,hpp,hxx`.
For header files without an extension, use an empty string (if there are no
other desired extensions) or leave an empty element in the list. e.g.,
-   "h,hh,hpp,hxx," (note the trailing comma).
+   `h,hh,hpp,hxx,` (note the trailing comma).
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -181,6 +181,7 @@
llvm-prefer-isa-or-dyn-cast-in-conditionals
llvm-twine-local
misc-definitions-in-headers
+   misc-header-guard
misc-misplaced-const
misc-new-delete-overloads
misc-non-copyable-objects
Index: docs/clang-tidy/checks/google-global-names-in-headers.rst
===
--- docs/clang-tidy/checks/google-global-names-in-headers.rst
+++ docs/clang-tidy/checks/google-global-names-in-headers.rst
@@ -15,7 +15,7 @@
 .. option:: HeaderFileExtensions
 
A comma-separated list of filename extensions of header files (the filename
-   extensions should not contain "." prefix). Default is "h".
+   extensions should not include "." prefix). Default is `h,hh,hpp,hxx`.
For header files without an extension, use an empty string (if there are no
other desired extensions) or leave an empty element in the list. e.g.,
-   "h,hh,hpp,hxx," (note the traili

[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-04 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Alexey, is this is good to go now?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-04 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 198152.
plotfi added a comment.
Herald added subscribers: llvm-commits, MaskRay, hiraditya, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Adding support for multiple formats using -interface-stubs-version=.

I'll add another diff soon. My idea is what 
-interface-stubs-version=experimental-ifo-elf-v1 could be used to generate 
literally anything that works currently (which is likely to be a distillation 
of whatever is the latest obj2yaml schema), or 
-interface-stubs-version=tapi-tbe to generate valid elfabi tapi.

I've also added an optional Endian field to elf tapi because that seems pretty 
important to have.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp
  llvm/include/llvm/TextAPI/ELF/ELFStub.h
  llvm/lib/TextAPI/ELF/TBEHandler.cpp

Index: llvm/lib/TextAPI/ELF/TBEHandler.cpp
===
--- llvm/lib/TextAPI/ELF/TBEHandler.cpp
+++ llvm/lib/TextAPI/ELF/TBEHandler.cpp
@@ -134,6 +134,7 @@
 IO.mapRequired("TbeVersion", Stub.TbeVersion);
 IO.mapOptional("SoName", Stub.SoName);
 IO.mapRequired("Arch", (ELFArchMapper &)Stub.Arch);
+IO.mapOptional("Endian", Stub.Endian);
 IO.mapOptional("NeededLibs", Stub.NeededLibs);
 IO.mapRequired("Symbols", Stub.Symbols);
   }
Index: llvm/include/llvm/TextAPI/ELF/ELFStub.h
===
--- llvm/include/llvm/TextAPI/ELF/ELFStub.h
+++ llvm/include/llvm/TextAPI/ELF/ELFStub.h
@@ -55,6 +55,7 @@
   VersionTuple TbeVersion;
   Optional SoName;
   ELFArch Arch;
+  Optional Endian;
   std::vector NeededLibs;
   std::set Symbols;
 
Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,57 @@
+// Using %clang instead of %clang_cc1 because of -fvisibility
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: _Z4fbarff
+// CHECK: _Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: _Z3fooii
+// CHECK-NOT:_Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,8 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIfsoObjYamlExpV1: return llvm::make_unique();
+  case GenerateIfsoTbeExpV1:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@

[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2019-05-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:1784
  bool IsClassTemplateDeductionContext = true,
+ bool AllowImplicitTypename = false,
  IdentifierInfo **CorrectedII = nullptr);

It's dangerous to add a `bool` parameter like this, in a long list of `bool` 
parameters with default arguments. Please add an `enum` for 
`AllowImplicitTypename` and use it instead of the boolean flag.



Comment at: clang/lib/Parse/ParseDecl.cpp:2652-2654
+  // But only if we are not in a function prototype scope.
+  if (getCurScope()->isFunctionPrototypeScope())
+break;

Can you split out this error recovery improvement and commit it separately 
before the rest of this work? It doesn't appear to have any dependency on the 
rest of the change.



Comment at: clang/lib/Parse/ParseDecl.cpp:4859
 // recurse to handle whatever we get.
-if (TryAnnotateTypeOrScopeToken())
+if (TryAnnotateTypeOrScopeToken(!getCurScope()->isTemplateParamScope()))
   return true;

This seems surprising to me; I'd expect to have an implicit `typename` here 
approximately when not `DisambiguatingWithExpression`. Also basing this off the 
scope seems wrong, as we can switch into and out of implicit `typename` 
contexts multiple times within a scope. Eg, in `template>` we get an implicit `typename` for `T::template U` but not 
for `T::V` despite them being in the same scope.

Should the callers of this function be passing in an "implicit `typename`" flag?



Comment at: clang/lib/Parse/ParseDecl.cpp:5882
   if (getLangOpts().CPlusPlus && D.mayBeFollowedByCXXDirectInit()) {
+bool AllowImplicitTypename = false;
+if (D.getCXXScopeSpec().isSet())

A citation of the relevant wording here would be useful.



Comment at: clang/lib/Parse/ParseDecl.cpp:6444
+
+  bool AllowImplicitTypename;
+  if (D.getContext() == DeclaratorContext::MemberContext ||

Likewise a citation of the relevant rule here would be useful.



Comment at: clang/lib/Parse/ParseTentative.cpp:1280
+  bool AllowImplicitTypename) {
+  const bool NoImplicitTypename = !HasMissingTypename || 
!AllowImplicitTypename;
+

This seems unclear to me.

I think we should be passing `AllowImplicitTypename` directly to 
`TryAnnotate...`, rather than taking `HasMissingTypename` into account -- 
`AllowImplicitTypename` reflects the language rules, whereas 
`HasMissingTypename` is just an error recovery tool, so `HasMissingTypename` 
should not have any influence on how we annotate the token stream unless we 
actually detect an error.



Comment at: clang/lib/Parse/ParseTentative.cpp:1342
 // We annotated this token as something. Recurse to handle whatever we got.
 return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename);
   }

These recursive steps need to pass in the `AllowImplicitTypename` flag. Maybe 
the default argument should be removed for safety.



Comment at: clang/lib/Parse/Parser.cpp:1490
 Parser::AnnotatedNameKind
 Parser::TryAnnotateName(bool IsAddressOfOperand,
 std::unique_ptr CCC) {

Have you checked that this is never called in an implicit typename context?

Please update the documentation for this to say that it can never be called in 
such a context, or add an `AllowImplicitTypename` parameter as necessary.



Comment at: clang/lib/Sema/SemaTemplate.cpp:9503
+  QualType T = CheckTypenameType(
+  TypenameLoc.isValid() || IsImplicitTypename ? ETK_Typename : ETK_None,
+  TypenameLoc, QualifierLoc, II, IdLoc);

Please parenthesize the left-hand-side of this ternary operator.



Comment at: clang/test/CXX/drs/dr1xx.cpp:61
 struct B { typedef int X; };
-B::X x; // expected-error {{missing 'typename'}}
+B::X x; // expected-error {{implicit 'typename' is a C++2a extension}}
 struct C : B { X x; }; // expected-error {{unknown type name}}

For each of these `test/CXX/drs` tests that you change, please add a C++20 
`RUN:` line and update the diagnostic expectations to match in pre- and 
post-C++20 mode as applicable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847



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


[PATCH] D36357: Added a better diagnostic when using the delete operator with lambdas

2019-05-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Thanks! Some minor nits, please feel free to commit once they're addressed.

In D36357#1177852 , @Rakete wrote:

> Note that clang doesn't support the fourth kind of lambda yet ([]<>), because 
> D36527  hasn't been merged yet, so I didn't 
> add a test case for that one.


We support that now, so please add a test for that :)




Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:109
+def err_lambda_after_delete : Error<
+  "'[]' after delete interpreted as 'delete[]'">;
 

Please add to this: "; add parentheses to treat this as a lambda-expression" or 
similar.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:2996
+   GetLookAheadToken(4).is(tok::identifier) {
+  SourceLocation RightBracketLock = NextToken().getLocation();
+  // Warn if the non-capturing lambda isn't surrounded by parenthesis

`RightBracketLock` -> `RSquareLoc`

(Our convention is to use `Loc` for "location" and to avoid the word "bracket" 
because it means different things in different English dialects -- usually `[]` 
in US English and usually `()` in UK English.)



Comment at: clang/lib/Parse/ParseExprCXX.cpp:2997
+  SourceLocation RightBracketLock = NextToken().getLocation();
+  // Warn if the non-capturing lambda isn't surrounded by parenthesis
+  // to disambiguate it from 'delete[]'.

if -> that
parenthesis -> parentheses



Comment at: clang/lib/Parse/ParseExprCXX.cpp:3014
+  // Evaluate any postfix expressions used on the lambda.
+  Lambda = ParsePostfixExpressionSuffix(Lambda);
+  return Actions.ActOnCXXDelete(Start, UseGlobal, /*ArrayForm=*/false,

Maybe we should do this before producing the diagnostic so that we can suggest 
inserting the `)` after the complete expression? (But I don't have a strong 
preference either way.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36357



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


[PATCH] D40381: Parse concept definition

2019-05-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

LGTM with a few mechanical updates.




Comment at: include/clang/Basic/DiagnosticParseKinds.td:1262
+  "name defined in concept definition must be an identifier">;
+def err_concept_legacy_bool_keyword : ExtWarn<
+  "ISO C++2a does not permit the 'bool' keyword after 'concept'">,

`ExtWarn` diagnostics should be named `ext_` not `err_`. (This is important 
because readers of the code emitting the diagnostic need to know whether they 
can mark things as invalid (etc) during error recovery -- which is only correct 
to do after emitting an error.)



Comment at: include/clang/Sema/Sema.h:6676
+  // Concepts
+  Decl *ActOnConceptDefinition(Scope *S,
+  MultiTemplateParamsArg TemplateParameterLists, IdentifierInfo *Name,

Nit: please wrap the first parameter onto the next line.



Comment at: lib/AST/DeclTemplate.cpp:833-834
+ Expr *ConstraintExpr) {
+  // TODO: Do we need this?
+  //  AdoptTemplateParameterList(Params, cast(Decl));
+  return new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);

Yes, you need that :)

(You should be able to check this with `-ast-dump`: for a concept in a 
namespace, its template parameters should have the namespace as their semantic 
`DeclContext`, not the translation unit. This also has some impact on merging 
of default argument visibility with modules.)



Comment at: lib/Index/IndexDecl.cpp:677
 if (D->getTemplateParameters() &&
-shouldIndexTemplateParameterDefaultValue(Parent)) {
+shouldIndexTemplateParameterDefaultValue(D, Parent)) {
   const TemplateParameterList *Params = D->getTemplateParameters();

Please revert the addition of the unused first parameter.


Repository:
  rC Clang

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

https://reviews.llvm.org/D40381



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


[PATCH] D61552: [clang] Adapt ASTMatcher to explicit(bool) specifier

2019-05-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This seems reasonable to me, but I'll leave it to @klimek or someone else to 
judge whether the `isExplicit` / `hasExplicitSpecifier` approach is the right 
way to expose this functionality to matcher users.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61552



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-04 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 198157.
plotfi added a comment.

Changing experimental flag to -interface-stubs-version=experimental-ifo-elf-v1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp
  llvm/include/llvm/TextAPI/ELF/ELFStub.h
  llvm/lib/TextAPI/ELF/TBEHandler.cpp

Index: llvm/lib/TextAPI/ELF/TBEHandler.cpp
===
--- llvm/lib/TextAPI/ELF/TBEHandler.cpp
+++ llvm/lib/TextAPI/ELF/TBEHandler.cpp
@@ -134,6 +134,7 @@
 IO.mapRequired("TbeVersion", Stub.TbeVersion);
 IO.mapOptional("SoName", Stub.SoName);
 IO.mapRequired("Arch", (ELFArchMapper &)Stub.Arch);
+IO.mapOptional("Endian", Stub.Endian);
 IO.mapOptional("NeededLibs", Stub.NeededLibs);
 IO.mapRequired("Symbols", Stub.Symbols);
   }
Index: llvm/include/llvm/TextAPI/ELF/ELFStub.h
===
--- llvm/include/llvm/TextAPI/ELF/ELFStub.h
+++ llvm/include/llvm/TextAPI/ELF/ELFStub.h
@@ -55,6 +55,7 @@
   VersionTuple TbeVersion;
   Optional SoName;
   ELFArch Arch;
+  Optional Endian;
   std::vector NeededLibs;
   std::set Symbols;
 
Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,57 @@
+// Using %clang instead of %clang_cc1 because of -fvisibility
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: _Z4fbarff
+// CHECK: _Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: _Z3fooii
+// CHECK-NOT:_Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,8 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIfsoObjYamlExpV1: return llvm::make_unique();
+  case GenerateIfsoTbeExpV1:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +161,264 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : publ

[PATCH] D61559: Fix the crash when formatting unsupported encodings

2019-05-04 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: klimek, djasper, sammccall, MyDeveloperDay, krasimir.
owenpan added a project: clang.
Herald added a subscriber: cfe-commits.

See PR33946 .


Repository:
  rC Clang

https://reviews.llvm.org/D61559

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,35 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -257,6 +257,35 @@
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56571: [RFC prototype] Implementation of asm-goto support in clang

2019-05-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Also: https://reviews.llvm.org/D61560


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

https://reviews.llvm.org/D56571



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


[PATCH] D60552: [X86] Enable intrinsics of AVX512_BF16, which are supported for BFLOAT16 in Cooper Lake

2019-05-04 Thread Tianle Liu via Phabricator via cfe-commits
liutianle updated this revision to Diff 198168.

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

https://reviews.llvm.org/D60552

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/avx512bf16intrin.h
  lib/Headers/avx512vlbf16intrin.h
  lib/Headers/cpuid.h
  lib/Headers/immintrin.h
  test/CodeGen/attr-target-x86.c
  test/CodeGen/avx512bf16-builtins.c
  test/CodeGen/avx512vlbf16-builtins.c
  test/Driver/x86-target-features.c
  test/Preprocessor/x86_target_features.c

Index: test/Preprocessor/x86_target_features.c
===
--- test/Preprocessor/x86_target_features.c
+++ test/Preprocessor/x86_target_features.c
@@ -443,3 +443,18 @@
 // RUN: %clang -target i386-unknown-unknown -march=atom -mrdpid -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDPID %s
 
 // RDPID: #define __RDPID__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -mavx512bf16 -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=AVX512BF16 %s
+
+// AVX512BF16: #define __AVX512BF16__ 1
+// AVX512BF16: #define __AVX512BW__ 1
+// AVX512BF16: #define __AVX512VL__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -mavx512bf16 -mno-avx512bw -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=AVX512BF16_NOAVX512BW %s
+
+// AVX512BF16_NOAVX512BW-NOT: #define __AVX512BF16__ 1
+
+// RUN: %clang -target i386-unknown-unknown -march=atom -mavx512bf16 -mno-avx512vl -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=AVX512BF16_NOAVX512VL %s
+
+// AVX512BF16_NOAVX512VL-NOT: #define __AVX512BF16__ 1
+
Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -178,3 +178,8 @@
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-invpcid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-INVPCID %s
 // INVPCID: "-target-feature" "+invpcid"
 // NO-INVPCID: "-target-feature" "-invpcid"
+
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mavx512bf16 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=AVX512BF16 %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-avx512bf16 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-AVX512BF16 %s
+// AVX512BF16: "-target-feature" "+avx512bf16"
+// NO-AVX512BF16: "-target-feature" "-avx512bf16"
Index: test/CodeGen/avx512vlbf16-builtins.c
===
--- /dev/null
+++ test/CodeGen/avx512vlbf16-builtins.c
@@ -0,0 +1,163 @@
+//  RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin \
+//  RUN:-target-feature +avx512bf16 -target-feature \
+//  RUN:+avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+
+#include 
+
+__m128bh test_mm_cvtne2ps2bf16(__m128 A, __m128 B) {
+  // CHECK-LABEL: @test_mm_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.128
+  // CHECK: ret <8 x i16> %{{.*}}
+  return _mm_cvtne2ps_pbh(A, B);
+}
+
+__m128bh test_mm_maskz_cvtne2ps2bf16(__m128 A, __m128 B, __mmask8 U) {
+  // CHECK-LABEL: @test_mm_maskz_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.128
+  // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
+  // CHECK: ret <8 x i16> %{{.*}}
+  return _mm_maskz_cvtne2ps_pbh(U, A, B);
+}
+
+__m128bh test_mm_mask_cvtne2ps2bf16(__m128bh C, __mmask8 U, __m128 A, __m128 B) {
+  // CHECK-LABEL: @test_mm_mask_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.128
+  // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
+  // CHECK: ret <8 x i16> %{{.*}}
+  return _mm_mask_cvtne2ps_pbh(C, U, A, B);
+}
+
+__m256bh test_mm256_cvtne2ps2bf16(__m256 A, __m256 B) {
+  // CHECK-LABEL: @test_mm256_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.256
+  // CHECK: ret <16 x i16> %{{.*}}
+  return _mm256_cvtne2ps_pbh(A, B);
+}
+
+__m256bh test_mm256_maskz_cvtne2ps2bf16(__m256 A, __m256 B, __mmask16 U) {
+  // CHECK-LABEL: @test_mm256_maskz_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.256
+  // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
+  // CHECK: ret <16 x i16> %{{.*}}
+  return _mm256_maskz_cvtne2ps_pbh(U, A, B);
+}
+
+__m256bh test_mm256_mask_cvtne2ps2bf16(__m256bh C, __mmask16 U, __m256 A, __m256 B) {
+  // CHECK-LABEL: @test_mm256_mask_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2bf16.256
+  // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
+  // CHECK: ret <16 x i16> %{{.*}}
+  return _mm256_mask_cvtne2ps_pbh(C, U, A, B);
+}
+
+__m512bh test_mm512_cvtne2ps2bf16(__m512 A, __m512 B) {
+  // CHECK-LABEL: @test_mm512_cvtne2ps2bf16
+  // CHECK: @llvm.x86.avx512bf16.cvtne2ps2b