[PATCH] D33365: [clang-tidy] misc-assertion-count: A New Check

2017-08-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D33365#802884, @lebedev.ri wrote:

> In https://reviews.llvm.org/D33365#775916, @alexfh wrote:
>
> > I think, this kind of a check needs some prior research (not necessarily in 
> > the sense of a printed paper, but at least a thoughtful analysis of the 
> > relevant metrics on real code bases)  to back up the specific way the 
> > sufficiency of asserts is determined.
>
>
> While might be slightly unrelated(?), there is obviously a Cyclomatic 
> Complexity, and a Cognitive Complexity, from SonarQube 
> .
>  The latter one **might** actually be interesting to have in 
> `readability-function-size` or a separate check... Not sure if there are 
> restrictions on the algorithm though.


I'll work on implementing that CognitiveComplexity as a new check 
(`readability-function-cognitive-complexity`, probably), and then we'll see if 
it will help here or not.


Repository:
  rL LLVM

https://reviews.llvm.org/D33365



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


[PATCH] D33676: Place implictly declared functions at block scope

2017-08-01 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

Ping.


https://reviews.llvm.org/D33676



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


[PATCH] D36131: clang-format: [JS] handle object types in extends positions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

clang-format would previously drop the whitespace after `extends` in code such 
as:

  class Foo extends {} {}

Where the first set of curly braces is an inline object literal type.


https://reviews.llvm.org/D36131

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
@@ -1989,7 +2000,7 @@
   // and thus rule out the record production in case there is no template
   // (this would still leave us with an ambiguity between template function
   // and class declarations).
-  if (FormatTok->isOneOf(tok::colon, tok::less)) {
+  if (FormatTok->isOneOf(tok::colon, tok::less, Keywords.kw_extends)) {
 while (!eof()) {
   if (FormatTok->is(tok::l_brace)) {
 calculateBraceTypes(/*ExpectClassBody=*/true);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2341,7 +2341,8 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
@@ -1989,7 +2000,7 @@
   // and thus rule out the record production in case there is no template
   // (this would still 

[PATCH] D36132: clang-format: [JS] support default imports.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

Formerly, `import {default as X} from y;` would not be recognized as an import.


https://reviews.llvm.org/D36132

Files:
  lib/Format/SortJavaScriptImports.cpp
  unittests/Format/SortImportsTestJS.cpp


Index: unittests/Format/SortImportsTestJS.cpp
===
--- unittests/Format/SortImportsTestJS.cpp
+++ unittests/Format/SortImportsTestJS.cpp
@@ -300,6 +300,14 @@
  "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+ "import {default as B} from 'b';\n",
+ "import {default as B} from 'b';\n"
+ "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/SortJavaScriptImports.cpp
===
--- lib/Format/SortJavaScriptImports.cpp
+++ lib/Format/SortJavaScriptImports.cpp
@@ -413,7 +413,7 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (Current->isNot(tok::identifier))
+  if (Current->isNot(tok::identifier) && Current->isNot(tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (Current->isNot(tok::identifier))
+if (Current->isNot(tok::identifier) && Current->isNot(tok::kw_default))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();


Index: unittests/Format/SortImportsTestJS.cpp
===
--- unittests/Format/SortImportsTestJS.cpp
+++ unittests/Format/SortImportsTestJS.cpp
@@ -300,6 +300,14 @@
  "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+ "import {default as B} from 'b';\n",
+ "import {default as B} from 'b';\n"
+ "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/SortJavaScriptImports.cpp
===
--- lib/Format/SortJavaScriptImports.cpp
+++ lib/Format/SortJavaScriptImports.cpp
@@ -413,7 +413,7 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (Current->isNot(tok::identifier))
+  if (Current->isNot(tok::identifier) && Current->isNot(tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (Current->isNot(tok::identifier))
+if (Current->isNot(tok::identifier) && Current->isNot(tok::kw_default))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

The new implementation allows code completion that never waits for AST.


https://reviews.llvm.org/D36133

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/GlobalCompilationDatabase.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Regex.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -130,10 +131,16 @@
 namespace clangd {
 namespace {
 
+// Don't wait for async ops in clangd test more than that to avoid blocking
+// indefinitely in case of bugs.
+static const std::chrono::seconds DefaultFutureTimeout =
+std::chrono::seconds(10);
+
 class ErrorCheckingDiagConsumer : public DiagnosticsConsumer {
 public:
-  void onDiagnosticsReady(PathRef File,
-  Tagged> Diagnostics) override {
+  void
+  onDiagnosticsReady(PathRef File,
+ Tagged> Diagnostics) override {
 bool HadError = false;
 for (const auto &DiagAndFixIts : Diagnostics.Value) {
   // FIXME: severities returned by clangd should have a descriptive
@@ -152,9 +159,7 @@
 return HadErrorInLastDiags;
   }
 
-  VFSTag lastVFSTag() {
-return LastVFSTag;
-  }
+  VFSTag lastVFSTag() { return LastVFSTag; }
 
 private:
   std::mutex Mutex;
@@ -276,9 +281,15 @@
 auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
 
 FS.ExpectedFile = SourceFilename;
-Server.addDocument(SourceFilename, SourceContents);
+
+// Have to sync reparses because RunSynchronously is false.
+auto AddDocFuture = Server.addDocument(SourceFilename, SourceContents);
 
 auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
+
+// Wait for reparse to finish before checking for errors.
+EXPECT_EQ(AddDocFuture.wait_for(DefaultFutureTimeout),
+  std::future_status::ready);
 EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
 return Result;
   }
@@ -338,16 +349,25 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, "");
+  ParseFuture = Server.addDocument(FooCpp, "");
   auto DumpParseEmpty = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, SourceContents);
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -374,18 +394,27 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParseDifferent = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "int a;";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  EXPECT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -404,10 +433,12 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
+  // No need to sync reparses, because RunSynchronously is set
+  // to true.
   FS.Tag = "123";
   Server.addDocument(FooCpp, SourceContents);
-  EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS.Tag);
+  EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
 
   FS.Tag 

[PATCH] D35012: [refactor] Add the AST source selection component

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D35012



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


[clang-tools-extra] r309668 - [clang-tidy] Handle anonymous structs/unions in member init checks.

2017-08-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Aug  1 02:54:05 2017
New Revision: 309668

URL: http://llvm.org/viewvc/llvm-project?rev=309668&view=rev
Log:
[clang-tidy] Handle anonymous structs/unions in member init checks.

Use getAnyMember() instead of getMember() to avoid crash on anonymous
structs/unions.
Don't warn about initializing members of an anonymous union.

Fixes PR32966.

Reviewed by alexfh.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Tue Aug  1 02:54:05 2017
@@ -166,21 +166,22 @@ void UseDefaultMemberInitCheck::register
   cxxConstructorDecl(
   isDefaultConstructor(), unless(isInstantiated()),
   forEachConstructorInitializer(
-  allOf(forField(unless(anyOf(isBitField(),
-  hasInClassInitializer(anything(),
-cxxCtorInitializer(isWritten(),
-   withInitializer(ignoringImplicit(Init)))
-.bind("default",
+  cxxCtorInitializer(
+  forField(unless(anyOf(isBitField(),
+hasInClassInitializer(anything()),
+hasParent(recordDecl(isUnion()),
+  isWritten(), withInitializer(ignoringImplicit(Init)))
+  .bind("default"))),
   this);
 
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(ast_matchers::isTemplateInstantiation()),
   forEachConstructorInitializer(
-  allOf(forField(hasInClassInitializer(anything())),
-cxxCtorInitializer(isWritten(),
-   withInitializer(ignoringImplicit(Init)))
-.bind("existing",
+  cxxCtorInitializer(forField(hasInClassInitializer(anything())),
+ isWritten(),
+ withInitializer(ignoringImplicit(Init)))
+  .bind("existing"))),
   this);
 }
 
@@ -197,7 +198,7 @@ void UseDefaultMemberInitCheck::check(co
 
 void UseDefaultMemberInitCheck::checkDefaultInit(
 const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
-  const FieldDecl *Field = Init->getMember();
+  const FieldDecl *Field = Init->getAnyMember();
 
   SourceLocation StartLoc = Field->getLocStart();
   if (StartLoc.isMacroID() && IgnoreMacros)

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantMemberInitCheck.cpp 
Tue Aug  1 02:54:05 2017
@@ -39,7 +39,8 @@ void RedundantMemberInitCheck::registerM
   forEachConstructorInitializer(
   cxxCtorInitializer(isWritten(),
  withInitializer(ignoringImplicit(Construct)),
- unless(forField(hasType(isConstQualified()
+ unless(forField(hasType(isConstQualified(,
+ 
unless(forField(hasParent(recordDecl(isUnion())
   .bind("init"))),
   this);
 }
@@ -52,7 +53,7 @@ void RedundantMemberInitCheck::check(con
   Construct->getArg(0)->isDefaultArgument()) {
 if (Init->isAnyMemberInitializer()) {
   diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getMember()
+  << Init->getAnyMember()
   << FixItHint::CreateRemoval(Init->getSourceRange());
 } else {
   diag(Init->getSourceLocation(),

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=309668&r1=309667&r2=309668&view=diff
==
--- 
clang-too

r309667 - [ASTMatchers] Allow forField to match indirect fields.

2017-08-01 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Tue Aug  1 02:53:55 2017
New Revision: 309667

URL: http://llvm.org/viewvc/llvm-project?rev=309667&view=rev
Log:
[ASTMatchers] Allow forField to match indirect fields.

This is needed for PR32966.

Reviewed by alexfh.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=309667&r1=309666&r2=309667&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug  1 02:53:55 2017
@@ -3237,7 +3237,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAny
 /// with forField matching foo_
 AST_MATCHER_P(CXXCtorInitializer, forField,
   internal::Matcher, InnerMatcher) {
-  const FieldDecl *NodeAsDecl = Node.getMember();
+  const FieldDecl *NodeAsDecl = Node.getAnyMember();
   return (NodeAsDecl != nullptr &&
   InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
 }

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=309667&r1=309666&r2=309667&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Tue Aug  1 
02:53:55 2017
@@ -785,14 +785,18 @@ TEST(HasAnyConstructorInitializer, ForFi
   static const char Code[] =
 "class Baz { };"
   "class Foo {"
-  "  Foo() : foo_() { }"
+  "  Foo() : foo_(), bar_() { }"
   "  Baz foo_;"
-  "  Baz bar_;"
+  "  struct {"
+  "Baz bar_;"
+  "  };"
   "};";
   EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasType(recordDecl(hasName("Baz";
   EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasName("foo_"));
+  EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
+forField(hasName("bar_"));
   EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
 forField(hasType(recordDecl(hasName("Bar";
 }


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


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I also want to rename ClangdUnit and ClangdUnitStore accordingly, but will do 
that in a separate commit so that git-svn correctly detects the renames (i.e. 
don't want file contents changes).


https://reviews.llvm.org/D36133



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


[PATCH] D35012: [refactor] Add the AST source selection component

2017-08-01 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Apart from nits, looks OK to me - Eric, are all your concerns addressed?




Comment at: include/clang/Tooling/Refactoring/ASTSelection.h:51-53
+  ast_type_traits::DynTypedNode Node;
+  SourceSelectionKind SelectionKind;
+  std::vector Children;

As this is a public interface, perhaps we should make them const?


Repository:
  rL LLVM

https://reviews.llvm.org/D35012



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


[PATCH] D35012: [refactor] Add the AST source selection component

2017-08-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Yep. Lgtm!


Repository:
  rL LLVM

https://reviews.llvm.org/D35012



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


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clangd/ClangdServer.h:113
+  /// queue. The request will be run on a separate thread.
+  template  void addToFront(Func &&F, Args &&... 
As);
+  /// Add a new request to run function \p F with args \p As to the end of the

Why the template? This is awkward now because it can only be called from 
ClangdServer.cpp



Comment at: clangd/ClangdUnit.cpp:887-889
+tooling::CompileCommand const &CppFile::getCompileCommand() const {
+  return Command;
+}

Move implementation into header



Comment at: clangd/ClangdUnit.cpp:910
+  return WasCancelledBeforeConstruction;
+}
+

Move implementation into header.



Comment at: clangd/ClangdUnit.h:104
 
-~ParsedAST();
+// Providse thread-safe access to ParsedAST.
+class ParsedASTWrapper {

Typo: Providse



Comment at: clangd/ClangdUnitStore.cpp:22
 return;
   OpenedFiles.erase(It);
 }

Not introduced in this commit, but this is equivalent to 
OpenedFiles.erase(File) without the find and check.


https://reviews.llvm.org/D36133



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


r309672 - [x86][inline-asm]Allow a pack of Control Debug to be properly picked

2017-08-01 Thread Coby Tayree via cfe-commits
Author: coby
Date: Tue Aug  1 03:51:09 2017
New Revision: 309672

URL: http://llvm.org/viewvc/llvm-project?rev=309672&view=rev
Log:
[x86][inline-asm]Allow a pack of Control Debug to be properly picked

Allows the incorporation of legit (x86) Debug Regs within inline asm stataements

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

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp
cfe/trunk/test/CodeGen/ms-inline-asm.c

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=309672&r1=309671&r2=309672&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Tue Aug  1 03:51:09 2017
@@ -59,6 +59,7 @@ static const char *const GCCRegNames[] =
 "zmm26", "zmm27", "zmm28", "zmm29", "zmm30",   "zmm31", "k0","k1",
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
+"dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {

Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=309672&r1=309671&r2=309672&view=diff
==
--- cfe/trunk/test/CodeGen/ms-inline-asm.c (original)
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c Tue Aug  1 03:51:09 2017
@@ -638,6 +638,19 @@ void t44() {
   // CHECK: call void asm sideeffect inteldialect "mov cr0, eax\0A\09mov cr2, 
ebx\0A\09mov cr3, ecx\0A\09mov cr4, edx", 
"~{cr0},~{cr2},~{cr3},~{cr4},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t45() {
+  // CHECK-LABEL: define void @t45
+  __asm {
+mov dr0, eax
+mov dr1, ebx
+mov dr2, ebx
+mov dr3, ecx
+mov dr6, edx
+mov dr7, ecx
+  }
+  // CHECK: call void asm sideeffect inteldialect "mov dr0, eax\0A\09mov dr1, 
ebx\0A\09mov dr2, ebx\0A\09mov dr3, ecx\0A\09mov dr6, edx\0A\09mov dr7, ecx", 
"~{dr0},~{dr1},~{dr2},~{dr3},~{dr6},~{dr7},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
 // CHECK-LABEL: define void @dot_operator
__asm { mov eax, 3[ebx]A.b}


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


[PATCH] D36074: [x86][inline-asm]Allow a pack of Control Debug to be properly picked

2017-08-01 Thread coby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309672: [x86][inline-asm]Allow a pack of Control Debug to be 
properly picked (authored by coby).

Changed prior to commit:
  https://reviews.llvm.org/D36074?vs=108872&id=109073#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36074

Files:
  cfe/trunk/lib/Basic/Targets/X86.cpp
  cfe/trunk/test/CodeGen/ms-inline-asm.c


Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -638,6 +638,19 @@
   // CHECK: call void asm sideeffect inteldialect "mov cr0, eax\0A\09mov cr2, 
ebx\0A\09mov cr3, ecx\0A\09mov cr4, edx", 
"~{cr0},~{cr2},~{cr3},~{cr4},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t45() {
+  // CHECK-LABEL: define void @t45
+  __asm {
+mov dr0, eax
+mov dr1, ebx
+mov dr2, ebx
+mov dr3, ecx
+mov dr6, edx
+mov dr7, ecx
+  }
+  // CHECK: call void asm sideeffect inteldialect "mov dr0, eax\0A\09mov dr1, 
ebx\0A\09mov dr2, ebx\0A\09mov dr3, ecx\0A\09mov dr6, edx\0A\09mov dr7, ecx", 
"~{dr0},~{dr1},~{dr2},~{dr3},~{dr6},~{dr7},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
 // CHECK-LABEL: define void @dot_operator
__asm { mov eax, 3[ebx]A.b}
Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -59,6 +59,7 @@
 "zmm26", "zmm27", "zmm28", "zmm29", "zmm30",   "zmm31", "k0","k1",
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
+"dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {


Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -638,6 +638,19 @@
   // CHECK: call void asm sideeffect inteldialect "mov cr0, eax\0A\09mov cr2, ebx\0A\09mov cr3, ecx\0A\09mov cr4, edx", "~{cr0},~{cr2},~{cr3},~{cr4},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t45() {
+  // CHECK-LABEL: define void @t45
+  __asm {
+mov dr0, eax
+mov dr1, ebx
+mov dr2, ebx
+mov dr3, ecx
+mov dr6, edx
+mov dr7, ecx
+  }
+  // CHECK: call void asm sideeffect inteldialect "mov dr0, eax\0A\09mov dr1, ebx\0A\09mov dr2, ebx\0A\09mov dr3, ecx\0A\09mov dr6, edx\0A\09mov dr7, ecx", "~{dr0},~{dr1},~{dr2},~{dr3},~{dr6},~{dr7},~{dirflag},~{fpsr},~{flags}"()
+}
+
 void dot_operator(){
 // CHECK-LABEL: define void @dot_operator
 	__asm { mov eax, 3[ebx]A.b}
Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -59,6 +59,7 @@
 "zmm26", "zmm27", "zmm28", "zmm29", "zmm30",   "zmm31", "k0","k1",
 "k2","k3","k4","k5","k6",  "k7",
 "cr0",   "cr2",   "cr3",   "cr4",   "cr8",
+"dr0",   "dr1",   "dr2",   "dr3",   "dr6", "dr7",
 };
 
 const TargetInfo::AddlRegName AddlRegNames[] = {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36131: clang-format: [JS] handle object types in extends positions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 109078.
mprobst added a comment.

- revert bogus change


https://reviews.llvm.org/D36131

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2341,7 +2341,8 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2341,7 +2341,8 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
__

[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-08-01 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I had a long discussion with James about this on IRC without reaching a clear 
consensus. I consider forcing this behavior on all targets to be a major bug. 
It should be opt-in and opt-in only:

(1) The header name is not mandated by any standard. It is not in any namespace 
generally accepted as implementation-owned.
(2) It adds magic behavior that can make debugging more difficult. Partially 
preprocessed sources for example could be compiled with plain -c before, now 
they need a different command line.
(3) It seems to me that the GNU userland (and maybe Windows) is the exception 
to a well integrated tool chain. Most other platforms have a single canonical 
libc, libm and libpthread implementation and can as such directly define all 
the relevant macros directly in the driver. Given that many of the macros 
involved are already reflected by the compiler behavior anyway, they can't be 
decoupled. I.e. the questionable concept of locale-independent wchar_t is 
already hard-coded in the front end as soon as any long character literals are 
used.

As such, please move the command line additions back into the target-specific 
files for targets that actually want to get this behavior.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D36131: clang-format: [JS] handle object types in extends positions.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D36131



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


[PATCH] D36132: clang-format: [JS] support default imports.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/SortJavaScriptImports.cpp:416
 break;
-  if (Current->isNot(tok::identifier))
+  if (Current->isNot(tok::identifier) && Current->isNot(tok::kw_default))
 return false;

Change to

  !Current->isOneOf(tok::identifier, tok::kw_default)

Same below.


https://reviews.llvm.org/D36132



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


[PATCH] D36139: clang-format: [JS] prefer wrapping chains over empty literals.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

E.g. don't wrap like this:

  (foo.bar.baz).and.bam(Blah.of({
  }))

But rather:

  (foo.bar.baz)
  .and.bam(Blah.of({}))


https://reviews.llvm.org/D36139

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -832,6 +832,15 @@
 
 }
 
+TEST_F(FormatTestJS, DontWrapEmptyLiterals) {
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of([]));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of({}));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of(()));");
+}
+
 TEST_F(FormatTestJS, InliningFunctionLiterals) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2005,6 +2005,11 @@
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return 100;
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if ((Left.is(tok::l_brace) && Right.is(tok::r_brace)) ||
+(Left.is(tok::l_square) && Right.is(tok::r_square)) ||
+(Left.is(tok::l_paren) && Right.is(tok::r_paren)))
+  return 200;
   }
 
   if (Right.is(tok::identifier) && Right.Next && 
Right.Next->is(TT_DictLiteral))


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -832,6 +832,15 @@
 
 }
 
+TEST_F(FormatTestJS, DontWrapEmptyLiterals) {
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of([]));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of({}));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of(()));");
+}
+
 TEST_F(FormatTestJS, InliningFunctionLiterals) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2005,6 +2005,11 @@
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return 100;
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if ((Left.is(tok::l_brace) && Right.is(tok::r_brace)) ||
+(Left.is(tok::l_square) && Right.is(tok::r_square)) ||
+(Left.is(tok::l_paren) && Right.is(tok::r_paren)))
+  return 200;
   }
 
   if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36141: [StaticAnalyzer] Fix FP in UnreachableCodeChecker

2017-08-01 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki created this revision.
Herald added a subscriber: whisperity.

This fixes a FP. Without the fix, the checker says that "static int x;" is 
unreachable.


Repository:
  rL LLVM

https://reviews.llvm.org/D36141

Files:
  lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
  test/Analysis/unreachable-code-path.c


Index: test/Analysis/unreachable-code-path.c
===
--- test/Analysis/unreachable-code-path.c
+++ test/Analysis/unreachable-code-path.c
@@ -213,3 +213,13 @@
   RETURN(1); // no-warning
 }
 
+// Avoid FP when macro argument is known
+void writeSomething(int *x);
+#define MACRO(C)\
+  if (!C) { \
+static int x;   \
+writeSomething(&x); \
+  }
+void macro2(void) {
+  MACRO(1);
+}
Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -112,7 +112,7 @@
   continue;
 
 // Check for false positives
-if (CB->size() > 0 && isInvalidPath(CB, *PM))
+if (isInvalidPath(CB, *PM))
   continue;
 
 // It is good practice to always have a "default" label in a "switch", even


Index: test/Analysis/unreachable-code-path.c
===
--- test/Analysis/unreachable-code-path.c
+++ test/Analysis/unreachable-code-path.c
@@ -213,3 +213,13 @@
   RETURN(1); // no-warning
 }
 
+// Avoid FP when macro argument is known
+void writeSomething(int *x);
+#define MACRO(C)\
+  if (!C) { \
+static int x;   \
+writeSomething(&x); \
+  }
+void macro2(void) {
+  MACRO(1);
+}
Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -112,7 +112,7 @@
   continue;
 
 // Check for false positives
-if (CB->size() > 0 && isInvalidPath(CB, *PM))
+if (isInvalidPath(CB, *PM))
   continue;
 
 // It is good practice to always have a "default" label in a "switch", even
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

In JavaScript, may keywords can be used in method names and thus call sites:

  foo.delete();
  foo.instanceof();

clang-format would previously insert whitespace after the `instanceof`. This
change generically skips inserting whitespace between a keyword and a
parenthesis if preceded by a dot, i.e. in a callsite.


https://reviews.llvm.org/D36142

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -232,6 +232,7 @@
   verifyFormat("x.var() = 1;");
   verifyFormat("x.for() = 1;");
   verifyFormat("x.as() = 1;");
+  verifyFormat("x.instanceof() = 1;");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,11 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+// Valid JS method names can include keywords, e.g. `foo.delete()` or
+// `bar.instanceof()`.
+if (Right.is(tok::l_paren) && Left.Tok.getIdentifierInfo() &&
+Left.Previous && Left.Previous->is(tok::period))
+  return false;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -232,6 +232,7 @@
   verifyFormat("x.var() = 1;");
   verifyFormat("x.for() = 1;");
   verifyFormat("x.as() = 1;");
+  verifyFormat("x.instanceof() = 1;");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,11 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+// Valid JS method names can include keywords, e.g. `foo.delete()` or
+// `bar.instanceof()`.
+if (Right.is(tok::l_paren) && Left.Tok.getIdentifierInfo() &&
+Left.Previous && Left.Previous->is(tok::period))
+  return false;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-08-01 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic updated this revision to Diff 109088.

https://reviews.llvm.org/D34878

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/ARM.cpp
  lib/Driver/ToolChains/Arch/ARM.h
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/clang-translation.c

Index: test/Driver/clang-translation.c
===
--- test/Driver/clang-translation.c
+++ test/Driver/clang-translation.c
@@ -75,6 +75,12 @@
 // ARMV5E: "-cc1"
 // ARMV5E: "-target-cpu" "arm1022e"
 
+// RUN: %clang -target arm-linux -mtp=cp15 -### -S %s -arch armv7 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER %s
+// ARMv7_THREAD_POINTER: "-target-feature" "+read-tp-hard"
+// ARMv7_THREAD_POINTER: "-mtp" "cp15"
+// ARMv7_THREAD_POINTER-NOT: "mtp" "soft"
+
 // RUN: %clang -target powerpc64-unknown-linux-gnu \
 // RUN: -### -S %s -mcpu=G5 2>&1 | FileCheck -check-prefix=PPCG5 %s
 // PPCG5: clang
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1345,6 +1345,17 @@
 CmdArgs.push_back("hard");
   }
 
+  arm::ReadTPMode ThreadPointer = arm::getReadTPMode(getToolChain(), Args);
+  if (ThreadPointer == arm::ReadTPMode::Cp15) {
+CmdArgs.push_back("-mtp");
+CmdArgs.push_back("cp15");
+  } else {
+assert(ThreadPointer == arm::ReadTPMode::Soft &&
+   "Invalid mode for reading thread pointer");
+CmdArgs.push_back("-mtp");
+CmdArgs.push_back("soft");
+  }
+
   // Forward the -mglobal-merge option for explicit control over the pass.
   if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
options::OPT_mno_global_merge)) {
Index: lib/Driver/ToolChains/Arch/ARM.h
===
--- lib/Driver/ToolChains/Arch/ARM.h
+++ lib/Driver/ToolChains/Arch/ARM.h
@@ -32,14 +32,21 @@
 void appendEBLinkFlags(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
const llvm::Triple &Triple);
+enum class ReadTPMode {
+  Invalid,
+  Soft,
+  Cp15,
+};
+
 enum class FloatABI {
   Invalid,
   Soft,
   SoftFP,
   Hard,
 };
 
 FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args);
+ReadTPMode getReadTPMode(const ToolChain &TC, const llvm::opt::ArgList &Args);
 
 bool useAAPCSForMachO(const llvm::Triple &T);
 void getARMArchCPUFromArgs(const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -122,6 +122,27 @@
  T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
 }
 
+// Select mode for reading thread pointer (-mtp=soft/cp15).
+arm::ReadTPMode arm::getReadTPMode(const ToolChain &TC, const ArgList &Args) {
+  const Driver &D = TC.getDriver();
+  arm::ReadTPMode ThreadPointer = ReadTPMode::Invalid;
+  if (Arg *A =
+  Args.getLastArg(options::OPT_mtp_mode_EQ)) {
+ThreadPointer = llvm::StringSwitch(A->getValue())
+.Case("cp15", ReadTPMode::Cp15)
+.Case("soft", ReadTPMode::Soft)
+.Default(ReadTPMode::Invalid);
+if (ThreadPointer == ReadTPMode::Invalid &&
+!StringRef(A->getValue()).empty()) {
+  D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
+  ThreadPointer = ReadTPMode::Soft;
+}
+  }
+  if (ThreadPointer == ReadTPMode::Invalid)
+ThreadPointer = ReadTPMode::Soft;
+  return ThreadPointer;
+}
+
 // Select the float ABI as determined by -msoft-float, -mhard-float, and
 // -mfloat-abi=.
 arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
@@ -253,6 +274,7 @@
   bool KernelOrKext =
   Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
   arm::FloatABI ABI = arm::getARMFloatABI(TC, Args);
+  arm::ReadTPMode ThreadPointer = arm::getReadTPMode(TC, Args);
   const Arg *WaCPU = nullptr, *WaFPU = nullptr;
   const Arg *WaHDiv = nullptr, *WaArch = nullptr;
 
@@ -294,6 +316,10 @@
 }
   }
 
+
+  if (ThreadPointer == arm::ReadTPMode::Cp15)
+Features.push_back("+read-tp-hard");
+
   // Check -march. ClangAs gives preference to -Wa,-march=.
   const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
   StringRef ArchName;
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1661,6 +1661,8 @@
   HelpText<"Disallow generation of data access to code sections (ARM only)">;
 def mno_execute_only : Flag<["-"], "mno-execute-only">, Group,
   HelpText<"Allow generation of data access to code sections (ARM only)">;
+def mtp_mode_EQ : Joined<["-"], "mtp=">, 

[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 109089.
mprobst added a comment.

- support switch, case, delete.


https://reviews.llvm.org/D36142

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -232,6 +232,9 @@
   verifyFormat("x.var() = 1;");
   verifyFormat("x.for() = 1;");
   verifyFormat("x.as() = 1;");
+  verifyFormat("x.instanceof() = 1;");
+  verifyFormat("x.switch() = 1;");
+  verifyFormat("x.case() = 1;");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,13 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+// Valid JS method names can include keywords, e.g. `foo.delete()` or
+// `bar.instanceof()`.
+if (Right.is(tok::l_paren) && Left.Previous &&
+Left.Previous->is(tok::period) &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete)))
+  return false;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -232,6 +232,9 @@
   verifyFormat("x.var() = 1;");
   verifyFormat("x.for() = 1;");
   verifyFormat("x.as() = 1;");
+  verifyFormat("x.instanceof() = 1;");
+  verifyFormat("x.switch() = 1;");
+  verifyFormat("x.case() = 1;");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,13 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+// Valid JS method names can include keywords, e.g. `foo.delete()` or
+// `bar.instanceof()`.
+if (Right.is(tok::l_paren) && Left.Previous &&
+Left.Previous->is(tok::period) &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete)))
+  return false;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-08-01 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added a comment.

Comments addressed.


https://reviews.llvm.org/D34878



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


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 109091.
ilya-biryukov added a comment.

- Fixed a bug that caused CppFiles to be deleted while used.


https://reviews.llvm.org/D36133

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/GlobalCompilationDatabase.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Regex.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -130,10 +131,16 @@
 namespace clangd {
 namespace {
 
+// Don't wait for async ops in clangd test more than that to avoid blocking
+// indefinitely in case of bugs.
+static const std::chrono::seconds DefaultFutureTimeout =
+std::chrono::seconds(10);
+
 class ErrorCheckingDiagConsumer : public DiagnosticsConsumer {
 public:
-  void onDiagnosticsReady(PathRef File,
-  Tagged> Diagnostics) override {
+  void
+  onDiagnosticsReady(PathRef File,
+ Tagged> Diagnostics) override {
 bool HadError = false;
 for (const auto &DiagAndFixIts : Diagnostics.Value) {
   // FIXME: severities returned by clangd should have a descriptive
@@ -152,9 +159,7 @@
 return HadErrorInLastDiags;
   }
 
-  VFSTag lastVFSTag() {
-return LastVFSTag;
-  }
+  VFSTag lastVFSTag() { return LastVFSTag; }
 
 private:
   std::mutex Mutex;
@@ -276,9 +281,15 @@
 auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
 
 FS.ExpectedFile = SourceFilename;
-Server.addDocument(SourceFilename, SourceContents);
+
+// Have to sync reparses because RunSynchronously is false.
+auto AddDocFuture = Server.addDocument(SourceFilename, SourceContents);
 
 auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
+
+// Wait for reparse to finish before checking for errors.
+EXPECT_EQ(AddDocFuture.wait_for(DefaultFutureTimeout),
+  std::future_status::ready);
 EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
 return Result;
   }
@@ -338,16 +349,25 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, "");
+  ParseFuture = Server.addDocument(FooCpp, "");
   auto DumpParseEmpty = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, SourceContents);
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -374,18 +394,27 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParseDifferent = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "int a;";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  EXPECT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -404,10 +433,12 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
+  // No need to sync reparses, because RunSynchronously is set
+  // to true.
   FS.Tag = "123";
   Server.addDocument(FooCpp, SourceContents);
-  EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS.Tag);
+  EXPECT_EQ(DiagConsumer.

[PATCH] D36143: [clang-format] Fix indent of 'key <...>' in text protos

2017-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This patch fixes the indentation of the code pattern `key <...>` in text protos.
Previously, such line would be alinged depending on the column of the previous
colon, which usually indents too much.


https://reviews.llvm.org/D36143

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -245,6 +245,10 @@
">\n"
"field: OK,\n"
"field_c >>");
+
+  verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+   "head_id: 1\n"
+   "data ");
 }
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -356,6 +356,12 @@
"  }\n"
"  field_g: OK\n"
">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  app_id: 'com.javax.swing.salsa.latino'\n"
+   "  head_id: 1\n"
+   "  data \n"
+   ">;");
 }
 
 TEST_F(FormatTestProto, FormatsService) {
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -731,7 +731,10 @@
   if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
 return State.Stack[State.Stack.size() - 2].LastSpace;
   if (Current.is(tok::identifier) && Current.Next &&
-  Current.Next->is(TT_DictLiteral))
+  (Current.Next->is(TT_DictLiteral) ||
+   ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Current.Next->is(TT_TemplateOpener
 return State.Stack.back().Indent;
   if (NextNonComment->is(TT_ObjCStringLiteral) &&
   State.StartOfStringLiteral != 0)


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -245,6 +245,10 @@
">\n"
"field: OK,\n"
"field_c >>");
+
+  verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+   "head_id: 1\n"
+   "data ");
 }
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -356,6 +356,12 @@
"  }\n"
"  field_g: OK\n"
">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  app_id: 'com.javax.swing.salsa.latino'\n"
+   "  head_id: 1\n"
+   "  data \n"
+   ">;");
 }
 
 TEST_F(FormatTestProto, FormatsService) {
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -731,7 +731,10 @@
   if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
 return State.Stack[State.Stack.size() - 2].LastSpace;
   if (Current.is(tok::identifier) && Current.Next &&
-  Current.Next->is(TT_DictLiteral))
+  (Current.Next->is(TT_DictLiteral) ||
+   ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Current.Next->is(TT_TemplateOpener
 return State.Stack.back().Indent;
   if (NextNonComment->is(TT_ObjCStringLiteral) &&
   State.StartOfStringLiteral != 0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-08-01 Thread Blower, Melanie via cfe-commits
 
joerg added a comment.

I had a long discussion with James about this on IRC without reaching a clear 
consensus. I consider forcing this behavior on all targets to be a major bug. 
It should be opt-in and opt-in only:

(1) The header name is not mandated by any standard. It is not in any namespace 
generally accepted as implementation-owned.
(2) It adds magic behavior that can make debugging more difficult. Partially 
preprocessed sources for example could be compiled with plain -c before, now 
they need a different command line.
(3) It seems to me that the GNU userland (and maybe Windows) is the exception 
to a well integrated tool chain. Most other platforms have a single canonical 
libc, libm and libpthread implementation and can as such directly define all 
the relevant macros directly in the driver. Given that many of the macros 
involved are already reflected by the compiler behavior anyway, they can't be 
decoupled. I.e. the questionable concept of locale-independent wchar_t is 
already hard-coded in the front end as soon as any long character literals are 
used.

As such, please move the command line additions back into the target-specific 
files for targets that actually want to get this behavior.

>Thank you Joerg.  Initially I had proposed this only for gnu/Linux. I will 
>submit another patch like this.  As far as I know this is the only toolchain 
>with this behavior.  Please clarify if there are other configurations to cover.

Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D36144: clang-format: [JS] consistenly format enums.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

Previously, const enums would get formatted differently because the modifier 
was not recognized.


https://reviews.llvm.org/D36144

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1414,6 +1414,14 @@
"  B\n"
"}\n"
"var x = 1;");
+  verifyFormat("const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
+  verifyFormat("export const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2516,7 +2516,9 @@
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_export, tok::kw_enum)))
+ Line.startsWith(tok::kw_const, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
   // JavaScript top-level enum key/value pairs are put on separate lines
   // instead of bin-packing.
   return true;


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1414,6 +1414,14 @@
"  B\n"
"}\n"
"var x = 1;");
+  verifyFormat("const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
+  verifyFormat("export const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2516,7 +2516,9 @@
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_export, tok::kw_enum)))
+ Line.startsWith(tok::kw_const, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
   // JavaScript top-level enum key/value pairs are put on separate lines
   // instead of bin-packing.
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-08-01 Thread Melanie Blower via Phabricator via cfe-commits
mibintc planned changes to this revision.
mibintc added a comment.

I will prepare another patch responding to joerg's comment:

> Quoted Text

I had a long discussion with James about this on IRC without reaching a clear 
consensus. I consider forcing this behavior on all targets to be a major bug. 
It should be opt-in and opt-in only:

(1) The header name is not mandated by any standard. It is not in any namespace 
generally accepted as implementation-owned.
(2) It adds magic behavior that can make debugging more difficult. Partially 
preprocessed sources for example could be compiled with plain -c before, now 
they need a different command line.
(3) It seems to me that the GNU userland (and maybe Windows) is the exception 
to a well integrated tool chain. Most other platforms have a single canonical 
libc, libm and libpthread implementation and can as such directly define all 
the relevant macros directly in the driver. Given that many of the macros 
involved are already reflected by the compiler behavior anyway, they can't be 
decoupled. I.e. the questionable concept of locale-independent wchar_t is 
already hard-coded in the front end as soon as any long character literals are 
used.

As such, please move the command line additions back into the target-specific 
files for targets that actually want to get this behavior.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D36141: [StaticAnalyzer] Fix FP in UnreachableCodeChecker

2017-08-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added reviewers: NoQ, dcoughlin.
xazax.hun added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rL LLVM

https://reviews.llvm.org/D36141



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


[PATCH] D36146: clang-format: [JS] whitespace between keywords and parenthesized expressions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

`throw (...)` should have a whitespace following it, as do await and void.


https://reviews.llvm.org/D36146

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -259,6 +259,15 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+   "await (await x).y;\n"
+   "void (0);\n"
+   "delete (x.y);\n"
+   "return (x);\n");
+}
+
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,9 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+if (Right.is(tok::l_paren) &&
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+  return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -259,6 +259,15 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+   "await (await x).y;\n"
+   "void (0);\n"
+   "delete (x.y);\n"
+   "return (x);\n");
+}
+
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,9 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+if (Right.is(tok::l_paren) &&
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+  return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309678 - [OpenCL] Add missing subgroup builtins

2017-08-01 Thread Joey Gouly via cfe-commits
Author: joey
Date: Tue Aug  1 06:27:09 2017
New Revision: 309678

URL: http://llvm.org/viewvc/llvm-project?rev=309678&view=rev
Log:
[OpenCL] Add missing subgroup builtins

This adds get_kernel_max_sub_group_size_for_ndrange and
get_kernel_sub_group_count_for_ndrange.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=309678&r1=309677&r2=309678&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Aug  1 06:27:09 2017
@@ -1398,8 +1398,10 @@ LANGBUILTIN(get_pipe_max_packets, "Ui.",
 // OpenCL v2.0 s6.13.17 - Enqueue kernel functions.
 // Custom builtin check allows to perform special check of passed block 
arguments.
 LANGBUILTIN(enqueue_kernel, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_work_group_size, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "i.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCLC20_LANG)
+LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
 
 // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
 LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=309678&r1=309677&r2=309678&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Aug  1 06:27:09 2017
@@ -2704,6 +2704,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 "__get_kernel_preferred_work_group_multiple_impl"),
 Arg));
   }
+  case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
+  case Builtin::BIget_kernel_sub_group_count_for_ndrange: {
+llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy(
+getContext().getTargetAddressSpace(LangAS::opencl_generic));
+LValue NDRangeL = EmitAggExprToLValue(E->getArg(0));
+llvm::Value *NDRange = NDRangeL.getAddress().getPointer();
+Value *Block = EmitScalarExpr(E->getArg(1));
+Block = Builder.CreatePointerCast(Block, GenericVoidPtrTy);
+const char *Name =
+BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange
+? "__get_kernel_max_sub_group_size_for_ndrange_impl"
+: "__get_kernel_sub_group_count_for_ndrange_impl";
+return RValue::get(Builder.CreateCall(
+CGM.CreateRuntimeFunction(
+llvm::FunctionType::get(
+IntTy, {NDRange->getType(), GenericVoidPtrTy}, false),
+Name),
+{NDRange, Block}));
+  }
   case Builtin::BIprintf:
 if (getTarget().getTriple().isNVPTX())
   return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=309678&r1=309677&r2=309678&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Aug  1 06:27:09 2017
@@ -308,6 +308,32 @@ static bool checkOpenCLSubgroupExt(Sema
   return false;
 }
 
+static bool SemaOpenCLBuiltinNDRangeAndBlock(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 2))
+return true;
+
+  if (checkOpenCLSubgroupExt(S, TheCall))
+return true;
+
+  // First argument is an ndrange_t type.
+  Expr *NDRangeArg = TheCall->getArg(0);
+  if (NDRangeArg->getType().getAsString() != "ndrange_t") {
+S.Diag(NDRangeArg->getLocStart(),
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'ndrange_t'";
+return true;
+  }
+
+  Expr *BlockArg = TheCall->getArg(1);
+  if (!isBlockPointer(BlockArg)) {
+S.Diag(BlockArg->getLocStart(),
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "block";
+return true;
+  }
+  return checkOpenCLBlockArgs(S, BlockArg);
+}
+
 /// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
 /// get_kernel_work_group_size
 /// and get_kernel_preferred_work_group_size_multiple builtin functions.
@@ -1109,6 +1135,12 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 if (SemaOpenCLBuiltinKernelWorkGroupSize(*this, TheCall))
   return ExprError();
 break;
+break;
+  case Builtin::BIget_kernel_max_sub_group_size_for

[PATCH] D36147: clang-format: [JS] handle union types in arrow functions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

clang-format would previously fail to detect that an arrow functions parameter 
block is not an expression, and thus insert whitespace around the `|` and `&` 
type operators in it.


https://reviews.llvm.org/D36147

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -988,6 +988,9 @@
".doSomethingElse(\n"
"// break\n"
");");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+   "  return x;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -533,6 +533,7 @@
 Contexts.back().ContextKind == tok::l_square || // array type
 (Contexts.size() == 1 &&
  Line.MustBeDeclaration)) { // method/property declaration
+  Contexts.back().IsExpression = false;
   Tok->Type = TT_JsTypeColon;
   break;
 }


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -988,6 +988,9 @@
".doSomethingElse(\n"
"// break\n"
");");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+   "  return x;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -533,6 +533,7 @@
 Contexts.back().ContextKind == tok::l_square || // array type
 (Contexts.size() == 1 &&
  Line.MustBeDeclaration)) { // method/property declaration
+  Contexts.back().IsExpression = false;
   Tok->Type = TT_JsTypeColon;
   break;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-08-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:126
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to shift count >= width of type";
+  } else {

danielmarjamaki wrote:
> zaks.anna wrote:
> > It's best not to use ">=" in diagnostic messages.
> > Suggestions: "due to shift count >= width of type" ->
> > - "due to shifting by a value larger than the width of type"
> > - "due to shifting by 5, which is larger than the width of type 'int'" // 
> > Providing the exact value and the type would be very useful and this 
> > information is readily available to us. Note that the users might not see 
> > the type or the value because of macros and such.
> I used "due to shifting by 5, which is larger than the width of type 'int'"
> 
> However I did not see an easy way to show the exact value. So I added 
> getConcreteValue(). Maybe you have a better suggestion. If it's a ConcreteInt 
> I show the exact value, but if it's some range etc then I write "due to 
> shifting by a value that is larger..." instead.
> 
> The message "due to shifting by 64, which is larger than the width of type 
> 'unsigned long long'" is a bit weird imho. Because 64 is not larger than the 
> width. Not sure how this can be rephrazed better though.
SValBuilder has a getKnownValue, does that help?


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D36148: clang-format: [JS] support fields with case/switch/default labels.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

`case:` and `default:` would normally parse as labels for a `switch` block.
However in TypeScript, they can be used in field declarations, e.g.:

  interface I {
case: string;
  }

This change special cases parsing them in declaration lines to avoid wrapping
them.


https://reviews.llvm.org/D36148

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -242,6 +242,12 @@
   verifyFormat("var interface = 2;");
   verifyFormat("interface = 2;");
   verifyFormat("x = interface instanceof y;");
+  verifyFormat("interface Test {\n"
+   "  x: string;\n"
+   "  switch: string;\n"
+   "  case: string;\n"
+   "  default: string;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReservedWordsMethods) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -326,6 +326,11 @@
   break;
 case tok::kw_default:
 case tok::kw_case:
+  if (Style.Language == FormatStyle::LK_JavaScript && 
Line->MustBeDeclaration) {
+// A 'case: string' style field declaration.
+parseStructuralElement();
+break;
+  }
   if (!SwitchLabelEncountered &&
   (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 
1)))
 ++Line->Level;
@@ -953,13 +958,22 @@
 parseDoWhile();
 return;
   case tok::kw_switch:
+if (Style.Language == FormatStyle::LK_JavaScript && 
Line->MustBeDeclaration)
+  // 'switch: string' field declaration.
+  break;
 parseSwitch();
 return;
   case tok::kw_default:
+if (Style.Language == FormatStyle::LK_JavaScript && 
Line->MustBeDeclaration)
+  // 'default: string' field declaration.
+  break;
 nextToken();
 parseLabel();
 return;
   case tok::kw_case:
+if (Style.Language == FormatStyle::LK_JavaScript && 
Line->MustBeDeclaration)
+  // 'case: string' field declaration.
+  break;
 parseCaseLabel();
 return;
   case tok::kw_try:


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -242,6 +242,12 @@
   verifyFormat("var interface = 2;");
   verifyFormat("interface = 2;");
   verifyFormat("x = interface instanceof y;");
+  verifyFormat("interface Test {\n"
+   "  x: string;\n"
+   "  switch: string;\n"
+   "  case: string;\n"
+   "  default: string;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReservedWordsMethods) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -326,6 +326,11 @@
   break;
 case tok::kw_default:
 case tok::kw_case:
+  if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) {
+// A 'case: string' style field declaration.
+parseStructuralElement();
+break;
+  }
   if (!SwitchLabelEncountered &&
   (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1)))
 ++Line->Level;
@@ -953,13 +958,22 @@
 parseDoWhile();
 return;
   case tok::kw_switch:
+if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration)
+  // 'switch: string' field declaration.
+  break;
 parseSwitch();
 return;
   case tok::kw_default:
+if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration)
+  // 'default: string' field declaration.
+  break;
 nextToken();
 parseLabel();
 return;
   case tok::kw_case:
+if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration)
+  // 'case: string' field declaration.
+  break;
 parseCaseLabel();
 return;
   case tok::kw_try:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36149: [Tooling] Add LLVM_NODISCARD to Replacements::merge

2017-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This patch adds LLVM_NODISCARD to Replacements::merge. I've hit this
several times already.


https://reviews.llvm.org/D36149

Files:
  include/clang/Tooling/Core/Replacement.h


Index: include/clang/Tooling/Core/Replacement.h
===
--- include/clang/Tooling/Core/Replacement.h
+++ include/clang/Tooling/Core/Replacement.h
@@ -255,7 +255,7 @@
 
   /// \brief Merges \p Replaces into the current replacements. \p Replaces
   /// refers to code after applying the current replacements.
-  Replacements merge(const Replacements &Replaces) const;
+  LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const;
 
   // Returns the affected ranges in the changed code.
   std::vector getAffectedRanges() const;


Index: include/clang/Tooling/Core/Replacement.h
===
--- include/clang/Tooling/Core/Replacement.h
+++ include/clang/Tooling/Core/Replacement.h
@@ -255,7 +255,7 @@
 
   /// \brief Merges \p Replaces into the current replacements. \p Replaces
   /// refers to code after applying the current replacements.
-  Replacements merge(const Replacements &Replaces) const;
+  LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const;
 
   // Returns the affected ranges in the changed code.
   std::vector getAffectedRanges() const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36149: [Tooling] Add LLVM_NODISCARD to Replacements::merge

2017-08-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Thanks!!!


https://reviews.llvm.org/D36149



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-08-01 Thread William Enright via Phabricator via cfe-commits
Nebiroth created this revision.

Small extension to LSP to allow clients to use clangd to switch between C 
header files and source files.
Final version will use the completed clangd indexer.


https://reviews.llvm.org/D36150

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/hover.test

Index: test/clangd/hover.test
===
--- /dev/null
+++ test/clangd/hover.test
@@ -0,0 +1,26 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 172
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"int main() {\nint a;\na;\n}\n"}}}
+
+Content-Length: 143
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":0,"character":5}}}
+# Go to local variable
+# CHECK: {"jsonrpc":"2.0","id":1,"result":{"contents": {"language": "C++", "value": "int main() {\nint a;\na;\n}"}, "range": {"start": {"line": 0, "character": 0}, "end": {"line": 3, "character": 1
+
+Content-Length: 143
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":1,"character":5}}}
+# Go to local variable
+# CHECK: {"jsonrpc":"2.0","id":1,"result":{"contents": {"language": "C++", "value": "int a"}, "range": {"start": {"line": 1, "character": 0}, "end": {"line": 1, "character": 5
+
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -48,6 +48,8 @@
 JSONOutput &Out) = 0;
   virtual void onGoToDefinition(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput &Out) = 0;
+  virtual void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef ID,
+JSONOutput &Out) = 0;
 };
 
 void regiterCallbackHandlers(JSONRPCDispatcher &Dispatcher, JSONOutput &Out,
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -204,6 +204,23 @@
   ProtocolCallbacks &Callbacks;
 };
 
+struct SwitchSourceHeaderHandler : Handler {
+  SwitchSourceHeaderHandler(JSONOutput &Output, ProtocolCallbacks &Callbacks)
+  : Handler(Output), Callbacks(Callbacks) {}
+
+  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
+auto TDPP = TextDocumentIdentifier::parse(Params);
+if (!TDPP) {
+  return;
+}
+
+Callbacks.onSwitchSourceHeader(*TDPP, ID, Output);
+  }
+
+private:
+  ProtocolCallbacks &Callbacks;
+};
+
 } // namespace
 
 void clangd::regiterCallbackHandlers(JSONRPCDispatcher &Dispatcher,
@@ -239,4 +256,7 @@
   llvm::make_unique(Out, Callbacks));
   Dispatcher.registerHandler("textDocument/definition",
   llvm::make_unique(Out, Callbacks));
+  Dispatcher.registerHandler(
+  "textDocument/switchSourceHeader",
+  llvm::make_unique(Out, Callbacks));
 }
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -182,6 +182,8 @@
   /// Get definition of symbol at a specified \p Line and \p Column in \p File.
   Tagged> findDefinitions(PathRef File, Position Pos);
 
+  std::string switchSourceHeader(std::string path);
+
   /// Run formatting for \p Rng inside \p File.
   std::vector formatRange(PathRef File, Range Rng);
   /// Run formatting for the whole \p File.
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -286,3 +286,18 @@
   });
   return make_tagged(std::move(Result), TaggedFS.Tag);
 }
+
+std::string ClangdServer::switchSourceHeader(std::string path) {
+
+  if (path.compare(path.length() - 4, 4, ".cpp") == 0) {
+path = path.substr(0, (path.length() - 4));
+path.append(".h");
+return "\"" + path + "\"";
+  } else if (path.compare(path.length() - 2, 2, ".h") == 0) {
+path = path.substr(0, (path.length() - 2));
+path.append(".cpp");
+return "\"" + path + "\"";
+  } else {
+return "";
+  }
+}
Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -71,6 +71,8 @@
 JSONOutput &Out) override;
   void onGoToDefinition(TextDocumentPositionParams Params, StringR

Re: r305903 - Function with unparsed body is a definition

2017-08-01 Thread Alexander Kornienko via cfe-commits
This change causes an assertion failure on valid code. Could you take a
look at fixing this?

A reduced test case:

$ cat /tmp/SemaTemplateInstantiateDecl-crash2.cpp
template 
constexpr void f(T) {
  f(0);
}
$ clang -fsyntax-only -std=c++11 /tmp/SemaTemplateInstantiateDecl-crash2.cpp
assert.h assertion failed at
llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:3840 in void
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl *, bool, bool, bool): (Pattern |
| PatternDecl->isDefaulted()) && "unexpected kind of function template
definition"
*** Check failure stack trace: ***
@  0x6094c4a  __assert_fail
@  0x2705bfe  clang::Sema::InstantiateFunctionDefinition()
@  0x2c1fb13  clang::Sema::MarkFunctionReferenced()
@  0x2bec07b  clang::Sema::MarkAnyDeclReferenced()
@  0x2c2327f  MarkExprReferenced()
@  0x2be8f0a  clang::Sema::MarkDeclRefReferenced()
@  0x2980ac0  clang::Sema::FixOverloadedFunctionReference()
@  0x2982e66  FinishOverloadedCallExpr()
@  0x2982b39  clang::Sema::BuildOverloadedCallExpr()
@  0x2be461b  clang::Sema::ActOnCallExpr()
@  0x2571e90  clang::Parser::ParsePostfixExpressionSuffix()
@  0x25784cb  clang::Parser::ParseCastExpression()
@  0x2570865  clang::Parser::ParseCastExpression()
@  0x256f1e3  clang::Parser::ParseAssignmentExpression()
@  0x256f0bf  clang::Parser::ParseExpression()
@  0x2517eeb  clang::Parser::ParseExprStatement()
@  0x2517074
 clang::Parser::ParseStatementOrDeclarationAfterAttributes()
@  0x2516b50  clang::Parser::ParseStatementOrDeclaration()
@  0x251deb4  clang::Parser::ParseCompoundStatementBody()
@  0x251ea53  clang::Parser::ParseFunctionStatementBody()
@  0x24f5b23  clang::Parser::ParseFunctionDefinition()
@  0x25082a5
 clang::Parser::ParseSingleDeclarationAfterTemplate()
@  0x2507652
 clang::Parser::ParseTemplateDeclarationOrSpecialization()
@  0x2506fa5
 clang::Parser::ParseDeclarationStartingWithTemplate()
@  0x25b6853  clang::Parser::ParseDeclaration()
@  0x24f36d5  clang::Parser::ParseExternalDeclaration()
@  0x24f2739  clang::Parser::ParseTopLevelDecl()
@  0x24f220e  clang::Parser::ParseFirstTopLevelDecl()
@  0x24ed582  clang::ParseAST()

On Wed, Jun 21, 2017 at 2:46 PM, Serge Pavlov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sepavloff
> Date: Wed Jun 21 07:46:57 2017
> New Revision: 305903
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305903&view=rev
> Log:
> Function with unparsed body is a definition
>
> While a function body is being parsed, the function declaration is not
> considered
> as a definition because it does not have a body yet. In some cases it
> leads to
> incorrect interpretation, the case is presented in
> https://bugs.llvm.org/show_bug.cgi?id=14785:
> ```
> template struct Somewhat {
>   void internal() const {}
>   friend void operator+(int const &, Somewhat const &) {}
> };
> void operator+(int const &, Somewhat const &x) { x.internal(); }
> ```
> When statement `x.internal()` in the body of global `operator+` is parsed,
> the type
> of `x` must be completed, so the instantiation of `Somewhat` is
> started. It
> instantiates the declaration of `operator+` defined inline, and makes a
> check for
> redefinition. The check does not detect another definition because the
> declaration
> of `operator+` is still not defining as does not have a body yet.
>
> To solves this problem the function `isThisDeclarationADefinition`
> considers
> a function declaration as a definition if it has flag `WillHaveBody` set.
>
> This change fixes PR14785.
>
> Differential Revision: https://reviews.llvm.org/D30375
>
> This is a recommit of 305379, reverted in 305381, with small changes.
>
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/lib/Sema/SemaCUDA.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> cfe/trunk/test/SemaCXX/friend2.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Decl.h?rev=305903&r1=305902&r2=305903&view=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Wed Jun 21 07:46:57 2017
> @@ -1874,7 +1874,7 @@ public:
>///
>bool isThisDeclarationADefinition() const {
>  return IsDeleted || IsDefaulted || Body || IsLateTemplateParsed ||
> -  hasDefiningAttr();
> +  WillHaveBody || hasDefiningAttr();
>}
>
>/// doesThisDeclarationHaveABody - Returns whether this specific
>
> Modified: cf

[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2017-08-01 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 109117.
baloghadamsoftware added a comment.

Overflow scenarios skipped.


https://reviews.llvm.org/D35109

Files:
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/svalbuilder-rearrange-comparisons.c

Index: test/Analysis/svalbuilder-rearrange-comparisons.c
===
--- /dev/null
+++ test/Analysis/svalbuilder-rearrange-comparisons.c
@@ -0,0 +1,163 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(int x);
+void clang_analyzer_eval(int x);
+void clang_analyzer_printState();
+
+int f();
+
+void compare_different_symbol() {
+  int x = f(), y = f();
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 0}}
+}
+
+void compare_different_symbol_plus_left_int() {
+  int x = f()+1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_minus_left_int() {
+  int x = f()-1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 1}}
+}
+
+void compare_different_symbol_plus_right_int() {
+  int x = f(), y = f()+2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 2}}
+}
+
+void compare_different_symbol_minus_right_int() {
+  int x = f(), y = f()-2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 2}}
+}
+
+void compare_different_symbol_plus_left_plus_right_int() {
+  int x = f()+2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_plus_left_minus_right_int() {
+  int x = f()+2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_plus_right_int() {
+  int x = f()-2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_minus_right_int() {
+  int x = f()-2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 1}}
+}
+
+void compare_same_symbol() {
+  int x = f(), y = x;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{1 S32b}}
+}
+
+void compare_same_symbol_plus_left_int() {
+  int x = f(), y = x;
+  ++x;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_minus_left_int() {
+  int x = f(), y = x;
+  --x;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_plus_right_int() {
+  int x = f(), y = x+1;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_minus_right_int() {
+  int x = f(), y = x-1;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_plus_left_plus_right_int() {
+  int x = f(), y = x+1;
+  

[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-08-01 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle requested changes to this revision.
malaperle added inline comments.
This revision now requires changes to proceed.



Comment at: clangd/ClangdServer.cpp:292
+
+  if (path.compare(path.length() - 4, 4, ".cpp") == 0) {
+path = path.substr(0, (path.length() - 4));

this won't work for other extensions, we need to make this more generic. I 
believe you had a list of typical source files extensions and header extensions 
before?



Comment at: clangd/ClangdServer.cpp:294
+path = path.substr(0, (path.length() - 4));
+path.append(".h");
+return "\"" + path + "\"";

we need to try if the file exists otherwise try other typical header extensions



Comment at: clangd/ClangdServer.cpp:296
+return "\"" + path + "\"";
+  } else if (path.compare(path.length() - 2, 2, ".h") == 0) {
+path = path.substr(0, (path.length() - 2));

needs to be more generic and handle more typical header extensions



Comment at: test/clangd/hover.test:1
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.

this is from another patch


https://reviews.llvm.org/D36150



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-08-01 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In the commit message, you could add that we will use and index of symbols 
later to be able to switch from header to source file when the file names don't 
match. This is more or less the justification of why we want this in Clangd and 
not on the client.


https://reviews.llvm.org/D36150



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clangd/ClangdServer.cpp:292
+
+  if (path.compare(path.length() - 4, 4, ".cpp") == 0) {
+path = path.substr(0, (path.length() - 4));

malaperle wrote:
> this won't work for other extensions, we need to make this more generic. I 
> believe you had a list of typical source files extensions and header 
> extensions before?
LLVM has a wonderful `sys::path` library for path manipulations. You could 
rewrite these checks like this:

```
if (llvm::sys::path::extension(path) == ".cpp") {
 SmallString<128> NewPath = path;
 llvm::sys::path::replace_extension(NewPath, "h");
 return "\"" + NewPath.str() + "\"";
}
```


https://reviews.llvm.org/D36150



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


[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-08-01 Thread Barancsuk Lilla via Phabricator via cfe-commits
barancsuk updated this revision to Diff 109120.
barancsuk marked 7 inline comments as done.
barancsuk added a comment.

Address review comments


https://reviews.llvm.org/D35937

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-static-accessed-through-instance.rst
  test/clang-tidy/readability-static-accessed-through-instance.cpp

Index: test/clang-tidy/readability-static-accessed-through-instance.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-static-accessed-through-instance.cpp
@@ -0,0 +1,222 @@
+// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t
+
+struct C {
+  static void foo();
+  static int x;
+  int nsx;
+  void mf() {
+(void)&x;// OK, x is accessed inside the struct.
+(void)&C::x; // OK, x is accessed using a qualified-id.
+foo();   // OK, foo() is accessed inside the struct.
+  }
+  void ns() const;
+};
+
+int C::x = 0;
+
+struct CC {
+  void foo();
+  int x;
+};
+
+template  struct CT {
+  static T foo();
+  static T x;
+  int nsx;
+  void mf() {
+(void)&x;// OK, x is accessed inside the struct.
+(void)&C::x; // OK, x is accessed using a qualified-id.
+foo();   // OK, foo() is accessed inside the struct.
+  }
+};
+
+// Expressions with side effects
+C &f(int, int, int, int);
+void g() {
+  f(1, 2, 3, 4).x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  f(1, 2, 3, 4).x;{{$}}
+}
+
+int i(int &);
+void j(int);
+C h();
+bool a();
+int k(bool);
+
+void f(C c) {
+  j(i(h().x));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: static member
+  // CHECK-FIXES: {{^}}  j(i(h().x));{{$}}
+
+  // The execution of h() depends on the return value of a().
+  j(k(a() && h().x));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: static member
+  // CHECK-FIXES: {{^}}  j(k(a() && h().x));{{$}}
+
+  if ([c]() {
+c.ns();
+return c;
+  }().x == 15)
+;
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: static member
+  // CHECK-FIXES: {{^}}  if ([c]() {{{$}}
+}
+
+// Nested specifiers
+namespace N {
+struct V {
+  static int v;
+  struct T {
+static int t;
+struct U {
+  static int u;
+};
+  };
+};
+}
+
+void f(N::V::T::U u) {
+  N::V v;
+  v.v = 12;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  N::V::v = 12;{{$}}
+
+  N::V::T w;
+  w.t = 12;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  N::V::T::t = 12;{{$}}
+
+  // u.u is not changed to N::V::T::U::u; because the nesting level is over 3.
+  u.u = 12;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  u.u = 12;{{$}}
+
+  using B = N::V::T::U;
+  B b;
+  b.u;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  B::u;{{$}}
+}
+
+// Templates
+template  T CT::x;
+
+template  struct CCT {
+  T foo();
+  T x;
+};
+
+typedef C D;
+
+using E = D;
+
+#define FOO(c) c.foo()
+#define X(c) c.x
+
+template  void f(T t, C c) {
+  t.x; // OK, t is a template parameter.
+  c.x; // 1
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::x; // 1{{$}}
+}
+
+template  struct S { static int x; };
+
+template <> struct S<0> { int x; };
+
+template  void h() {
+  S sN;
+  sN.x; // OK, value of N affects whether x is static or not.
+
+  S<2> s2;
+  s2.x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  S<2>::x;{{$}}
+}
+
+void static_through_instance() {
+  C *c1 = new C();
+  c1->foo(); // 1
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::foo(); // 1{{$}}
+  c1->x; // 2
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::x; // 2{{$}}
+  c1->nsx; // OK, nsx is a non-static member.
+
+  const C *c2 = new C();
+  c2->foo(); // 2
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  C::foo(); // 2{{$}}
+
+  C::foo(); // OK, foo() is accessed using a qualified-id.
+  C::x; // OK, x is accessed using a qualified-id.
+
+  D d;
+  d.foo();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  D::foo();{{$}}
+  d.x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  D::x;{{$}}
+
+  E e;
+  e.foo();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  E::foo();{{$}}
+  e.x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  E::x;{{$}}
+
+  CC *cc = new CC;
+
+  f(*c1, *c1);
+  f(*cc

[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-08-01 Thread Barancsuk Lilla via Phabricator via cfe-commits
barancsuk added inline comments.



Comment at: clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp:23
+  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
+  varDecl(hasStaticStorageDuration(,
+ unless(isInTemplateInstantiation()))

aaron.ballman wrote:
> Why not use `isStaticStorageClass()` here as well?
Unfortunately, `isStaticStorageClass()` misses variable declarations that do 
not contain the static keyword, including definitions of static variables 
outside of their class.
However, `hasStaticStorageDuration()` has no problem finding all static 
variable declarations correctly. 



Comment at: 
docs/clang-tidy/checks/readability-static-accessed-through-instance.rst:7
+Checks for member expressions that access static members through instances, and
+replaces them with the corresponding expressions that use a more readable `::` 
operator.
+

aaron.ballman wrote:
> Eugene.Zelenko wrote:
> > Is :: operator really?
> Same wording suggestion here as above.
The suggested wording is indeed a clearer one, and I rewrote the descriptions 
and the documentation accordingly, however I found, that in the C++ 
International Standard `::` is referred to as a scope (resolution) operator.



Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through 
instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}

aaron.ballman wrote:
> baloghadamsoftware wrote:
> > xazax.hun wrote:
> > > baloghadamsoftware wrote:
> > > > aaron.ballman wrote:
> > > > > This fix-it worries me because it changes the semantics of the code. 
> > > > > The function `f()` is no longer called, and so this isn't a valid 
> > > > > source transformation.
> > > > Maybe the correct fix would be here f(1, 2, 3, 4); C::x;
> > > Maybe for now we should just skip this cases. Expr::HasSideEffects might 
> > > be a  good candidate to filter these cases. 
> > I think including the expression with side effect before the member access 
> > (as I suggested) is not more complicated than skipping these cases.
> Please ensure you handle the more complex cases then, such as:
> ```
> struct S {
>   static int X;
> };
> 
> void g(int &);
> S h();
> 
> void f(S s) {
>   g(h().X);
>   if ([s]() { return s; }().X == 15)
> ;
> }
> ```
Expressions with side effects introduce some troublesome cases.
For example, in the following code, the static member expression, `h().x` does 
not get evaluated if a() returns false. 

```
struct C {
  static int x;
};

void j(int);
int k(bool);
bool a();
C h();

void g(){
  j(k(a() && h().x));
}
```

Maybe for now, the check should filter these expressions with side effects.
They might better be addressed in a follow-up patch.


https://reviews.llvm.org/D35937



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


r309689 - [Tooling] Add LLVM_NODISCARD to Replacements::merge

2017-08-01 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Aug  1 07:58:14 2017
New Revision: 309689

URL: http://llvm.org/viewvc/llvm-project?rev=309689&view=rev
Log:
[Tooling] Add LLVM_NODISCARD to Replacements::merge

Summary:
This patch adds LLVM_NODISCARD to Replacements::merge. I've hit this
several times already.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/Core/Replacement.h

Modified: cfe/trunk/include/clang/Tooling/Core/Replacement.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Replacement.h?rev=309689&r1=309688&r2=309689&view=diff
==
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h (original)
+++ cfe/trunk/include/clang/Tooling/Core/Replacement.h Tue Aug  1 07:58:14 2017
@@ -255,7 +255,7 @@ class Replacements {
 
   /// \brief Merges \p Replaces into the current replacements. \p Replaces
   /// refers to code after applying the current replacements.
-  Replacements merge(const Replacements &Replaces) const;
+  LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const;
 
   // Returns the affected ranges in the changed code.
   std::vector getAffectedRanges() const;


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


[PATCH] D36149: [Tooling] Add LLVM_NODISCARD to Replacements::merge

2017-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309689: [Tooling] Add LLVM_NODISCARD to Replacements::merge 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D36149

Files:
  cfe/trunk/include/clang/Tooling/Core/Replacement.h


Index: cfe/trunk/include/clang/Tooling/Core/Replacement.h
===
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h
+++ cfe/trunk/include/clang/Tooling/Core/Replacement.h
@@ -255,7 +255,7 @@
 
   /// \brief Merges \p Replaces into the current replacements. \p Replaces
   /// refers to code after applying the current replacements.
-  Replacements merge(const Replacements &Replaces) const;
+  LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const;
 
   // Returns the affected ranges in the changed code.
   std::vector getAffectedRanges() const;


Index: cfe/trunk/include/clang/Tooling/Core/Replacement.h
===
--- cfe/trunk/include/clang/Tooling/Core/Replacement.h
+++ cfe/trunk/include/clang/Tooling/Core/Replacement.h
@@ -255,7 +255,7 @@
 
   /// \brief Merges \p Replaces into the current replacements. \p Replaces
   /// refers to code after applying the current replacements.
-  Replacements merge(const Replacements &Replaces) const;
+  LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const;
 
   // Returns the affected ranges in the changed code.
   std::vector getAffectedRanges() const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 109124.
ilya-biryukov added a comment.

Addressed review comments.

- Moved implementations of template function to header.
- Fixed a typo.


https://reviews.llvm.org/D36133

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/GlobalCompilationDatabase.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Regex.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -130,10 +131,16 @@
 namespace clangd {
 namespace {
 
+// Don't wait for async ops in clangd test more than that to avoid blocking
+// indefinitely in case of bugs.
+static const std::chrono::seconds DefaultFutureTimeout =
+std::chrono::seconds(10);
+
 class ErrorCheckingDiagConsumer : public DiagnosticsConsumer {
 public:
-  void onDiagnosticsReady(PathRef File,
-  Tagged> Diagnostics) override {
+  void
+  onDiagnosticsReady(PathRef File,
+ Tagged> Diagnostics) override {
 bool HadError = false;
 for (const auto &DiagAndFixIts : Diagnostics.Value) {
   // FIXME: severities returned by clangd should have a descriptive
@@ -152,9 +159,7 @@
 return HadErrorInLastDiags;
   }
 
-  VFSTag lastVFSTag() {
-return LastVFSTag;
-  }
+  VFSTag lastVFSTag() { return LastVFSTag; }
 
 private:
   std::mutex Mutex;
@@ -276,9 +281,15 @@
 auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
 
 FS.ExpectedFile = SourceFilename;
-Server.addDocument(SourceFilename, SourceContents);
+
+// Have to sync reparses because RunSynchronously is false.
+auto AddDocFuture = Server.addDocument(SourceFilename, SourceContents);
 
 auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
+
+// Wait for reparse to finish before checking for errors.
+EXPECT_EQ(AddDocFuture.wait_for(DefaultFutureTimeout),
+  std::future_status::ready);
 EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
 return Result;
   }
@@ -338,16 +349,25 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, "");
+  ParseFuture = Server.addDocument(FooCpp, "");
   auto DumpParseEmpty = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
-  Server.addDocument(FooCpp, SourceContents);
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -374,18 +394,27 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
-  Server.addDocument(FooCpp, SourceContents);
+  // To sync reparses before checking for errors.
+  std::future ParseFuture;
+
+  ParseFuture = Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParseDifferent = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  ASSERT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
 
   FS.Files[FooH] = "int a;";
-  Server.forceReparse(FooCpp);
+  ParseFuture = Server.forceReparse(FooCpp);
   auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp);
+  EXPECT_EQ(ParseFuture.wait_for(DefaultFutureTimeout),
+std::future_status::ready);
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 
   EXPECT_EQ(DumpParse1, DumpParse2);
@@ -404,10 +433,12 @@
   FS.Files[FooCpp] = SourceContents;
   FS.ExpectedFile = FooCpp;
 
+  // No need to sync reparses, because RunSynchronously is set
+  // to true.
   FS.Tag = "123";
   Server.addDocument(FooCpp, SourceContents);
-  EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).T

[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added inline comments.



Comment at: clangd/ClangdServer.h:113
+  /// queue. The request will be run on a separate thread.
+  template  void addToFront(Func &&F, Args &&... 
As);
+  /// Add a new request to run function \p F with args \p As to the end of the

bkramer wrote:
> Why the template? This is awkward now because it can only be called from 
> ClangdServer.cpp
Storing `std::future`s  with `std::async(std::launch::deferred, ...` makes 
things easier than storing `std::function`, as that allows to move into the 
caller(`std::function` must be copyable).
But we want to store only properly created `std::future`s, so we create them on 
our own, hence the signature similar to `std::async`. 

I actually think that the signature itself is not that bad, but the fact that 
definition is only available in `.cpp` file is wrong. I've moved definintions 
to header.



Comment at: clangd/ClangdUnitStore.cpp:22
 return;
   OpenedFiles.erase(It);
 }

bkramer wrote:
> Not introduced in this commit, but this is equivalent to 
> OpenedFiles.erase(File) without the find and check.
The code has changed a bit after initial submission. It returns removed element 
now and there seems to be no equivalent in `StringMap` for that.


https://reviews.llvm.org/D36133



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


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2017-08-01 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 109126.
baloghadamsoftware added a comment.
Herald added a subscriber: JDevlieghere.

Test changed. I made some bad throws reachable, but the frontend check still 
does detects them.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/ExceptionEscapeCheck.cpp
  clang-tidy/misc/ExceptionEscapeCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-exception-escape.rst
  test/clang-tidy/misc-exception-escape.cpp

Index: test/clang-tidy/misc-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-exception-escape.cpp
@@ -0,0 +1,256 @@
+// RUN: %check_clang_tidy %s misc-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: misc-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: misc-exception-escape.EnabledFunctions, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function '~throwing_destructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'throwing_move_constructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: function 'operator=' throws
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_noexcept' throws
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_throw_nothing' throws
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch' throws
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_catch_some' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_each' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_all' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_rethrow' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_throw' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_rethrow_the_rest' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_derived_catch_base' throws
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_try' throws
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_try_nested_try' throws
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_catch' throws
+  try {
+try {
+  throw 1;
+} catch(int &) {
+  throw 1.1;
+}
+  } catch(double &) {
+  }
+}
+
+void catch_nested_try() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1; 
+} catch(int &) {
+}
+  }
+}
+
+void bad_catch_nested_try() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void implicit_int_thrower() {
+  throw 1;
+}
+
+void explicit_int_thrower() throw(int);
+
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :

[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-08-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Even though it is not undefined behavior in C, it can still cause surprising 
behavior for the users. I think maybe putting it into the optin package instead 
of cplusplus is better. What do you think?


https://reviews.llvm.org/D33672



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-08-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Even though it is not undefined behavior in C, it can still cause surprising 
behavior for the users. I think maybe putting it into the optin package instead 
of cplusplus is better. What do you think?


https://reviews.llvm.org/D33672



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


[PATCH] D36154: Adapt clang-tidy checks to changing semantics of hasDeclaration.

2017-08-01 Thread Manuel Klimek via Phabricator via cfe-commits
klimek created this revision.
Herald added a subscriber: JDevlieghere.

https://reviews.llvm.org/D36154

Files:
  clang-tidy/google/StringReferenceMemberCheck.cpp
  clang-tidy/misc/DanglingHandleCheck.cpp
  clang-tidy/misc/InaccurateEraseCheck.cpp
  clang-tidy/misc/UseAfterMoveCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/MakeSharedCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/performance/FasterStringFindCheck.cpp
  clang-tidy/performance/InefficientStringConcatenationCheck.cpp
  clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tidy/readability/RedundantStringInitCheck.cpp
  include-fixer/find-all-symbols/FindAllSymbols.cpp

Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -230,7 +230,8 @@
   MatchFinder->addMatcher(
   typeLoc(isExpansionInMainFile(),
   loc(templateSpecializationType(hasDeclaration(
-  classTemplateDecl(has(CXXRecords.bind("use"))),
+  classTemplateSpecializationDecl(hasSpecializedTemplate(
+  classTemplateDecl(has(CXXRecords.bind("use"),
   this);
 }
 
Index: clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -47,7 +47,8 @@
   // string bar("");
   Finder->addMatcher(
   namedDecl(
-  varDecl(hasType(cxxRecordDecl(hasName("basic_string"))),
+  varDecl(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(hasName("basic_string")),
   hasInitializer(expr(ignoringImplicit(anyOf(
   EmptyStringCtorExpr,
   EmptyStringCtorExprWithTemporaries)))
Index: clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -77,7 +77,8 @@
 return;
 
   // Match expressions of type 'string' or 'string*'.
-  const auto StringDecl = cxxRecordDecl(hasName("::std::basic_string"));
+  const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(hasName("::std::basic_string"));
   const auto StringExpr =
   expr(anyOf(hasType(StringDecl), hasType(qualType(pointsTo(StringDecl);
 
Index: clang-tidy/readability/ContainerSizeEmptyCheck.cpp
===
--- clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -32,16 +32,18 @@
   if (!getLangOpts().CPlusPlus)
 return;
 
-  const auto ValidContainer = cxxRecordDecl(isSameOrDerivedFrom(
-  namedDecl(
-  has(cxxMethodDecl(
-  isConst(), parameterCountIs(0), isPublic(), hasName("size"),
-  returns(qualType(isInteger(), unless(booleanType()
-  .bind("size")),
-  has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
-hasName("empty"), returns(booleanType()))
-  .bind("empty")))
-  .bind("container")));
+  const auto ValidContainer = qualType(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom(
+  namedDecl(
+  has(cxxMethodDecl(
+  isConst(), parameterCountIs(0), isPublic(),
+  hasName("size"),
+  returns(qualType(isInteger(), unless(booleanType()
+  .bind("size")),
+  has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
+hasName("empty"), returns(booleanType()))
+  .bind("empty")))
+  .bind("container")));
 
   const auto WrongUse = anyOf(
   hasParent(binaryOperator(
Index: clang-tidy/performance/InefficientStringConcatenationCheck.cpp
===
--- clang-tidy/performance/InefficientStringConcatenationCheck.cpp
+++ clang-tidy/performance/InefficientStringConcatenationCheck.cpp
@@ -33,7 +33,8 @@
 return;
 
   const auto BasicStringType =
-  hasType(cxxRecordDecl(hasName("::std::basic_string")));
+  hasType(qualType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(hasName("::std::basic_string")));
 
   const auto BasicStringPlusOperator = cxxOperatorCallExpr(
   hasOverloadedOperatorName("+"),
Index: clang-tidy/performance/FasterStr

[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

ship it!


https://reviews.llvm.org/D36133



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


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2017-08-01 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

In https://reviews.llvm.org/D33537#827509, @baloghadamsoftware wrote:

> Test changed. I made some bad throws reachable, but the frontend check still 
> does detects them.


If block contains two or more throws, that mean compiler can not statically 
know throw is really throws.  So to avoid fails positive, if one of throw can 
be catch, compiler don't emit warning.

Jennifer


https://reviews.llvm.org/D33537



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


[PATCH] D36155: Use VFS operations in FileManager::makeAbsolutePath.

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

It used to call into llvm::sys::fs::make_absolute.


https://reviews.llvm.org/D36155

Files:
  lib/Basic/FileManager.cpp
  unittests/Basic/FileManagerTest.cpp


Index: unittests/Basic/FileManagerTest.cpp
===
--- unittests/Basic/FileManagerTest.cpp
+++ unittests/Basic/FileManagerTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Basic/FileSystemStatCache.h"
+#include "clang/Basic/VirtualFileSystem.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Path.h"
@@ -296,4 +297,30 @@
 
 #endif  // !LLVM_ON_WIN32
 
+TEST_F(FileManagerTest, makeAbsoluteUsesVFS) {
+  SmallString<64> CustomWorkingDir;
+#ifdef LLVM_ON_WIN32
+  CustomWorkingDir = "C:";
+#else
+  CustomWorkingDir = "/";
+#endif
+  llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path");
+
+  auto FS =
+  IntrusiveRefCntPtr(new vfs::InMemoryFileSystem);
+  // setCurrentworkingdirectory must finish without error.
+  ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
+
+  FileSystemOptions Opts;
+  FileManager Manager(Opts, FS);
+
+  SmallString<64> Path("a/foo.cpp");
+
+  SmallString<64> ExpectedResult(CustomWorkingDir);
+  llvm::sys::path::append(ExpectedResult, Path);
+
+  ASSERT_TRUE(Manager.makeAbsolutePath(Path));
+  EXPECT_EQ(Path, ExpectedResult);
+}
+
 } // anonymous namespace
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -408,7 +408,7 @@
   bool Changed = FixupRelativePath(Path);
 
   if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size( {
-llvm::sys::fs::make_absolute(Path);
+FS->makeAbsolute(Path);
 Changed = true;
   }
 


Index: unittests/Basic/FileManagerTest.cpp
===
--- unittests/Basic/FileManagerTest.cpp
+++ unittests/Basic/FileManagerTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Basic/FileSystemStatCache.h"
+#include "clang/Basic/VirtualFileSystem.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Path.h"
@@ -296,4 +297,30 @@
 
 #endif  // !LLVM_ON_WIN32
 
+TEST_F(FileManagerTest, makeAbsoluteUsesVFS) {
+  SmallString<64> CustomWorkingDir;
+#ifdef LLVM_ON_WIN32
+  CustomWorkingDir = "C:";
+#else
+  CustomWorkingDir = "/";
+#endif
+  llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path");
+
+  auto FS =
+  IntrusiveRefCntPtr(new vfs::InMemoryFileSystem);
+  // setCurrentworkingdirectory must finish without error.
+  ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
+
+  FileSystemOptions Opts;
+  FileManager Manager(Opts, FS);
+
+  SmallString<64> Path("a/foo.cpp");
+
+  SmallString<64> ExpectedResult(CustomWorkingDir);
+  llvm::sys::path::append(ExpectedResult, Path);
+
+  ASSERT_TRUE(Manager.makeAbsolutePath(Path));
+  EXPECT_EQ(Path, ExpectedResult);
+}
+
 } // anonymous namespace
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -408,7 +408,7 @@
   bool Changed = FixupRelativePath(Path);
 
   if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size( {
-llvm::sys::fs::make_absolute(Path);
+FS->makeAbsolute(Path);
 Changed = true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35894: [clangd] Code hover for Clangd

2017-08-01 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle requested changes to this revision.
malaperle added a comment.
This revision now requires changes to proceed.

Can you also update your code with the latest SVN trunk? The patch does not 
apply cleanly anymore.




Comment at: clangd/ClangdServer.cpp:11
 #include "ClangdServer.h"
+#include "Protocol.h"
 #include "clang/Format/Format.h"

I don't know if the intention was to keep the protocol completely out of the 
ClangdServer class. Maybe someone else can clarify. But either way, I see that 
ClangdUnit does include "Protocol.h" so it's probably OK for now.



Comment at: clangd/ClangdServer.cpp:297
+  
+  MarkedString MS = MarkedString("", "");
+  Range R;

Use default constructor for MarkedString instead? MarkedString MS;



Comment at: clangd/ClangdUnit.h:72
 
+  Hover getHover(Location L){
+

Move definition to ClangdUnit.cpp ?



Comment at: clangd/ClangdUnit.h:74
+
+MarkedString MS = MarkedString("", "");
+Range R;

MarkedString MS;



Comment at: clangd/ClangdUnit.h:76
+Range R;
+const FileEntry *FE = Unit->getFileManager().getFile(L.uri.file);
+FileID id = Unit->getSourceManager().translateFile(FE);

I don't know if you have access to a FileManager with the latest SVN trunk.



Comment at: clangd/ClangdUnit.h:82
+ref = ref.slice(start, end);
+MS = MarkedString("C++", ref);
+R = L.range;

MS = {"", "C++", ref};?



Comment at: clangd/ClangdUnit.h:87
+  }
+  unsigned start;
+  unsigned end;

I don't think those two are used (start,end). But if they are, those fields 
should not be in ClangdUnit.h



Comment at: clangd/Protocol.h:26
 #include "llvm/Support/YAMLParser.h"
+#include "clang/Basic/SourceLocation.h"
 #include 

not needed?



Comment at: clangd/Protocol.h:309
+struct MarkedString {
+  /**
+ * MarkedString can be used to render human readable text. It is either a

I don't think we should copy big parts of the documentation verbatim, 
otherwise, we'd have to distribute part of Clangd under the license for the 
LSP. I'm not familiar with "Creative Commons Attribution 3.0", etc to really 
know if you can copy everything and change the license to the LLVM's but I 
think it's safe to say that we can't.



Comment at: clangd/Protocol.h:329
+  MarkedString(std::string markdown)
+  : markdownString(markdown), codeBlockLanguage(""), codeBlockValue("") {}
+

I don't think the constructors bring much, I think they should be removed.



Comment at: clangd/Protocol.h:331
+
+  MarkedString(std::string blockLanguage, std::string blockValue)
+  : markdownString(""), codeBlockLanguage(blockLanguage),

remove?



Comment at: clangd/Protocol.h:344
+
+  Hover(MarkedString ms, Range r) : contents(ms), range(r) {}
+

MS, R  (first letters of params/local vars is capitalized)



Comment at: clangd/clients/clangd-vscode/src/extension.ts:3
 import * as vscodelc from 'vscode-languageclient';
+import * as vscodejsonrpc from 'vscode-jsonrpc';
 

remove?


https://reviews.llvm.org/D35894



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


r309695 - clang-format: [JS] handle object types in extends positions.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 08:46:10 2017
New Revision: 309695

URL: http://llvm.org/viewvc/llvm-project?rev=309695&view=rev
Log:
clang-format: [JS] handle object types in extends positions.

Summary:
clang-format would previously drop the whitespace after `extends` in code such 
as:

class Foo extends {} {}

Where the first set of curly braces is an inline object literal type.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309695&r1=309694&r2=309695&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 08:46:10 2017
@@ -2341,7 +2341,8 @@ bool TokenAnnotator::spaceRequiredBefore
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=309695&r1=309694&r2=309695&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Aug  1 08:46:10 2017
@@ -1970,6 +1970,17 @@ void UnwrappedLineParser::parseRecord(bo
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309695&r1=309694&r2=309695&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 08:46:10 2017
@@ -1400,6 +1400,17 @@ TEST_F(FormatTestJS, InterfaceDeclaratio
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"


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


[clang-tools-extra] r309696 - [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug  1 08:51:38 2017
New Revision: 309696

URL: http://llvm.org/viewvc/llvm-project?rev=309696&view=rev
Log:
[clangd] Rewrote AST and Preamble management.

Summary: The new implementation allows code completion that never waits for AST.

Reviewers: bkramer, krasimir, klimek

Reviewed By: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=309696&r1=309695&r2=309696&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Aug  1 08:51:38 2017
@@ -23,6 +23,16 @@ using namespace clang::clangd;
 
 namespace {
 
+class FulfillPromiseGuard {
+public:
+  FulfillPromiseGuard(std::promise &Promise) : Promise(Promise) {}
+
+  ~FulfillPromiseGuard() { Promise.set_value(); }
+
+private:
+  std::promise &Promise;
+};
+
 std::vector formatCode(StringRef Code, StringRef 
Filename,
  ArrayRef Ranges) {
   // Call clang-format.
@@ -79,7 +89,7 @@ ClangdScheduler::ClangdScheduler(bool Ru
   // using not-yet-initialized members
   Worker = std::thread([this]() {
 while (true) {
-  std::function Request;
+  std::future Request;
 
   // Pick request from the queue
   {
@@ -99,7 +109,7 @@ ClangdScheduler::ClangdScheduler(bool Ru
 RequestQueue.pop_front();
   } // unlock Mutex
 
-  Request();
+  Request.get();
 }
   });
 }
@@ -117,32 +127,6 @@ ClangdScheduler::~ClangdScheduler() {
   Worker.join();
 }
 
-void ClangdScheduler::addToFront(std::function Request) {
-  if (RunSynchronously) {
-Request();
-return;
-  }
-
-  {
-std::lock_guard Lock(Mutex);
-RequestQueue.push_front(Request);
-  }
-  RequestCV.notify_one();
-}
-
-void ClangdScheduler::addToEnd(std::function Request) {
-  if (RunSynchronously) {
-Request();
-return;
-  }
-
-  {
-std::lock_guard Lock(Mutex);
-RequestQueue.push_back(Request);
-  }
-  RequestCV.notify_one();
-}
-
 ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB,
DiagnosticsConsumer &DiagConsumer,
FileSystemProvider &FSProvider,
@@ -153,41 +137,73 @@ ClangdServer::ClangdServer(GlobalCompila
   PCHs(std::make_shared()),
   WorkScheduler(RunSynchronously) {}
 
-void ClangdServer::addDocument(PathRef File, StringRef Contents) {
+std::future ClangdServer::addDocument(PathRef File, StringRef Contents) {
   DocVersion Version = DraftMgr.updateDraft(File, Contents);
-  Path FileStr = File;
-  WorkScheduler.addToFront([this, FileStr, Version]() {
-auto FileContents = DraftMgr.getDraft(FileStr);
-if (FileContents.Version != Version)
-  return; // This request is outdated, do nothing
 
-assert(FileContents.Draft &&
-   "No contents inside a file that was scheduled for reparse");
-auto TaggedFS = FSProvider.getTaggedFileSystem(FileStr);
-Units.runOnUnit(
-FileStr, *FileContents.Draft, ResourceDir, CDB, PCHs, TaggedFS.Value,
-[&](ClangdUnit const &Unit) {
-  DiagConsumer.onDiagnosticsReady(
-  FileStr, make_tagged(Unit.getLocalDiagnostics(), TaggedFS.Tag));
-});
-  });
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  std::shared_ptr Resources =
+  Units.getOrCreateFile(File, ResourceDir, CDB, PCHs, TaggedFS.Value);
+
+  std::future>> DeferredRebuild =
+  Resources->deferRebuild(Contents, TaggedFS.Value);
+  std::promise DonePromise;
+  std::future DoneFuture = DonePromise.get_future();
+
+  Path FileStr = File;
+  VFSTag Tag = TaggedFS.Tag;
+  auto ReparseAndPublishDiags =
+  [this, FileStr, Version,
+   Tag](std::future>>
+DeferredRebuild,
+std::promise DonePromise) -> void {
+FulfillPromiseGuard Guard(DonePromise);
+
+auto CurrentVersion = DraftMgr.getVersion(FileStr);
+if (CurrentVersion != Version)
+  return; // This request is outdated
+
+auto Diags = DeferredRebuild.get();
+if (!Diags)
+  return; // A new reparse was requested before this one completed.
+DiagConsumer.onDiagnosticsReady(FileStr,
+make_tagged(std::move(*Diags), Tag));
+  };
+
+  WorkScheduler.addToFront(std::move(ReparseAndPublishDiags),
+   std

r309697 - clang-format: [JS] support default imports.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 08:54:43 2017
New Revision: 309697

URL: http://llvm.org/viewvc/llvm-project?rev=309697&view=rev
Log:
clang-format: [JS] support default imports.

Summary: Formerly, `import {default as X} from y;` would not be recognized as 
an import.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/unittests/Format/SortImportsTestJS.cpp

Modified: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/SortJavaScriptImports.cpp?rev=309697&r1=309696&r2=309697&view=diff
==
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp (original)
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp Tue Aug  1 08:54:43 2017
@@ -413,7 +413,7 @@ private:
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (Current->isNot(tok::identifier))
+  if (!Current->isOneOf(tok::identifier, tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@ private:
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (Current->isNot(tok::identifier))
+if (!Current->isOneOf(tok::identifier, tok::kw_default))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();

Modified: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJS.cpp?rev=309697&r1=309696&r2=309697&view=diff
==
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp Tue Aug  1 08:54:43 2017
@@ -300,6 +300,14 @@ TEST_F(SortImportsTestJS, SortMultiLine)
  "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+ "import {default as B} from 'b';\n",
+ "import {default as B} from 'b';\n"
+ "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
Herald added a subscriber: mgorny.

Symbol occurrences store the results of local rename and will also be used for 
the global, indexed rename results. They can be converted to a set of 
`AtomicChanges` as well. This is a preparation patch for both the support of 
multi-piece local-renames (ObjC selectors) and the migration of clang-rename 
over to clang-refactor.
This is a non functional change, and I just wanted to make sure the general 
direction of this patch is accepted before committing.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156

Files:
  include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Index: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -48,8 +48,8 @@
const ASTContext &Context)
   : RecursiveSymbolVisitor(Context.getSourceManager(),
Context.getLangOpts()),
-USRSet(USRs.begin(), USRs.end()), PrevName(PrevName), Context(Context) {
-  }
+USRSet(USRs.begin(), USRs.end()), PrevName(PrevName),
+Occurrences(PrevName), Context(Context) {}
 
   bool visitSymbolOccurrence(const NamedDecl *ND,
  ArrayRef NameRanges) {
@@ -68,11 +68,9 @@
 
   // Non-visitors:
 
-  // \brief Returns a list of unique locations. Duplicate or overlapping
-  // locations are erroneous and should be reported!
-  const std::vector &getLocationsFound() const {
-return LocationsFound;
-  }
+  /// \brief Returns a set of unique symbol occurrences. Duplicate or
+  /// overlapping occurrences are erroneous and should be reported!
+  SymbolOccurrences &getOccurrences() { return Occurrences; }
 
 private:
   void checkAndAddLocation(SourceLocation Loc) {
@@ -87,12 +85,13 @@
 // The token of the source location we find actually has the old
 // name.
 if (Offset != StringRef::npos)
-  LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset));
+  Occurrences.emplace_back(SymbolOccurrence::MatchingSymbol,
+   BeginLoc.getLocWithOffset(Offset));
   }
 
   const std::set USRSet;
   const std::string PrevName;
-  std::vector LocationsFound;
+  SymbolOccurrences Occurrences;
   const ASTContext &Context;
 };
 
@@ -391,12 +390,11 @@
 
 } // namespace
 
-std::vector
-getLocationsOfUSRs(const std::vector &USRs, StringRef PrevName,
-   Decl *Decl) {
+SymbolOccurrences getOccurrencesOfUSRs(ArrayRef USRs,
+   StringRef PrevName, Decl *Decl) {
   USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext());
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }
 
 std::vector
Index: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- /dev/null
+++ lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -0,0 +1,22 @@
+//===--- SymbolOccurrences.cpp - Clang refactoring library ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+
+using namespace clang;
+using namespace tooling;
+
+void SymbolOccurrences::emplace_back(SymbolOccurrence::OccurrenceKind Kind,
+ ArrayRef Locations) {
+  unsigned Offset = this->Locations.size();
+  Occurrences.push_back({Kind, Offset, (unsigned)Locations.size()});
+  for (const auto &Loc : Locations)
+this->Locations.push_back(Loc);
+}
Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -32,6 +32,42 @@
 namespace clang {
 namespace tooling {
 
+Expected>
+createRenameReplacements(const SymbolOccurrences &Occurrences,
+ const SourceManager &SM,
+ ArrayRef NewNameStrings) {
+  // FIXME: A true local rename can use just one AtomicChange.
+  std::vector Changes;
+  for (const auto &Occurrence : Occurrences) {
+ArrayRef Locs = Occurrence.getNameLocations();
+assert(NewNameStrings.size() == Locs.s

[PATCH] D36144: clang-format: [JS] consistenly format enums.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D36144



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


[PATCH] D36146: clang-format: [JS] whitespace between keywords and parenthesized expressions.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D36146



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


[PATCH] D36147: clang-format: [JS] handle union types in arrow functions.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D36147



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


[PATCH] D36133: [clangd] Rewrote AST and Preamble management.

2017-08-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309696: [clangd] Rewrote AST and Preamble management. 
(authored by ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D36133

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/ClangdUnit.h
  clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
  clang-tools-extra/trunk/clangd/ClangdUnitStore.h
  clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -108,30 +108,54 @@
   ClangdScheduler(bool RunSynchronously);
   ~ClangdScheduler();
 
-  /// Add \p Request to the start of the queue. \p Request will be run on a
-  /// separate worker thread.
-  /// \p Request is scheduled to be executed before all currently added
-  /// requests.
-  void addToFront(std::function Request);
-  /// Add \p Request to the end of the queue. \p Request will be run on a
-  /// separate worker thread.
-  /// \p Request is scheduled to be executed after all currently added
-  /// requests.
-  void addToEnd(std::function Request);
+  /// Add a new request to run function \p F with args \p As to the start of the
+  /// queue. The request will be run on a separate thread.
+  template 
+  void addToFront(Func &&F, Args &&... As) {
+if (RunSynchronously) {
+  std::forward(F)(std::forward(As)...);
+  return;
+}
+
+{
+  std::lock_guard Lock(Mutex);
+  RequestQueue.push_front(std::async(std::launch::deferred,
+ std::forward(F),
+ std::forward(As)...));
+}
+RequestCV.notify_one();
+  }
+
+  /// Add a new request to run function \p F with args \p As to the end of the
+  /// queue. The request will be run on a separate thread.
+  template  void addToEnd(Func &&F, Args &&... As) {
+if (RunSynchronously) {
+  std::forward(F)(std::forward(As)...);
+  return;
+}
+
+{
+  std::lock_guard Lock(Mutex);
+  RequestQueue.push_back(std::async(std::launch::deferred,
+std::forward(F),
+std::forward(As)...));
+}
+RequestCV.notify_one();
+  }
 
 private:
   bool RunSynchronously;
   std::mutex Mutex;
-  /// We run some tasks on a separate thread(parsing, ClangdUnit cleanup).
+  /// We run some tasks on a separate threads(parsing, CppFile cleanup).
   /// This thread looks into RequestQueue to find requests to handle and
   /// terminates when Done is set to true.
   std::thread Worker;
   /// Setting Done to true will make the worker thread terminate.
   bool Done = false;
   /// A queue of requests.
   /// FIXME(krasimir): code completion should always have priority over parsing
   /// for diagnostics.
-  std::deque> RequestQueue;
+  std::deque> RequestQueue;
   /// Condition variable to wake up the worker thread.
   std::condition_variable RequestCV;
 };
@@ -163,12 +187,16 @@
   /// \p File is already tracked. Also schedules parsing of the AST for it on a
   /// separate thread. When the parsing is complete, DiagConsumer passed in
   /// constructor will receive onDiagnosticsReady callback.
-  void addDocument(PathRef File, StringRef Contents);
+  /// \return A future that will become ready when the rebuild (including
+  /// diagnostics) is finished.
+  std::future addDocument(PathRef File, StringRef Contents);
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it.
-  void removeDocument(PathRef File);
+  /// \return A future that will become ready the file is removed and all
+  /// associated reosources are freed.
+  std::future removeDocument(PathRef File);
   /// Force \p File to be reparsed using the latest contents.
-  void forceReparse(PathRef File);
+  std::future forceReparse(PathRef File);
 
   /// Run code completion for \p File at \p Pos. If \p OverridenContents is not
   /// None, they will used only for code completion, i.e. no diagnostics update
@@ -209,7 +237,7 @@
   DiagnosticsConsumer &DiagConsumer;
   FileSystemProvider &FSProvider;
   DraftStore DraftMgr;
-  ClangdUnitStore Units;
+  CppFileCollection Units;
   std::string ResourceDir;
   std::shared_ptr PCHs;
   // WorkScheduler has to be the last member, because its destructor has to be
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -23,6 +23,16 @@
 
 namespace {
 
+class FulfillPromiseGuard {
+public:
+  F

[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2355
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete)))
+  return false;

Why is instanceof not required in this list?



Comment at: unittests/Format/FormatTestJS.cpp:237
+  verifyFormat("x.switch() = 1;");
+  verifyFormat("x.case() = 1;");
   verifyFormat("x = {\n"

no test for delete?


https://reviews.llvm.org/D36142



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


[PATCH] D36131: clang-format: [JS] handle object types in extends positions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309695: clang-format: [JS] handle object types in extends 
positions. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36131

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2341,7 +2341,8 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: number} { }
+  nextToken();
+  if (FormatTok->is(tok::l_brace)) {
+tryToParseBracedList();
+continue;
+  }
+}
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1400,6 +1400,17 @@
"}");
 }
 
+TEST_F(FormatTestJS, ObjectTypesInExtendsImplements) {
+  verifyFormat("class C extends {} {}");
+  verifyFormat("class C implements {bar: number} {}");
+  // Somewhat odd, but probably closest to reasonable formatting?
+  verifyFormat("class C implements {\n"
+   "  bar: number,\n"
+   "  baz: string,\n"
+   "} {}");
+  verifyFormat("class C {}");
+}
+
 TEST_F(FormatTestJS, EnumDeclarations) {
   verifyFormat("enum Foo {\n"
"  A = 1,\n"
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2341,7 +2341,8 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
   return false;
 if (Right.isOneOf(tok::l_brace, tok::l_square) &&
-Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
+ Keywords.kw_extends, Keywords.kw_implements))
   return true;
 // JS methods can use some keywords as names (e.g. `delete()`).
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1970,6 +1970,17 @@
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
+if (Style.Language == FormatStyle::LK_JavaScript &&
+FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
+  // JavaScript/TypeScript supports inline object types in
+  // extends/implements positions:
+  // class Foo implements {bar: num

[PATCH] D36139: clang-format: [JS] prefer wrapping chains over empty literals.

2017-08-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2009
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if ((Left.is(tok::l_brace) && Right.is(tok::r_brace)) ||
+(Left.is(tok::l_square) && Right.is(tok::r_square)) ||

Or just Left.opensScope() && Right.closesScope()?

Technically, that's probably not the same thing, but otherwise you have 
unmatched brackets and that's bad no matter what, no?


https://reviews.llvm.org/D36139



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


[PATCH] D36132: clang-format: [JS] support default imports.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309697: clang-format: [JS] support default imports. 
(authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D36132?vs=109059&id=109136#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36132

Files:
  cfe/trunk/lib/Format/SortJavaScriptImports.cpp
  cfe/trunk/unittests/Format/SortImportsTestJS.cpp


Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -413,7 +413,7 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (Current->isNot(tok::identifier))
+  if (!Current->isOneOf(tok::identifier, tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (Current->isNot(tok::identifier))
+if (!Current->isOneOf(tok::identifier, tok::kw_default))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
Index: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
===
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp
@@ -300,6 +300,14 @@
  "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+ "import {default as B} from 'b';\n",
+ "import {default as B} from 'b';\n"
+ "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -413,7 +413,7 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (Current->isNot(tok::identifier))
+  if (!Current->isOneOf(tok::identifier, tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (Current->isNot(tok::identifier))
+if (!Current->isOneOf(tok::identifier, tok::kw_default))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
Index: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
===
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp
@@ -300,6 +300,14 @@
  "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+ "import {default as B} from 'b';\n",
+ "import {default as B} from 'b';\n"
+ "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36154: Adapt clang-tidy checks to changing semantics of hasDeclaration.

2017-08-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clang-tidy/google/StringReferenceMemberCheck.cpp:31
+  auto String = anyOf(namedDecl(hasName("::std::string")),
   recordDecl(hasName("::string")));
   auto ConstString = qualType(isConstQualified(), hasDeclaration(String));

I think this should be namedDecl too.


https://reviews.llvm.org/D36154



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-08-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a reviewer: ilya-biryukov.
ilya-biryukov added a comment.

Also, +1 to the comments about file extensions, we have to cover at least `.c`, 
`.cc` and `.cpp` for source files, `.h` and `.hpp` for header files.




Comment at: clangd/ClangdLSPServer.cpp:228
+R"({"jsonrpc":"2.0","id":)" + ID.str() +
+R"(,"result":)" + result + R"(})");
+}

We should probably use `Uri` here.



Comment at: clangd/ClangdServer.h:185
 
+  std::string switchSourceHeader(std::string path);
+

Please use descriptive typedefs for paths: `Path` (equivalent to `std::string`) 
for return type and `PathRef` (equivalent to `StringRef`) for parameter type.



Comment at: clangd/ClangdServer.h:185
 
+  std::string switchSourceHeader(std::string path);
+

ilya-biryukov wrote:
> Please use descriptive typedefs for paths: `Path` (equivalent to 
> `std::string`) for return type and `PathRef` (equivalent to `StringRef`) for 
> parameter type.
Maybe add a small comment for this function to indicate it's a fairly trivial 
helper?



Comment at: clangd/ProtocolHandlers.cpp:260
+  Dispatcher.registerHandler(
+  "textDocument/switchSourceHeader",
+  llvm::make_unique(Out, Callbacks));

I don't see this method in the [[ 
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md | 
LSP spec ]].
Is this some kind of extension?

Could you add some comments on that with pointers to proposal/explanation of 
where this extension is used?


https://reviews.llvm.org/D36150



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


Re: r305903 - Function with unparsed body is a definition

2017-08-01 Thread Serge Pavlov via cfe-commits
Yes, sure, I will investigate it.

Thanks,
--Serge

2017-08-01 21:32 GMT+07:00 Alexander Kornienko :

> This change causes an assertion failure on valid code. Could you take a
> look at fixing this?
>
> A reduced test case:
>
> $ cat /tmp/SemaTemplateInstantiateDecl-crash2.cpp
> template 
> constexpr void f(T) {
>   f(0);
> }
> $ clang -fsyntax-only -std=c++11 /tmp/SemaTemplateInstantiateDecl-
> crash2.cpp
> assert.h assertion failed at llvm/tools/clang/lib/Sema/
> SemaTemplateInstantiateDecl.cpp:3840 in void clang::Sema::
> InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl
> *, bool, bool, bool): (Pattern |
> | PatternDecl->isDefaulted()) && "unexpected kind of function template
> definition"
> *** Check failure stack trace: ***
> @  0x6094c4a  __assert_fail
> @  0x2705bfe  clang::Sema::InstantiateFunctionDefinition()
> @  0x2c1fb13  clang::Sema::MarkFunctionReferenced()
> @  0x2bec07b  clang::Sema::MarkAnyDeclReferenced()
> @  0x2c2327f  MarkExprReferenced()
> @  0x2be8f0a  clang::Sema::MarkDeclRefReferenced()
> @  0x2980ac0  clang::Sema::FixOverloadedFunctionReference()
> @  0x2982e66  FinishOverloadedCallExpr()
> @  0x2982b39  clang::Sema::BuildOverloadedCallExpr()
> @  0x2be461b  clang::Sema::ActOnCallExpr()
> @  0x2571e90  clang::Parser::ParsePostfixExpressionSuffix()
> @  0x25784cb  clang::Parser::ParseCastExpression()
> @  0x2570865  clang::Parser::ParseCastExpression()
> @  0x256f1e3  clang::Parser::ParseAssignmentExpression()
> @  0x256f0bf  clang::Parser::ParseExpression()
> @  0x2517eeb  clang::Parser::ParseExprStatement()
> @  0x2517074  clang::Parser::ParseStatementOrDeclarationAft
> erAttributes()
> @  0x2516b50  clang::Parser::ParseStatementOrDeclaration()
> @  0x251deb4  clang::Parser::ParseCompoundStatementBody()
> @  0x251ea53  clang::Parser::ParseFunctionStatementBody()
> @  0x24f5b23  clang::Parser::ParseFunctionDefinition()
> @  0x25082a5  clang::Parser::ParseSingleDeclarationAfterTem
> plate()
> @  0x2507652  clang::Parser::ParseTemplateDeclarationOrSpec
> ialization()
> @  0x2506fa5  clang::Parser::ParseDeclarationStartingWithTe
> mplate()
> @  0x25b6853  clang::Parser::ParseDeclaration()
> @  0x24f36d5  clang::Parser::ParseExternalDeclaration()
> @  0x24f2739  clang::Parser::ParseTopLevelDecl()
> @  0x24f220e  clang::Parser::ParseFirstTopLevelDecl()
> @  0x24ed582  clang::ParseAST()
>
> On Wed, Jun 21, 2017 at 2:46 PM, Serge Pavlov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: sepavloff
>> Date: Wed Jun 21 07:46:57 2017
>> New Revision: 305903
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=305903&view=rev
>> Log:
>> Function with unparsed body is a definition
>>
>> While a function body is being parsed, the function declaration is not
>> considered
>> as a definition because it does not have a body yet. In some cases it
>> leads to
>> incorrect interpretation, the case is presented in
>> https://bugs.llvm.org/show_bug.cgi?id=14785:
>> ```
>> template struct Somewhat {
>>   void internal() const {}
>>   friend void operator+(int const &, Somewhat const &) {}
>> };
>> void operator+(int const &, Somewhat const &x) { x.internal(); }
>> ```
>> When statement `x.internal()` in the body of global `operator+` is
>> parsed, the type
>> of `x` must be completed, so the instantiation of `Somewhat` is
>> started. It
>> instantiates the declaration of `operator+` defined inline, and makes a
>> check for
>> redefinition. The check does not detect another definition because the
>> declaration
>> of `operator+` is still not defining as does not have a body yet.
>>
>> To solves this problem the function `isThisDeclarationADefinition`
>> considers
>> a function declaration as a definition if it has flag `WillHaveBody` set.
>>
>> This change fixes PR14785.
>>
>> Differential Revision: https://reviews.llvm.org/D30375
>>
>> This is a recommit of 305379, reverted in 305381, with small changes.
>>
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/lib/Sema/SemaCUDA.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> cfe/trunk/test/SemaCXX/friend2.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> AST/Decl.h?rev=305903&r1=305902&r2=305903&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Wed Jun 21 07:46:57 2017
>> @@ -1874,7 +1874,7 @@ public:
>>///
>>bool isTh

[PATCH] D35925: [Coverage] Precise region termination with deferred regions

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks, it does make sense to update llvm-cov.

LGTM:




Comment at: lib/CodeGen/CoverageMappingGen.cpp:554
+  // useful to try and create a deferred region inside of one.
+  UpdateDeferredRegion &= SM.getFileID(EndLoc) == SM.getMainFileID();
+

Might be better to use `&&` to avoid extra work.



Comment at: lib/CodeGen/CoverageMappingGen.cpp:561
+  } else {
+if (Region.isDeferred()) {
+  assert(!ParentOfDeferredRegion && "Consecutive deferred regions");

You can use `else if` here.


https://reviews.llvm.org/D35925



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


[PATCH] D36083: [utils] Add a script that runs clang in LLDB and stops it when a specified diagnostic is emitted

2017-08-01 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

This is a good example of how to script lldb, but it's predicated on knowing 
the diag name, which is great if you know the name.

However, this isn't my use case.  I don't have the diag name, just a diagnostic 
message.  In order to get the diag name associated with a specific diagnostic 
message, I have to grep the source, which was the original motivation behind 
https://reviews.llvm.org/D35175.

Here's how I currently do it:

1. select a partial substring from the diagnostic (omitting variable/class 
names and anything that might be part of a %select{}, e.g., 
(public|private|protected), etc...)
2. use grep to match a diagnostic definition in one of the diagnostic inc files 
generated by tblgen, i.e., tools/clang/include/clang/Basic/Diagnostic*.inc
3. if one or more matches found, select the correct one(s), otherwise, adjust 
substring and go back to 2
4. pass diag name(s) found in 3 to this tool

However, once the diag name is known, it would be just as easy to find/grep the 
source to find the file/line numbers and where the diag name is seen.  Then you 
could either look directly at the source, or use them to set breakpoints in 
lldb.  This avoids issues concerning late calls to report and PartialDiagnostic 
locations.

Alternatively, one could do what John suggested (paraphrasing here) and munge 
the strings found in tools/clang/include/clang/Basic/Diagnostic*.inc to create 
regular expressions and use flex to generate a lexer, or write one by hand, 
that could find a specific diag name that matched the diagnostic message.  
(obviously there are a lot of ways to do this)


Repository:
  rL LLVM

https://reviews.llvm.org/D36083



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


[PATCH] D35925: [Coverage] Precise region termination with deferred regions

2017-08-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 109142.
vsk marked 2 inline comments as done.
vsk edited the summary of this revision.
vsk added a comment.

Thanks for the review! I'll hold off on landing this until the llvm-cov changes 
are in, so that people don't hit the issue where unexpected line execution 
counts are displayed.


https://reviews.llvm.org/D35925

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/deferred-region.cpp
  test/CoverageMapping/label.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/return.c
  test/CoverageMapping/switch.cpp
  test/CoverageMapping/switchmacro.c
  test/CoverageMapping/trycatch.cpp

Index: test/CoverageMapping/trycatch.cpp
===
--- test/CoverageMapping/trycatch.cpp
+++ test/CoverageMapping/trycatch.cpp
@@ -18,7 +18,7 @@
   // CHECK-NEXT: File 0, [[@LINE+1]]:10 -> [[@LINE+2]]:27 = (#0 - #1)
   } else if(i == 8)   // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:19 = (#0 - #1)
 throw ImportantError();   // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:27 = #2
-}
+} // CHECK-NEXT: File 0, [[@LINE-1]]:27 -> [[@LINE]]:2 = ((#0 - #1) - #2)
 
   // CHECK-NEXT: main
 int main() {  // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0
Index: test/CoverageMapping/switchmacro.c
===
--- test/CoverageMapping/switchmacro.c
+++ test/CoverageMapping/switchmacro.c
@@ -8,6 +8,7 @@
   default:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> {{[0-9]+}}:11 = #2
 if (i == 1)  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:15 = #2
   return 0;  // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = #3
+ // CHECK-NEXT: File 0, [[@LINE-1]]:15 -> [[@LINE+3]]:5 = (#2 - #3)
 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:5 -> [[@LINE+2]]:8 = (#2 - #3) (Expanded file = 1)
 // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> {{[0-9]+}}:11 = (#2 - #3)
 FOO(1);
Index: test/CoverageMapping/switch.cpp
===
--- test/CoverageMapping/switch.cpp
+++ test/CoverageMapping/switch.cpp
@@ -6,7 +6,7 @@
   case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #2
 return;
   case 2:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3
-break;
+break;  // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+2]]:3 = #1
   }
   int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1
 }
@@ -55,16 +55,16 @@
 i = 2;
 break;
   default:  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4
-break;
+break;  // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+2]]:3 = #1
   }
   switch(i) {   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1
   case 0:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6
 i = 1;
 break;
   case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #7
 i = 2;
   default:  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = (#7 + #8)
-break;
+break;  // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+3]]:3 = #5
   }
 
   switch(i) {   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5
Index: test/CoverageMapping/return.c
===
--- test/CoverageMapping/return.c
+++ test/CoverageMapping/return.c
@@ -13,7 +13,7 @@
   for(int i = 0; i < 10; ++i) { // CHECK-NEXT: File 0, [[@LINE]]:31 -> {{[0-9]+}}:4 = #1
 // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> [[@LINE+1]]:13 = #1
 if(i > 2) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+2]]:6 = #2
-  return;
+  return;   // CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+3]]:5 = (#1 - #2)
 }   // CHECK-NEXT: File 0, [[@LINE+2]]:5 -> {{[0-9]+}}:4 = (#1 - #2)
 // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> [[@LINE+1]]:14 = (#1 - #2)
 if(i == 3) {// CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE+2]]:6 = #3
Index: test/CoverageMapping/moremacros.c
===
--- test/CoverageMapping/moremacros.c
+++ test/CoverageMapping/moremacros.c
@@ -15,23 +15,23 @@
   if (!argc) LBRAC
 return 0;
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #2
-  RBRAC
+  RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+6]]:3 = (#0 - #2)
 
   // CHECK-NEXT: File 0, [[@LINE+4]]:3 -> [[@LINE+15]]:2 = (#0 - #2)
   // CHECK-NEXT: File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:12 = (#0 - #2)
   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:19 = #3
   // CHECK-NEXT: File 0, [[@LINE+1]]:19 -> [[@LINE+3]]:4 = #3
   if (!argc) LBRAC
 return 0;
- 

[PATCH] D36159: clang-format: [JS] handle single lines comments ending in `\\`.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

Previously, clang-format would consider the following code line to be part of
the comment and incorrectly format the rest of the file.


https://reviews.llvm.org/D36159

Files:
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2038,5 +2038,27 @@
"};", FourSpaces);
 }
 
+TEST_F(FormatTestJS, BackslashesInComments) {
+  verifyFormat("// hello \\\n"
+   "if (x) foo();\n",
+   "// hello \\\n"
+   " if ( x) \n"
+   "   foo();\n");
+  verifyFormat("/* ignore \\\n"
+   " */\n"
+   "if (x) foo();\n",
+   "/* ignore \\\n"
+   " */\n"
+   " if (  x) foo();\n");
+  verifyFormat("// st \\ art\\\n"
+   "// comment"
+   "// continue \\\n"
+   "formatMe();\n",
+   "// st \\ art\\\n"
+   "// comment"
+   "// continue \\\n"
+   "formatMe( );\n");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -529,6 +529,34 @@
 readRawToken(*FormatTok);
   }
 
+  // JavaScript and Java do not allow to escape the end of the line with a
+  // backslash. Backslashes are syntax errors in plain source, but can occur in
+  // comments. When a single line comment ends with a \, it'll cause the next
+  // line of code to be lexed as a comment, breaking formatting. The code below
+  // finds comments that contain a backslash followed by a line break, 
truncates
+  // the comment token at the backslash, and resets the lexer to restart behind
+  // the backslash.
+  if ((Style.Language == FormatStyle::LK_JavaScript ||
+   Style.Language == FormatStyle::LK_Java) &&
+  FormatTok->is(tok::comment) && FormatTok->TokenText.startswith("//")) {
+size_t BackslashPos = FormatTok->TokenText.find('\\');
+while (BackslashPos != StringRef::npos) {
+  if (BackslashPos + 1 < FormatTok->TokenText.size() &&
+  FormatTok->TokenText[BackslashPos + 1] == '\n') {
+const char *Offset = Lex->getBufferLocation();
+Offset -= FormatTok->TokenText.size();
+Offset += BackslashPos + 1;
+resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
+FormatTok->TokenText = FormatTok->TokenText.substr(0, BackslashPos + 
1);
+FormatTok->ColumnWidth = encoding::columnWidthWithTabs(
+FormatTok->TokenText, FormatTok->OriginalColumn, Style.TabWidth,
+Encoding);
+break;
+  }
+  BackslashPos = FormatTok->TokenText.find('\\', BackslashPos + 1);
+}
+  }
+
   // In case the token starts with escaped newlines, we want to
   // take them into account as whitespace - this pattern is quite frequent
   // in macro definitions.


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2038,5 +2038,27 @@
"};", FourSpaces);
 }
 
+TEST_F(FormatTestJS, BackslashesInComments) {
+  verifyFormat("// hello \\\n"
+   "if (x) foo();\n",
+   "// hello \\\n"
+   " if ( x) \n"
+   "   foo();\n");
+  verifyFormat("/* ignore \\\n"
+   " */\n"
+   "if (x) foo();\n",
+   "/* ignore \\\n"
+   " */\n"
+   " if (  x) foo();\n");
+  verifyFormat("// st \\ art\\\n"
+   "// comment"
+   "// continue \\\n"
+   "formatMe();\n",
+   "// st \\ art\\\n"
+   "// comment"
+   "// continue \\\n"
+   "formatMe( );\n");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -529,6 +529,34 @@
 readRawToken(*FormatTok);
   }
 
+  // JavaScript and Java do not allow to escape the end of the line with a
+  // backslash. Backslashes are syntax errors in plain source, but can occur in
+  // comments. When a single line comment ends with a \, it'll cause the next
+  // line of code to be lexed as a comment, breaking formatting. The code below
+  // finds comments that contain a backslash followed by a line break, truncates
+  // the comment token at the backslash, and resets the lexer to restart behind
+  // the backslash.
+  if ((Style.Language == FormatStyle::LK_JavaScript ||
+   Style.Language == FormatSty

[PATCH] D35817: Ban implicit _Complex to scalar conversions in C++

2017-08-01 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover updated this revision to Diff 109149.
t.p.northover added a comment.

Sounds like an improvement, I've updated the diff.


https://reviews.llvm.org/D35817

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/stmtexpr.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp
  clang/test/OpenMP/atomic_update_codegen.cpp
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/complex-overload.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  clang/test/SemaCXX/warn-absolute-value.cpp

Index: clang/test/SemaCXX/warn-absolute-value.cpp
===
--- clang/test/SemaCXX/warn-absolute-value.cpp
+++ clang/test/SemaCXX/warn-absolute-value.cpp
@@ -448,126 +448,23 @@
 }
 
 void test_complex_float(_Complex float x) {
-  (void)abs(x);
-  // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabsf"
-  (void)labs(x);
-  // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)llabs(x);
-  // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
-  (void)fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-  (void)fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
   (void)cabsf(x);
   (void)cabs(x);
   (void)cabsl(x);
 
-  (void)__builtin_abs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabsf"
-  (void)__builtin_labs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_llabs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-
-  (void)__builtin_fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-  (void)__builtin_fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-
   (void)__builtin_cabsf(x);
   (void)__builtin_cabs(x);
   (void)__builtin_cabsl(x);
 }
 
 void test_complex_double(_Complex double x) {
-  (void)abs(x);
-  // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabs' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabs"
-  (void)labs(x);
-  // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabs' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabs"
-  (void)llabs(x);
-  // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}}
- 

r309703 - clang-format: [JS] consistenly format enums.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 10:12:15 2017
New Revision: 309703

URL: http://llvm.org/viewvc/llvm-project?rev=309703&view=rev
Log:
clang-format: [JS] consistenly format enums.

Summary: Previously, const enums would get formatted differently because the 
modifier was not recognized.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309703&r1=309702&r2=309703&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:12:15 2017
@@ -2517,7 +2517,9 @@ bool TokenAnnotator::mustBreakBefore(con
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_export, tok::kw_enum)))
+ Line.startsWith(tok::kw_const, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
   // JavaScript top-level enum key/value pairs are put on separate lines
   // instead of bin-packing.
   return true;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309703&r1=309702&r2=309703&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:12:15 2017
@@ -1425,6 +1425,14 @@ TEST_F(FormatTestJS, EnumDeclarations) {
"  B\n"
"}\n"
"var x = 1;");
+  verifyFormat("const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
+  verifyFormat("export const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {


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


[PATCH] D36144: clang-format: [JS] consistenly format enums.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309703: clang-format: [JS] consistenly format enums. 
(authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36144

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2517,7 +2517,9 @@
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_export, tok::kw_enum)))
+ Line.startsWith(tok::kw_const, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
   // JavaScript top-level enum key/value pairs are put on separate lines
   // instead of bin-packing.
   return true;
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1425,6 +1425,14 @@
"  B\n"
"}\n"
"var x = 1;");
+  verifyFormat("const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
+  verifyFormat("export const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2517,7 +2517,9 @@
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_export, tok::kw_enum)))
+ Line.startsWith(tok::kw_const, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_enum) ||
+ Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
   // JavaScript top-level enum key/value pairs are put on separate lines
   // instead of bin-packing.
   return true;
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1425,6 +1425,14 @@
"  B\n"
"}\n"
"var x = 1;");
+  verifyFormat("const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
+  verifyFormat("export const enum Foo {\n"
+   "  A = 1,\n"
+   "  B\n"
+   "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r309705 - [clangd] Fixed MSVC compilation failures.

2017-08-01 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug  1 10:17:37 2017
New Revision: 309705

URL: http://llvm.org/viewvc/llvm-project?rev=309705&view=rev
Log:
[clangd] Fixed MSVC compilation failures.

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.h

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=309705&r1=309704&r2=309705&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue Aug  1 10:17:37 2017
@@ -104,6 +104,10 @@ private:
 // Provides thread-safe access to ParsedAST.
 class ParsedASTWrapper {
 public:
+  // MSVC does not allow to use types without default constructor in
+  // std::promise<> template arguments.
+  ParsedASTWrapper() = default;
+
   ParsedASTWrapper(ParsedASTWrapper &&Wrapper);
   ParsedASTWrapper(llvm::Optional AST);
 


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


r309707 - clang-format: [JS] handle union types in arrow functions.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 10:19:32 2017
New Revision: 309707

URL: http://llvm.org/viewvc/llvm-project?rev=309707&view=rev
Log:
clang-format: [JS] handle union types in arrow functions.

Summary: clang-format would previously fail to detect that an arrow functions 
parameter block is not an expression, and thus insert whitespace around the `|` 
and `&` type operators in it.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309707&r1=309706&r2=309707&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:19:32 2017
@@ -533,6 +533,7 @@ private:
 Contexts.back().ContextKind == tok::l_square || // array type
 (Contexts.size() == 1 &&
  Line.MustBeDeclaration)) { // method/property declaration
+  Contexts.back().IsExpression = false;
   Tok->Type = TT_JsTypeColon;
   break;
 }

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309707&r1=309706&r2=309707&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:19:32 2017
@@ -988,6 +988,9 @@ TEST_F(FormatTestJS, ArrowFunctions) {
".doSomethingElse(\n"
"// break\n"
");");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+   "  return x;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {


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


[PATCH] D36147: clang-format: [JS] handle union types in arrow functions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309707: clang-format: [JS] handle union types in arrow 
functions. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36147

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -533,6 +533,7 @@
 Contexts.back().ContextKind == tok::l_square || // array type
 (Contexts.size() == 1 &&
  Line.MustBeDeclaration)) { // method/property declaration
+  Contexts.back().IsExpression = false;
   Tok->Type = TT_JsTypeColon;
   break;
 }
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -988,6 +988,9 @@
".doSomethingElse(\n"
"// break\n"
");");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+   "  return x;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -533,6 +533,7 @@
 Contexts.back().ContextKind == tok::l_square || // array type
 (Contexts.size() == 1 &&
  Line.MustBeDeclaration)) { // method/property declaration
+  Contexts.back().IsExpression = false;
   Tok->Type = TT_JsTypeColon;
   break;
 }
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -988,6 +988,9 @@
".doSomethingElse(\n"
"// break\n"
");");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+   "  return x;\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309710 - clang-format: [JS] whitespace between keywords and parenthesized expressions.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 10:22:15 2017
New Revision: 309710

URL: http://llvm.org/viewvc/llvm-project?rev=309710&view=rev
Log:
clang-format: [JS] whitespace between keywords and parenthesized expressions.

Summary: `throw (...)` should have a whitespace following it, as do await and 
void.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309710&r1=309709&r2=309710&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:22:15 2017
@@ -2349,6 +2349,9 @@ bool TokenAnnotator::spaceRequiredBefore
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+if (Right.is(tok::l_paren) &&
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+  return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309710&r1=309709&r2=309710&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:22:15 2017
@@ -259,6 +259,15 @@ TEST_F(FormatTestJS, ReservedWordsMethod
   "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+   "await (await x).y;\n"
+   "void (0);\n"
+   "delete (x.y);\n"
+   "return (x);\n");
+}
+
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");


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


[PATCH] D36146: clang-format: [JS] whitespace between keywords and parenthesized expressions.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309710: clang-format: [JS] whitespace between keywords and 
parenthesized expressions. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36146

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2349,6 +2349,9 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+if (Right.is(tok::l_paren) &&
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+  return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -259,6 +259,15 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+   "await (await x).y;\n"
+   "void (0);\n"
+   "delete (x.y);\n"
+   "return (x);\n");
+}
+
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2349,6 +2349,9 @@
 if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
 Left.Tok.getIdentifierInfo())
   return false;
+if (Right.is(tok::l_paren) &&
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+  return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -259,6 +259,15 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+   "await (await x).y;\n"
+   "void (0);\n"
+   "delete (x.y);\n"
+   "return (x);\n");
+}
+
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-01 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

High-level comment from the peanut gallery:

The word "occurrences" is horrible to type and most people misspell it (you did 
great here!) Would you consider something like "SymbolMatches" or even 
"SymbolHits"?


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


r309712 - clang-format: [JS] prefer wrapping chains over empty literals.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 10:35:57 2017
New Revision: 309712

URL: http://llvm.org/viewvc/llvm-project?rev=309712&view=rev
Log:
clang-format: [JS] prefer wrapping chains over empty literals.

Summary:
E.g. don't wrap like this:

(foo.bar.baz).and.bam(Blah.of({
}))

But rather:

(foo.bar.baz)
.and.bam(Blah.of({}))

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309712&r1=309711&r2=309712&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:35:57 2017
@@ -2006,6 +2006,9 @@ unsigned TokenAnnotator::splitPenalty(co
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return 100;
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if (Left.opensScope() && Right.closesScope())
+  return 200;
   }
 
   if (Right.is(tok::identifier) && Right.Next && 
Right.Next->is(TT_DictLiteral))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309712&r1=309711&r2=309712&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:35:57 2017
@@ -841,6 +841,15 @@ TEST_F(FormatTestJS, FunctionLiterals) {
 
 }
 
+TEST_F(FormatTestJS, DontWrapEmptyLiterals) {
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of([]));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of({}));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of(()));");
+}
+
 TEST_F(FormatTestJS, InliningFunctionLiterals) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;


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


[PATCH] D36139: clang-format: [JS] prefer wrapping chains over empty literals.

2017-08-01 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309712: clang-format: [JS] prefer wrapping chains over empty 
literals. (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D36139?vs=109082&id=109155#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36139

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2006,6 +2006,9 @@
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return 100;
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if (Left.opensScope() && Right.closesScope())
+  return 200;
   }
 
   if (Right.is(tok::identifier) && Right.Next && 
Right.Next->is(TT_DictLiteral))
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -841,6 +841,15 @@
 
 }
 
+TEST_F(FormatTestJS, DontWrapEmptyLiterals) {
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of([]));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of({}));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of(()));");
+}
+
 TEST_F(FormatTestJS, InliningFunctionLiterals) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2006,6 +2006,9 @@
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return 100;
+// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
+if (Left.opensScope() && Right.closesScope())
+  return 200;
   }
 
   if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -841,6 +841,15 @@
 
 }
 
+TEST_F(FormatTestJS, DontWrapEmptyLiterals) {
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of([]));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of({}));");
+  verifyFormat("(a.getData as jasmine.Spy)\n"
+   ".and.returnValue(Observable.of(()));");
+}
+
 TEST_F(FormatTestJS, InliningFunctionLiterals) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309713 - clang-format: [JS] no whitespace between typeof operator and l_paren.

2017-08-01 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Aug  1 10:42:16 2017
New Revision: 309713

URL: http://llvm.org/viewvc/llvm-project?rev=309713&view=rev
Log:
clang-format: [JS] no whitespace between typeof operator and l_paren.

Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=309713&r1=309712&r2=309713&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Aug  1 10:42:16 2017
@@ -644,6 +644,7 @@ struct AdditionalKeywords {
 kw_readonly = &IdentTable.get("readonly");
 kw_set = &IdentTable.get("set");
 kw_type = &IdentTable.get("type");
+kw_typeof = &IdentTable.get("typeof");
 kw_var = &IdentTable.get("var");
 kw_yield = &IdentTable.get("yield");
 
@@ -680,7 +681,7 @@ struct AdditionalKeywords {
 JsExtraKeywords = std::unordered_set(
 {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
  kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
- kw_set, kw_type, kw_var, kw_yield,
+ kw_set, kw_type, kw_typeof, kw_var, kw_yield,
  // Keywords from the Java section.
  kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
   }
@@ -714,6 +715,7 @@ struct AdditionalKeywords {
   IdentifierInfo *kw_readonly;
   IdentifierInfo *kw_set;
   IdentifierInfo *kw_type;
+  IdentifierInfo *kw_typeof;
   IdentifierInfo *kw_var;
   IdentifierInfo *kw_yield;
 

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=309713&r1=309712&r2=309713&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:42:16 2017
@@ -2353,7 +2353,7 @@ bool TokenAnnotator::spaceRequiredBefore
 Left.Tok.getIdentifierInfo())
   return false;
 if (Right.is(tok::l_paren) &&
-Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof, 
tok::kw_void))
   return true;
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309713&r1=309712&r2=309713&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:42:16 2017
@@ -263,6 +263,7 @@ TEST_F(FormatTestJS, ReservedWordsParent
   // All of these are statements using the keyword, not function calls.
   verifyFormat("throw (x + y);\n"
"await (await x).y;\n"
+   "typeof (x) === 'string';\n"
"void (0);\n"
"delete (x.y);\n"
"return (x);\n");


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


[PATCH] D36083: [utils] Add a script that runs clang in LLDB and stops it when a specified diagnostic is emitted

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Makes sense. I'll see if I can get somewhere with the regex idea.


Repository:
  rL LLVM

https://reviews.llvm.org/D36083



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


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-01 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D36156#827733, @kimgr wrote:

> High-level comment from the peanut gallery:
>
> The word "occurrences" is horrible to type and most people misspell it (you 
> did great here!) Would you consider something like "SymbolMatches" or even 
> "SymbolHits"?


Sure, it would be reasonable to change it something easier, as long as it's 
still descriptive. "SymbolMatches" could work, although I think I'd prefer 
something a bit more descriptive. What about "SymbolReference"/"References"?


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


[clang-tools-extra] r309720 - [clangd] Fix more MSVC compilation failures.

2017-08-01 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug  1 11:27:58 2017
New Revision: 309720

URL: http://llvm.org/viewvc/llvm-project?rev=309720&view=rev
Log:
[clangd] Fix more MSVC compilation failures.

It turns out MSVC does not allow non-copyable classes in std::future
and std::promise template arguments.

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=309720&r1=309719&r2=309720&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Aug  1 11:27:58 2017
@@ -275,7 +275,7 @@ std::string ClangdServer::dumpAST(PathRe
   assert(Resources && "dumpAST is called for non-added document");
 
   std::string Result;
-  Resources->getAST().get().runUnderLock([&Result](ParsedAST *AST) {
+  Resources->getAST().get()->runUnderLock([&Result](ParsedAST *AST) {
 llvm::raw_string_ostream ResultOS(Result);
 if (AST) {
   clangd::dumpAST(*AST, ResultOS);
@@ -299,7 +299,7 @@ Tagged> ClangdServ
   assert(Resources && "Calling findDefinitions on non-added file");
 
   std::vector Result;
-  Resources->getAST().get().runUnderLock([Pos, &Result](ParsedAST *AST) {
+  Resources->getAST().get()->runUnderLock([Pos, &Result](ParsedAST *AST) {
 if (!AST)
   return;
 Result = clangd::findDefinitions(*AST, Pos);

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=309720&r1=309719&r2=309720&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Aug  1 11:27:58 2017
@@ -707,7 +707,7 @@ CppFile::CppFile(PathRef FileName, tooli
   PreamblePromise.set_value(nullptr);
   PreambleFuture = PreamblePromise.get_future();
 
-  ASTPromise.set_value(ParsedASTWrapper(llvm::None));
+  ASTPromise.set_value(std::make_shared(llvm::None));
   ASTFuture = ASTPromise.get_future();
 }
 
@@ -722,7 +722,7 @@ void CppFile::cancelRebuilds() {
 PreambleFuture = PreamblePromise.get_future();
   }
   if (futureIsReady(ASTFuture)) {
-ASTPromise = std::promise();
+ASTPromise = std::promise>();
 ASTFuture = ASTPromise.get_future();
   }
   // Now wait for rebuild to finish.
@@ -730,7 +730,7 @@ void CppFile::cancelRebuilds() {
 
   // Return empty results for futures.
   PreamblePromise.set_value(nullptr);
-  ASTPromise.set_value(ParsedASTWrapper(llvm::None));
+  ASTPromise.set_value(std::make_shared(llvm::None));
 }
 
 llvm::Optional>
@@ -763,7 +763,7 @@ CppFile::deferRebuild(StringRef NewConte
   this->PreambleFuture = this->PreamblePromise.get_future();
 }
 if (futureIsReady(this->ASTFuture)) {
-  this->ASTPromise = std::promise();
+  this->ASTPromise = std::promise>();
   this->ASTFuture = this->ASTPromise.get_future();
 }
   } // unlock Mutex.
@@ -878,7 +878,7 @@ CppFile::deferRebuild(StringRef NewConte
 return Diagnostics; // Our rebuild request was cancelled, don't set
 // ASTPromise.
 
-  That->ASTPromise.set_value(ParsedASTWrapper(std::move(NewAST)));
+  
That->ASTPromise.set_value(std::make_shared(std::move(NewAST)));
 } // unlock Mutex
 
 return Diagnostics;
@@ -898,7 +898,7 @@ std::shared_ptr CppF
   return LatestAvailablePreamble;
 }
 
-std::shared_future CppFile::getAST() const {
+std::shared_future> CppFile::getAST() const {
   std::lock_guard Lock(Mutex);
   return ASTFuture;
 }

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=309720&r1=309719&r2=309720&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue Aug  1 11:27:58 2017
@@ -104,10 +104,6 @@ private:
 // Provides thread-safe access to ParsedAST.
 class ParsedASTWrapper {
 public:
-  // MSVC does not allow to use types without default constructor in
-  // std::promise<> template arguments.
-  ParsedASTWrapper() = default;
-
   ParsedASTWrapper(ParsedASTWrapper &&Wrapper);
   ParsedASTWrapper(llvm::Optional AST);
 
@@ -192,7 +188,10 @@ public:
 
   /// Returns a future to get the most fresh AST for a file. Returned AST is
   /// wrapped to prevent concurrent accesses.
-  std::shared_future getAST() const;
+  /// We use std::shared_ptr here because MVSC fails to compile non-copyable
+  /// classes as template arguments of promise/future. It is guaranteed to
+  /// always be non-null.
+  std::shared_future> getAST()

[PATCH] D35020: [Modules] Add ability to specify module name to module file mapping

2017-08-01 Thread Boris Kolpackov via Phabricator via cfe-commits
boris added a comment.

Ping.


https://reviews.llvm.org/D35020



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


[PATCH] D36122: Thread Safety Analysis: fix assert_capability.

2017-08-01 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley accepted this revision.
delesley added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D36122



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


r309722 - [Sema] Fix lax conversion between non ext vectors

2017-08-01 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Aug  1 12:05:25 2017
New Revision: 309722

URL: http://llvm.org/viewvc/llvm-project?rev=309722&view=rev
Log:
[Sema] Fix lax conversion between non ext vectors

r282968 introduced a regression due to the lack of proper testing.
Re-add lax conversion support between non ext vectors for compound
assignments and add a test for that.

rdar://problem/28639467

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/vector-cast.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=309722&r1=309721&r2=309722&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Aug  1 12:05:25 2017
@@ -8288,7 +8288,7 @@ QualType Sema::CheckVectorOperands(ExprR
 // type. Note that this is already done by non-compound assignments in
 // CheckAssignmentConstraints. If it's a scalar type, only bitcast for
 // <1 x T> -> T. The result is also a vector type.
-} else if (OtherType->isExtVectorType() ||
+} else if (OtherType->isExtVectorType() || OtherType->isVectorType() ||
(OtherType->isScalarType() && VT->getNumElements() == 1)) {
   ExprResult *RHSExpr = &RHS;
   *RHSExpr = ImpCastExprToType(RHSExpr->get(), LHSType, CK_BitCast);

Modified: cfe/trunk/test/Sema/vector-cast.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-cast.c?rev=309722&r1=309721&r2=309722&view=diff
==
--- cfe/trunk/test/Sema/vector-cast.c (original)
+++ cfe/trunk/test/Sema/vector-cast.c Tue Aug  1 12:05:25 2017
@@ -48,6 +48,9 @@ typedef float float2 __attribute__ ((vec
 typedef __attribute__((vector_size(8))) double float64x1_t;
 typedef __attribute__((vector_size(16))) double float64x2_t;
 float64x1_t vget_low_f64(float64x2_t __p0);
+typedef float float16 __attribute__((__vector_size__(16)));
+typedef signed int vSInt32 __attribute__((__vector_size__(16)));
+typedef unsigned int vUInt32 __attribute__((__vector_size__(16)));
 
 void f4() {
   float2 f2;
@@ -73,3 +76,8 @@ void f5() {
   v = ptr; // expected-error-re {{assigning to 'short_sizeof_pointer' (vector 
of {{[0-9]+}} 'short' values) from incompatible type 'void *'}}
   ptr = v; // expected-error {{assigning to 'void *' from incompatible type 
'short_sizeof_pointer'}}
 }
+
+void f6(vSInt32 a0) {
+  vUInt32 counter = (float16){0.0f, 0.0f, 0.0f, 0.0f}; // expected-warning 
{{incompatible vector types initializing 'vUInt32' (vector of 4 'unsigned int' 
values) with an expression of type 'float16' (vector of 4 'float' values)}}
+  counter -= a0;
+}


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


r309724 - [CMake] Include sancov tool in Fuchsia toolchain

2017-08-01 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Aug  1 12:15:32 2017
New Revision: 309724

URL: http://llvm.org/viewvc/llvm-project?rev=309724&view=rev
Log:
[CMake] Include sancov tool in Fuchsia toolchain

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

Modified:
cfe/trunk/cmake/caches/Fuchsia-stage2.cmake

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=309724&r1=309723&r2=309724&view=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Tue Aug  1 12:15:32 2017
@@ -68,6 +68,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-size
   llvm-symbolizer
   opt
+  sancov
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS


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


[PATCH] D35930: [CMake] Include sancov tool in Fuchsia toolchain

2017-08-01 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309724: [CMake] Include sancov tool in Fuchsia toolchain 
(authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D35930?vs=108418&id=109173#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35930

Files:
  cfe/trunk/cmake/caches/Fuchsia-stage2.cmake


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -68,6 +68,7 @@
   llvm-size
   llvm-symbolizer
   opt
+  sancov
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -68,6 +68,7 @@
   llvm-size
   llvm-symbolizer
   opt
+  sancov
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309725 - Thread Safety Analysis: fix assert_capability.

2017-08-01 Thread Josh Gao via cfe-commits
Author: jmgao
Date: Tue Aug  1 12:18:05 2017
New Revision: 309725

URL: http://llvm.org/viewvc/llvm-project?rev=309725&view=rev
Log:
Thread Safety Analysis: fix assert_capability.

Summary:
Previously, the assert_capability attribute was completely ignored by
thread safety analysis.

Reviewers: delesley, rnk

Reviewed By: delesley

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=309725&r1=309724&r2=309725&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Aug  1 12:18:05 2017
@@ -2138,7 +2138,7 @@ def AssertCapability : InheritableAttr {
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let DuplicatesAllowedWhileMerging = 1;
-  let Args = [ExprArgument<"Expr">];
+  let Args = [VariadicExprArgument<"Args">];
   let Accessors = [Accessor<"isShared",
 [GNU<"assert_shared_capability">,
  CXX11<"clang", "assert_shared_capability">]>];

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=309725&r1=309724&r2=309725&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Tue Aug  1 12:18:05 2017
@@ -1735,8 +1735,23 @@ void BuildLockset::handleCall(Expr *Exp,
 CapExprSet AssertLocks;
 Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD);
 for (const auto &AssertLock : AssertLocks)
-  Analyzer->addLock(FSet, llvm::make_unique(
-  AssertLock, LK_Shared, Loc, false, true),
+  Analyzer->addLock(FSet,
+llvm::make_unique(
+AssertLock, LK_Shared, Loc, false, true),
+ClassifyDiagnostic(A));
+break;
+  }
+
+  case attr::AssertCapability: {
+AssertCapabilityAttr *A = cast(At);
+CapExprSet AssertLocks;
+Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD);
+for (const auto &AssertLock : AssertLocks)
+  Analyzer->addLock(FSet,
+llvm::make_unique(
+AssertLock,
+A->isShared() ? LK_Shared : LK_Exclusive, Loc,
+false, true),
 ClassifyDiagnostic(A));
 break;
   }

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=309725&r1=309724&r2=309725&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Aug  1 12:18:05 2017
@@ -5686,8 +5686,12 @@ static void handleCapabilityAttr(Sema &S
 
 static void handleAssertCapabilityAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
+  SmallVector Args;
+  if (!checkLockFunAttrCommon(S, D, Attr, Args))
+return;
+
   D->addAttr(::new (S.Context) AssertCapabilityAttr(Attr.getRange(), S.Context,
-Attr.getArgAsExpr(0),
+Args.data(), Args.size(),
 Attr.getAttributeSpellingListIndex()));
 }
 

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=309725&r1=309724&r2=309725&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Aug  1 12:18:05 
2017
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions 
-DUSE_ASSERT_CAPABILITY=0 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions 
-DUSE_ASSERT_CAPABILITY=1 %s
 
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety 
-std=c++11 -Wc++98-compat %s
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety %s

[PATCH] D36122: Thread Safety Analysis: fix assert_capability.

2017-08-01 Thread Josh Gao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309725: Thread Safety Analysis: fix assert_capability. 
(authored by jmgao).

Repository:
  rL LLVM

https://reviews.llvm.org/D36122

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/lib/Analysis/ThreadSafety.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp


Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -5686,8 +5686,12 @@
 
 static void handleAssertCapabilityAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
+  SmallVector Args;
+  if (!checkLockFunAttrCommon(S, D, Attr, Args))
+return;
+
   D->addAttr(::new (S.Context) AssertCapabilityAttr(Attr.getRange(), S.Context,
-Attr.getArgAsExpr(0),
+Args.data(), Args.size(),
 Attr.getAttributeSpellingListIndex()));
 }
 
Index: cfe/trunk/lib/Analysis/ThreadSafety.cpp
===
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp
@@ -1735,8 +1735,23 @@
 CapExprSet AssertLocks;
 Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD);
 for (const auto &AssertLock : AssertLocks)
-  Analyzer->addLock(FSet, llvm::make_unique(
-  AssertLock, LK_Shared, Loc, false, true),
+  Analyzer->addLock(FSet,
+llvm::make_unique(
+AssertLock, LK_Shared, Loc, false, true),
+ClassifyDiagnostic(A));
+break;
+  }
+
+  case attr::AssertCapability: {
+AssertCapabilityAttr *A = cast(At);
+CapExprSet AssertLocks;
+Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD);
+for (const auto &AssertLock : AssertLocks)
+  Analyzer->addLock(FSet,
+llvm::make_unique(
+AssertLock,
+A->isShared() ? LK_Shared : LK_Exclusive, Loc,
+false, true),
 ClassifyDiagnostic(A));
 break;
   }
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -2138,7 +2138,7 @@
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let DuplicatesAllowedWhileMerging = 1;
-  let Args = [ExprArgument<"Expr">];
+  let Args = [VariadicExprArgument<"Args">];
   let Accessors = [Accessor<"isShared",
 [GNU<"assert_shared_capability">,
  CXX11<"clang", "assert_shared_capability">]>];
Index: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions 
-DUSE_ASSERT_CAPABILITY=0 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety 
-Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions 
-DUSE_ASSERT_CAPABILITY=1 %s
 
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety 
-std=c++11 -Wc++98-compat %s
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
@@ -13,8 +14,15 @@
 #define ACQUIRED_BEFORE(...) __attribute__((acquired_before(__VA_ARGS__)))
 #define EXCLUSIVE_LOCK_FUNCTION(...)
__attribute__((exclusive_lock_function(__VA_ARGS__)))
 #define SHARED_LOCK_FUNCTION(...)   
__attribute__((shared_lock_function(__VA_ARGS__)))
+
+#if USE_ASSERT_CAPABILITY
+#define ASSERT_EXCLUSIVE_LOCK(...)  
__attribute__((assert_capability(__VA_ARGS__)))
+#define ASSERT_SHARED_LOCK(...) 
__attribute__((assert_shared_capability(__VA_ARGS__)))
+#else
 #define ASSERT_EXCLUSIVE_LOCK(...)  
__attribute__((assert_exclusive_lock(__VA_ARGS__)))
 #define ASSERT_SHARED_LOCK(...) 
__attribute__((assert_shared_lock(__VA_ARGS__)))
+#endif
+
 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 
__attribute__((exclusive_trylock_function(__VA_ARGS__)))
 #define SHARED_TRYLOCK_FUNCTION(...)
__attribute__((shared_trylock_function(__VA_ARGS__)))
 #define UNLOCK_FUNCTION(...)
__attribute__((unlock_function(__VA_ARGS__)))


Index: cfe/trunk/lib/Sema/SemaDeclAttr.c

[PATCH] D36105: [AArch64] Ignore stdcall and similar on aarch64/windows

2017-08-01 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: lib/Basic/Targets/AArch64.cpp:466-467
+  case CC_X86ThisCall:
+  case CC_X86FastCall:
+  case CC_X86VectorCall:
+return CCCR_Ignore;

mstorsjo wrote:
> rnk wrote:
> > Do they really ignore __fastcall and __vectorcall on arm64?
> > 
> > I assume __thiscall and __stdcall are all over various Win SDK headers, so 
> > they need to be ignored for compatibility, but I've never seen public 
> > documented APIs using __vectorcall. The STL ifdefs out those overloads, 
> > right?
> I don't have MSVC for arm64 to test with (but @mgrang does so he can check), 
> but I included them for consistency and completeness.
@mgrang - can you check whether this compiles without warnings (with e.g. 
`-W3`) on MSVC?

```
void __stdcall foo(void) {
}

void __fastcall bar(void) {
}

void __vectorcall baz(void) {
}
```

@rnk - FWIW, I checked MSVC for ARM (32 bit), and that one also ignores all of 
them without a warning.


https://reviews.llvm.org/D36105



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


[PATCH] D36168: added support for build with dataflow sanitizer

2017-08-01 Thread Farah Hariri via Phabricator via cfe-commits
farahhariri created this revision.
Herald added a subscriber: mgorny.

[libc++] added support for build with dataflow sanitizer


https://reviews.llvm.org/D36168

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -572,6 +572,8 @@
 endif()
 if (LLVM_USE_SANITIZER STREQUAL "Address")
   add_flags("-fsanitize=address")
+elseif (LLVM_USE_SANITIZER MATCHES "Dataflow")
+  add_flags("-fsanitize=dataflow")
 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
   add_flags(-fsanitize=memory)
   if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -572,6 +572,8 @@
 endif()
 if (LLVM_USE_SANITIZER STREQUAL "Address")
   add_flags("-fsanitize=address")
+elseif (LLVM_USE_SANITIZER MATCHES "Dataflow")
+  add_flags("-fsanitize=dataflow")
 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
   add_flags(-fsanitize=memory)
   if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >