[PATCH] D52058: Add Parameters to DW_AT_name Attribute of Template Variables

2018-09-18 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

Generally this looks good, but I'd like for the other to have a look first (at 
this and the other patch) before accepting.




Comment at: lib/CodeGen/CGDebugInfo.cpp:1783
+  if (auto *TS = dyn_cast(VL)) {
+if (TS->getSpecializedTemplateOrPartial()
+.is()) {

Might be nice to add a comment here saying what you're doing in this block and 
below. Looks like the top one is for partial specialization and the bottom one 
for the general case?



Comment at: lib/CodeGen/CGDebugInfo.cpp:1783
+  if (auto *TS = dyn_cast(VL)) {
+if (TS->getSpecializedTemplateOrPartial()
+.is()) {

JDevlieghere wrote:
> Might be nice to add a comment here saying what you're doing in this block 
> and below. Looks like the top one is for partial specialization and the 
> bottom one for the general case?
I also suggest to extract `TS->getSpecializedTemplateOrPartial()` into a 
variable to make this a little less dense.


Repository:
  rC Clang

https://reviews.llvm.org/D52058



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


[PATCH] D52098: [Index] Add an option to collect macros from preprocesor.

2018-09-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: include/clang/Index/IndexingAction.h:59
 /// Recursively indexes \p Decls.
-/// Note that this does not index macros.
-void indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls,
+void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
+ArrayRef Decls,

ioeric wrote:
> ilya-biryukov wrote:
> > It means we won't have the API to index AST without the preprocessor.
> > I don't have a strong opinion on whether this change is fine, our usages 
> > look ok, but not sure if someone has a use-case that might break.
> > 
> > We could take a slightly more backwards-compatible approach, add an 
> > overload without the preprocessor and assert that the 
> > `IndexMacrosInPreprocessor` option is set to false.
> > Not worth the trouble if all the clients want macros, though. WDYT?
> yeah, not sure if it's worth the trouble. In theory, a PP should always be 
> available when AST is available (I hope the index library could enforce 
> somehow). And having two overloads with slightly different behaviors seems 
> worse than unknown backward compatibility.
Agreed, let's see if anyone complains instead of assuming 
backwards-compatibility is a requirement.



Comment at: unittests/Index/IndexTests.cpp:61
+S.Roles = Roles;
+if (MI)
+  S.Info = getSymbolInfoForMacro(*MI);

ioeric wrote:
> ilya-biryukov wrote:
> > Can this actually happen? It seems weird to have a macro occurrence without 
> > a `MacroInfo`.
> > Maybe try asserting that MI is non-null instead?
> this can happen for macros that are #undefined. Not relevant anymore.  
Ah, makes sense, thanks.
Any reason to not report those? It looks like a valuable information (e.g. to 
avoid showing undefined macros in code completion).


Repository:
  rC Clang

https://reviews.llvm.org/D52098



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


[PATCH] D52079: [Sema] Do not load macros from preamble when LoadExternal is false.

2018-09-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Maybe add a test? 
There is `test/Index/complete-pch-skip.cpp` that checks similar things for AST 
completions, adding macros there should be trivial.


Repository:
  rC Clang

https://reviews.llvm.org/D52079



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


[PATCH] D52076: [CodeComplete] Add completions for filenames in #include directives.

2018-09-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lib/Sema/SemaCodeComplete.cpp:8057
+  if (!(Filename.endswith(".h") || Filename.endswith(".hh") ||
+Filename.endswith(".H") || Filename.endswith(".hpp") ||
+Filename.endswith(".inc")))

sammccall wrote:
> ilya-biryukov wrote:
> > Maybe do case-insensitive matching?
> > A corner case, but still...
> This matches Driver's behavior (I'd reuse it but I don't think Sema 
> can/should depend on Driver). Clang doesn't think "HPP" is a valid c++ header 
> filename.
> I'll add a comment.
IIUC, Driver uses this to infer the language based on file extension (when no 
explicit -x flag was provided).
However, this does not stop anyone from using uppercase file extensions in 
practice (and I assume inferring on headers is also pretty rare, since all 
compiles start with source files anyway).
But this should rare in any case, I don't think it's a blocker.


Repository:
  rC Clang

https://reviews.llvm.org/D52076



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


[PATCH] D51214: [clangd] Add options to enable/disable fixits and function argument snippets.

2018-09-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Maybe commit only an option to enable function arg snippets for now (found 
myself wanting this option today :-))? The fixes would also be nice, but since 
they never work...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51214



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


[PATCH] D52193: RFC: [clang] Multithreaded compilation support

2018-09-18 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D52193#1237468, @zturner wrote:

> What about the timings of clang-cl without /MP?


And one using Ninja rather than msbuild.

I think the real question is whether we want clang and clang-cl to do this. I'm 
not sure we do as it adds complexity for solving a problem that's better solved 
at the build system level.


Repository:
  rC Clang

https://reviews.llvm.org/D52193



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


[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.

FileIndex now provides explicit interfaces for preamble and main file updates.
This avoids growing parameter list when preamble and main symbols diverge
further (e.g. https://reviews.llvm.org/D52078). This also gets rid of the hack 
in `indexAST` that
inferred main file index based on `TopLevelDecls`.

Also separate `indexMainDecls` from `indexAST`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D5

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -50,8 +50,8 @@
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();
-  auto Content = indexAST(AST.getASTContext(), AST.getPreprocessorPtr(),
-  AST.getLocalTopLevelDecls());
+  auto Content = indexMainDecls(AST.getASTContext(), AST.getPreprocessorPtr(),
+AST.getLocalTopLevelDecls());
   return MemIndex::build(std::move(Content.first), std::move(Content.second));
 }
 
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -231,7 +231,7 @@
 TEST(MergeIndexTest, Refs) {
   FileIndex Dyn({"unittest"});
   FileIndex StaticIndex({"unittest"});
-  auto MergedIndex = mergeIndex(&Dyn, &StaticIndex);
+  auto MergedIndex = mergeIndex(&Dyn.index(), &StaticIndex.index());
 
   const char *HeaderCode = "class Foo;";
   auto HeaderSymbols = TestTU::withHeaderCode("class Foo;").headerSymbols();
@@ -244,29 +244,29 @@
   Test.Code = Test1Code.code();
   Test.Filename = "test.cc";
   auto AST = Test.build();
-  Dyn.update(Test.Filename, &AST.getASTContext(), AST.getPreprocessorPtr(),
- AST.getLocalTopLevelDecls());
+  Dyn.updateMain(Test.Filename, AST.getASTContext(), AST.getPreprocessorPtr(),
+ AST.getLocalTopLevelDecls());
 
   // Build static index for test.cc.
   Test.HeaderCode = HeaderCode;
   Test.Code = "// static\nclass Foo {};";
   Test.Filename = "test.cc";
   auto StaticAST = Test.build();
   // Add stale refs for test.cc.
-  StaticIndex.update(Test.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test.Filename, StaticAST.getASTContext(),
+ StaticAST.getPreprocessorPtr(),
+ StaticAST.getLocalTopLevelDecls());
 
   // Add refs for test2.cc
   Annotations Test2Code(R"(class $Foo[[Foo]] {};)");
   TestTU Test2;
   Test2.HeaderCode = HeaderCode;
   Test2.Code = Test2Code.code();
   Test2.Filename = "test2.cc";
   StaticAST = Test2.build();
-  StaticIndex.update(Test2.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test2.Filename, StaticAST.getASTContext(),
+ StaticAST.getPreprocessorPtr(),
+ StaticAST.getLocalTopLevelDecls());
 
   RefsRequest Request;
   Request.IDs = {Foo.ID};
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -119,10 +119,10 @@
   EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
 }
 
-std::vector match(const SymbolIndex &I,
+std::vector match(const FileIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
-  I.fuzzyFind(Req, [&](const Symbol &Sym) {
+  I.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 Matches.push_back((Sym.Scope + Sym.Name).str());
   });
   return Matches;
@@ -135,7 +135,8 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = Code;
   auto AST = File.build();
-  M.update(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
+  M.updatePreamble(File.Filename, AST.getASTContext(),
+   AST.getPreprocessorPtr());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -145,7 +146,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
 SeenSymbol = true;
   });
@@ -182,25 +183,6 @@
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X", "ns::ff"));
 }
 
-TEST(FileIndexTest, RemoveAST) {
-  FileIndex M;
-  update(M, "f1",

[PATCH] D52098: [Index] Add an option to collect macros from preprocesor.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: unittests/Index/IndexTests.cpp:61
+S.Roles = Roles;
+if (MI)
+  S.Info = getSymbolInfoForMacro(*MI);

ilya-biryukov wrote:
> ioeric wrote:
> > ilya-biryukov wrote:
> > > Can this actually happen? It seems weird to have a macro occurrence 
> > > without a `MacroInfo`.
> > > Maybe try asserting that MI is non-null instead?
> > this can happen for macros that are #undefined. Not relevant anymore.  
> Ah, makes sense, thanks.
> Any reason to not report those? It looks like a valuable information (e.g. to 
> avoid showing undefined macros in code completion).
I don't think this is a bug e.g. SemaCodeCompletion can intentionally show 
undefined macros in some contexts. It's up to the index consumer 
implementations how to handle undefinitions.


Repository:
  rC Clang

https://reviews.llvm.org/D52098



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


[PATCH] D52076: [CodeComplete] Add completions for filenames in #include directives.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: lib/Sema/SemaCodeComplete.cpp:8057
+  if (!(Filename.endswith(".h") || Filename.endswith(".hh") ||
+Filename.endswith(".H") || Filename.endswith(".hpp") ||
+Filename.endswith(".inc")))

ilya-biryukov wrote:
> sammccall wrote:
> > ilya-biryukov wrote:
> > > Maybe do case-insensitive matching?
> > > A corner case, but still...
> > This matches Driver's behavior (I'd reuse it but I don't think Sema 
> > can/should depend on Driver). Clang doesn't think "HPP" is a valid c++ 
> > header filename.
> > I'll add a comment.
> IIUC, Driver uses this to infer the language based on file extension (when no 
> explicit -x flag was provided).
> However, this does not stop anyone from using uppercase file extensions in 
> practice (and I assume inferring on headers is also pretty rare, since all 
> compiles start with source files anyway).
> But this should rare in any case, I don't think it's a blocker.
Oh true, headers will work in practice with any extension, so Driver might be 
too restrictive.
Made these case insensitive.


Repository:
  rC Clang

https://reviews.llvm.org/D52076



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


r342449 - [CodeComplete] Add completions for filenames in #include directives.

2018-09-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Sep 18 01:40:41 2018
New Revision: 342449

URL: http://llvm.org/viewvc/llvm-project?rev=342449&view=rev
Log:
[CodeComplete] Add completions for filenames in #include directives.

Summary:
The dir component ("somedir" in #include ) is considered fixed.
We append "foo" to each directory on the include path, and then list its files.

Completions are of the forms:
 #include 
   fox/

The filter is set to the filename part ("fo"), so fuzzy matching can be
applied to the filename only.

No fancy scoring/priorities are set, and no information is added to
CodeCompleteResult to make smart scoring possible. Could be in future.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeCompletion/included-files.cpp
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
cfe/trunk/include/clang/Lex/Lexer.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=342449&r1=342448&r2=342449&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Sep 18 01:40:41 2018
@@ -5606,9 +5606,14 @@ enum CXCompletionContext {
   CXCompletionContext_NaturalLanguage = 1 << 21,
 
   /**
+   * #include file completions should be included in the results.
+   */
+  CXCompletionContext_IncludedFile = 1 << 22,
+
+  /**
* The current context is unknown, so set all contexts.
*/
-  CXCompletionContext_Unknown = ((1 << 22) - 1)
+  CXCompletionContext_Unknown = ((1 << 23) - 1)
 };
 
 /**

Modified: cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/CodeCompletionHandler.h?rev=342449&r1=342448&r2=342449&view=diff
==
--- cfe/trunk/include/clang/Lex/CodeCompletionHandler.h (original)
+++ cfe/trunk/include/clang/Lex/CodeCompletionHandler.h Tue Sep 18 01:40:41 2018
@@ -14,6 +14,8 @@
 #ifndef LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
 #define LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 class IdentifierInfo;
@@ -60,6 +62,11 @@ public:
  MacroInfo *MacroInfo,
  unsigned ArgumentIndex) { }
 
+  /// Callback invoked when performing code completion inside the filename
+  /// part of an #include directive. (Also #import, #include_next, etc).
+  /// \p Dir is the directory relative to the include path, e.g. "a" for http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=342449&r1=342448&r2=342449&view=diff
==
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Tue Sep 18 01:40:41 2018
@@ -711,6 +711,9 @@ private:
 
   bool isHexaLiteral(const char *Start, const LangOptions &LangOpts);
 
+  void codeCompleteIncludedFile(const char *PathStart,
+const char *CompletionPoint, bool IsAngled);
+
   /// Read a universal character name.
   ///
   /// \param StartPtr The position in the source buffer after the initial '\'.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=342449&r1=342448&r2=342449&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Sep 18 01:40:41 2018
@@ -1128,6 +1128,10 @@ public:
 CodeComplete = nullptr;
   }
 
+  /// Hook used by the lexer to invoke the "included file" code
+  /// completion point.
+  void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
+
   /// Hook used by the lexer to invoke the "natural language" code
   /// completion point.
   void CodeCompleteNaturalLanguage();

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=342449&r1=342448&r2=342449&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Pa

[PATCH] D52076: [CodeComplete] Add completions for filenames in #include directives.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC342449: [CodeComplete] Add completions for filenames in 
#include directives. (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52076?vs=165787&id=165904#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52076

Files:
  include/clang-c/Index.h
  include/clang/Lex/CodeCompletionHandler.h
  include/clang/Lex/Lexer.h
  include/clang/Lex/Preprocessor.h
  include/clang/Parse/Parser.h
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/Sema.h
  lib/Frontend/ASTUnit.cpp
  lib/Lex/Lexer.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/Parser.cpp
  lib/Sema/CodeCompleteConsumer.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/included-files.cpp
  tools/libclang/CIndexCodeCompletion.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1976,6 +1976,7 @@
   case CodeCompletionContext::CCC_ObjCInstanceMessage:
   case CodeCompletionContext::CCC_ObjCClassMessage:
   case CodeCompletionContext::CCC_ObjCCategoryName:
+  case CodeCompletionContext::CCC_IncludedFile:
 // We're looking for nothing, or we're looking for names that cannot
 // be hidden.
 return;
Index: lib/Parse/Parser.cpp
===
--- lib/Parse/Parser.cpp
+++ lib/Parse/Parser.cpp
@@ -1967,6 +1967,10 @@
 ArgumentIndex);
 }
 
+void Parser::CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled) {
+  Actions.CodeCompleteIncludedFile(Dir, IsAngled);
+}
+
 void Parser::CodeCompleteNaturalLanguage() {
   Actions.CodeCompleteNaturalLanguage();
 }
Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -445,6 +445,13 @@
   return false;
 }
 
+void Preprocessor::CodeCompleteIncludedFile(llvm::StringRef Dir,
+bool IsAngled) {
+  if (CodeComplete)
+CodeComplete->CodeCompleteIncludedFile(Dir, IsAngled);
+  setCodeCompletionReached();
+}
+
 void Preprocessor::CodeCompleteNaturalLanguage() {
   if (CodeComplete)
 CodeComplete->CodeCompleteNaturalLanguage();
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1896,6 +1896,7 @@
 /// either " or L" or u8" or u" or U".
 bool Lexer::LexStringLiteral(Token &Result, const char *CurPtr,
  tok::TokenKind Kind) {
+  const char *AfterQuote = CurPtr;
   // Does this string contain the \0 character?
   const char *NulCharacter = nullptr;
 
@@ -1924,8 +1925,11 @@
 
 if (C == 0) {
   if (isCodeCompletionPoint(CurPtr-1)) {
-PP->CodeCompleteNaturalLanguage();
-FormTokenWithChars(Result, CurPtr-1, tok::unknown);
+if (ParsingFilename)
+  codeCompleteIncludedFile(AfterQuote, CurPtr - 1, /*IsAngled=*/false);
+else
+  PP->CodeCompleteNaturalLanguage();
+FormTokenWithChars(Result, CurPtr - 1, tok::unknown);
 cutOffLexing();
 return true;
   }
@@ -2043,16 +2047,21 @@
 if (C == '\\')
   C = getAndAdvanceChar(CurPtr, Result);
 
-if (C == '\n' || C == '\r' || // Newline.
-(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
-isCodeCompletionPoint(CurPtr-1 {
+if (C == '\n' || C == '\r' ||// Newline.
+(C == 0 && (CurPtr - 1 == BufferEnd))) { // End of file.
   // If the filename is unterminated, then it must just be a lone <
   // character.  Return this as such.
   FormTokenWithChars(Result, AfterLessPos, tok::less);
   return true;
 }
 
 if (C == 0) {
+  if (isCodeCompletionPoint(CurPtr - 1)) {
+codeCompleteIncludedFile(AfterLessPos, CurPtr - 1, /*IsAngled=*/true);
+cutOffLexing();
+FormTokenWithChars(Result, CurPtr - 1, tok::unknown);
+return true;
+  }
   NulCharacter = CurPtr-1;
 }
 C = getAndAdvanceChar(CurPtr, Result);
@@ -2069,6 +2078,34 @@
   return true;
 }
 
+void Lexer::codeCompleteIncludedFile(const char *PathStart,
+ const char *CompletionPoint,
+ bool IsAngled) {
+  // Completion only applies to the filename, after the last slash.
+  StringRef PartialPath(PathStart, CompletionPoint - PathStart);
+  auto Slash = PartialPath.find_last_of(LangOpts.MSVCCompat ? "/\\" : "/");
+  StringRef Dir =
+  (Slash == StringRef::npos) ? "" : PartialPath.take_front(Slash);
+  const char *StartOfFilename =
+  (Slash == StringRef::npos) ? PathStart : PathStart + Slash + 1;
+  // Code completion filter range is the filename only, up to completion point.
+  PP->setCodeCompletionIde

[PATCH] D52076: [CodeComplete] Add completions for filenames in #include directives.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342449: [CodeComplete] Add completions for filenames in 
#include directives. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52076?vs=165787&id=165903#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52076

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
  cfe/trunk/include/clang/Lex/Lexer.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Frontend/ASTUnit.cpp
  cfe/trunk/lib/Lex/Lexer.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Parse/Parser.cpp
  cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/CodeCompletion/included-files.cpp
  cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Index: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
===
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
@@ -499,6 +499,10 @@
   contexts = CXCompletionContext_NaturalLanguage;
   break;
 }
+case CodeCompletionContext::CCC_IncludedFile: {
+  contexts = CXCompletionContext_IncludedFile;
+  break;
+}
 case CodeCompletionContext::CCC_SelectorName: {
   contexts = CXCompletionContext_ObjCSelectorName;
   break;
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -5606,9 +5606,14 @@
   CXCompletionContext_NaturalLanguage = 1 << 21,
 
   /**
+   * #include file completions should be included in the results.
+   */
+  CXCompletionContext_IncludedFile = 1 << 22,
+
+  /**
* The current context is unknown, so set all contexts.
*/
-  CXCompletionContext_Unknown = ((1 << 22) - 1)
+  CXCompletionContext_Unknown = ((1 << 23) - 1)
 };
 
 /**
Index: cfe/trunk/include/clang/Parse/Parser.h
===
--- cfe/trunk/include/clang/Parse/Parser.h
+++ cfe/trunk/include/clang/Parse/Parser.h
@@ -2969,6 +2969,7 @@
   void CodeCompletePreprocessorExpression() override;
   void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
  unsigned ArgumentIndex) override;
+  void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled) override;
   void CodeCompleteNaturalLanguage() override;
 };
 
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1128,6 +1128,10 @@
 CodeComplete = nullptr;
   }
 
+  /// Hook used by the lexer to invoke the "included file" code
+  /// completion point.
+  void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
+
   /// Hook used by the lexer to invoke the "natural language" code
   /// completion point.
   void CodeCompleteNaturalLanguage();
Index: cfe/trunk/include/clang/Lex/Lexer.h
===
--- cfe/trunk/include/clang/Lex/Lexer.h
+++ cfe/trunk/include/clang/Lex/Lexer.h
@@ -711,6 +711,9 @@
 
   bool isHexaLiteral(const char *Start, const LangOptions &LangOpts);
 
+  void codeCompleteIncludedFile(const char *PathStart,
+const char *CompletionPoint, bool IsAngled);
+
   /// Read a universal character name.
   ///
   /// \param StartPtr The position in the source buffer after the initial '\'.
Index: cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
===
--- cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
+++ cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
@@ -14,6 +14,8 @@
 #ifndef LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
 #define LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 class IdentifierInfo;
@@ -60,6 +62,11 @@
  MacroInfo *MacroInfo,
  unsigned ArgumentIndex) { }
 
+  /// Callback invoked when performing code completion inside the filename
+  /// part of an #include directive. (Also #import, #include_next, etc).
+  /// \p Dir is the directory relative to the include path, e.g. "a" for 
+// RUN: %clang -fsyntax-only -isystem %t/a -Xclang -code-completion-at=%t/main.cc:19:13 %t/main.cc | FileCheck -check-prefix=CHECK-3 %s
+// CHECK-3-NOT: foo.cc>
+// CHECK-3-NOT: foo.h>
+// CHECK-3: foosys>
+
+// Backslash handling.
+#include "a\foosys"
+// RUN: %clang -fsyntax-only -isystem %t/a -Xclang -code-completion-at=%t

r342451 - [Index] Add an option to collect macros from preprocesor.

2018-09-18 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Sep 18 01:51:08 2018
New Revision: 342451

URL: http://llvm.org/viewvc/llvm-project?rev=342451&view=rev
Log:
[Index] Add an option to collect macros from preprocesor.

Summary: Also added unit tests for the index library; lit+c-index-test is 
painful...

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/Index/
cfe/trunk/unittests/Index/CMakeLists.txt
cfe/trunk/unittests/Index/IndexTests.cpp
Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexingAction.cpp
cfe/trunk/unittests/CMakeLists.txt

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=342451&r1=342450&r2=342451&view=diff
==
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Tue Sep 18 01:51:08 2018
@@ -12,6 +12,7 @@
 
 #include "clang/Basic/LLVM.h"
 #include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include 
 
@@ -40,6 +41,10 @@ struct IndexingOptions {
 = SystemSymbolFilterKind::DeclarationsOnly;
   bool IndexFunctionLocals = false;
   bool IndexImplicitInstantiation = false;
+  // Whether to index macro definitions in the Preprocesor when preprocessor
+  // callback is not available (e.g. after parsing has finished). Note that
+  // macro references are not available in Proprocessor.
+  bool IndexMacrosInPreprocessor = false;
 };
 
 /// Creates a frontend action that indexes all symbols (macros and AST decls).
@@ -50,13 +55,12 @@ createIndexingAction(std::shared_ptr WrappedAction);
 
 /// Recursively indexes all decls in the AST.
-/// Note that this does not index macros.
 void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
   IndexingOptions Opts);
 
 /// Recursively indexes \p Decls.
-/// Note that this does not index macros.
-void indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls,
+void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
+ArrayRef Decls,
 IndexDataConsumer &DataConsumer, IndexingOptions Opts);
 
 /// Creates a PPCallbacks that indexes macros and feeds macros to \p Consumer.
@@ -65,7 +69,6 @@ std::unique_ptr indexMacros
  IndexingOptions Opts);
 
 /// Recursively indexes all top-level decls in the module.
-/// FIXME: make this index macros as well.
 void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
  IndexDataConsumer &DataConsumer, IndexingOptions Opts);
 

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=342451&r1=342450&r2=342451&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Tue Sep 18 01:51:08 2018
@@ -215,23 +215,41 @@ static void indexTranslationUnit(ASTUnit
   Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
 }
 
+static void indexPreprocessorMacros(const Preprocessor &PP,
+IndexDataConsumer &DataConsumer) {
+  for (const auto &M : PP.macros())
+if (MacroDirective *MD = M.second.getLatest())
+  DataConsumer.handleMacroOccurence(
+  M.first, MD->getMacroInfo(),
+  static_cast(index::SymbolRole::Definition),
+  MD->getLocation());
+}
+
 void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
  IndexingOptions Opts) {
   IndexingContext IndexCtx(Opts, DataConsumer);
   IndexCtx.setASTContext(Unit.getASTContext());
   DataConsumer.initialize(Unit.getASTContext());
   DataConsumer.setPreprocessor(Unit.getPreprocessorPtr());
+
+  if (Opts.IndexMacrosInPreprocessor)
+indexPreprocessorMacros(Unit.getPreprocessor(), DataConsumer);
   indexTranslationUnit(Unit, IndexCtx);
   DataConsumer.finish();
 }
 
-void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls,
+void index::indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
+   ArrayRef Decls,
IndexDataConsumer &DataConsumer,
IndexingOptions Opts) {
   IndexingContext IndexCtx(Opts, DataConsumer);
   IndexCtx.setASTContext(Ctx);
 
   DataConsumer.initialize(Ctx);
+
+  if (Opts.IndexMacrosInPreprocessor)
+indexPreprocessorMacros(PP, DataConsumer);
+
   for (const Decl *D : Decls)
 IndexCtx.indexTopLevelDecl(D);
   DataConsumer.finish();
@@ -251,6 +269,9 @@ void index::indexModuleFile(serializatio
   IndexCtx.setASTContext(Ctx);
   DataConsumer.initialize(Ctx);
 
+  if (Opts.Index

[PATCH] D52098: [Index] Add an option to collect macros from preprocesor.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342451: [Index] Add an option to collect macros from 
preprocesor. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52098

Files:
  cfe/trunk/include/clang/Index/IndexingAction.h
  cfe/trunk/lib/Index/IndexingAction.cpp
  cfe/trunk/unittests/CMakeLists.txt
  cfe/trunk/unittests/Index/CMakeLists.txt
  cfe/trunk/unittests/Index/IndexTests.cpp

Index: cfe/trunk/lib/Index/IndexingAction.cpp
===
--- cfe/trunk/lib/Index/IndexingAction.cpp
+++ cfe/trunk/lib/Index/IndexingAction.cpp
@@ -215,23 +215,41 @@
   Unit.visitLocalTopLevelDecls(&IndexCtx, topLevelDeclVisitor);
 }
 
+static void indexPreprocessorMacros(const Preprocessor &PP,
+IndexDataConsumer &DataConsumer) {
+  for (const auto &M : PP.macros())
+if (MacroDirective *MD = M.second.getLatest())
+  DataConsumer.handleMacroOccurence(
+  M.first, MD->getMacroInfo(),
+  static_cast(index::SymbolRole::Definition),
+  MD->getLocation());
+}
+
 void index::indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
  IndexingOptions Opts) {
   IndexingContext IndexCtx(Opts, DataConsumer);
   IndexCtx.setASTContext(Unit.getASTContext());
   DataConsumer.initialize(Unit.getASTContext());
   DataConsumer.setPreprocessor(Unit.getPreprocessorPtr());
+
+  if (Opts.IndexMacrosInPreprocessor)
+indexPreprocessorMacros(Unit.getPreprocessor(), DataConsumer);
   indexTranslationUnit(Unit, IndexCtx);
   DataConsumer.finish();
 }
 
-void index::indexTopLevelDecls(ASTContext &Ctx, ArrayRef Decls,
+void index::indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
+   ArrayRef Decls,
IndexDataConsumer &DataConsumer,
IndexingOptions Opts) {
   IndexingContext IndexCtx(Opts, DataConsumer);
   IndexCtx.setASTContext(Ctx);
 
   DataConsumer.initialize(Ctx);
+
+  if (Opts.IndexMacrosInPreprocessor)
+indexPreprocessorMacros(PP, DataConsumer);
+
   for (const Decl *D : Decls)
 IndexCtx.indexTopLevelDecl(D);
   DataConsumer.finish();
@@ -251,6 +269,9 @@
   IndexCtx.setASTContext(Ctx);
   DataConsumer.initialize(Ctx);
 
+  if (Opts.IndexMacrosInPreprocessor)
+indexPreprocessorMacros(Reader.getPreprocessor(), DataConsumer);
+
   for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
 IndexCtx.indexTopLevelDecl(D);
   }
Index: cfe/trunk/unittests/Index/CMakeLists.txt
===
--- cfe/trunk/unittests/Index/CMakeLists.txt
+++ cfe/trunk/unittests/Index/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Support
+  )
+
+add_clang_unittest(IndexTests
+  IndexTests.cpp
+  )
+
+target_link_libraries(IndexTests
+  PRIVATE
+  clangAST
+  clangBasic
+  clangFrontend
+  clangIndex
+  clangLex
+  clangTooling
+  )
Index: cfe/trunk/unittests/Index/IndexTests.cpp
===
--- cfe/trunk/unittests/Index/IndexTests.cpp
+++ cfe/trunk/unittests/Index/IndexTests.cpp
@@ -0,0 +1,125 @@
+//===--- IndexTests.cpp - Test indexing actions -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexSymbol.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace index {
+
+struct TestSymbol {
+  std::string QName;
+  // FIXME: add more information.
+};
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const TestSymbol &S) {
+  return OS << S.QName;
+}
+
+namespace {
+class Indexer : public IndexDataConsumer {
+public:
+  bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
+   ArrayRef, SourceLocation,
+   ASTNodeInfo) override {
+const auto *ND = llvm::dyn_cast(D);
+if (!ND)
+  return true;
+TestSymbol S;
+S.QName = ND->getQualifiedNameAsString();
+Symbols.push_back(std::move(S));
+return true;
+  }
+
+  bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *,
+SymbolRoleSet, SourceLocation) override {
+Tes

[clang-tools-extra] r342452 - [clangd] Adapt API change after 342451.

2018-09-18 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Sep 18 01:52:14 2018
New Revision: 342452

URL: http://llvm.org/viewvc/llvm-project?rev=342452&view=rev
Log:
[clangd] Adapt API change after 342451.

Modified:
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=342452&r1=342451&r2=342452&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Tue Sep 18 01:52:14 2018
@@ -270,8 +270,9 @@ getDocumentSymbols(ParsedAST &AST) {
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly;
   IndexOpts.IndexFunctionLocals = false;
-  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
- DocumentSymbolsCons, IndexOpts);
+  indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
+ AST.getLocalTopLevelDecls(), DocumentSymbolsCons,
+ IndexOpts);
 
   return DocumentSymbolsCons.takeSymbols();
 }

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=342452&r1=342451&r2=342452&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Sep 18 01:52:14 2018
@@ -206,8 +206,8 @@ IdentifiedSymbol getSymbolAtPosition(Par
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
- DeclMacrosFinder, IndexOpts);
+  indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
+ AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts);
 
   return {DeclMacrosFinder.getFoundDecls(), DeclMacrosFinder.takeMacroInfos()};
 }
@@ -414,8 +414,8 @@ findRefs(const std::vector
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
- RefFinder, IndexOpts);
+  indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
+ AST.getLocalTopLevelDecls(), RefFinder, IndexOpts);
   return std::move(RefFinder).take();
 }
 

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=342452&r1=342451&r2=342452&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Tue Sep 18 01:52:14 2018
@@ -54,7 +54,7 @@ indexAST(ASTContext &AST, std::shared_pt
 
   SymbolCollector Collector(std::move(CollectorOpts));
   Collector.setPreprocessor(PP);
-  index::indexTopLevelDecls(AST, DeclsToIndex, Collector, IndexOpts);
+  index::indexTopLevelDecls(AST, *PP, DeclsToIndex, Collector, IndexOpts);
 
   const auto &SM = AST.getSourceManager();
   const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());


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


[clang-tools-extra] r342453 - [clangd] Update code completion for #include completions in r342449

2018-09-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Sep 18 02:08:28 2018
New Revision: 342453

URL: http://llvm.org/viewvc/llvm-project?rev=342453&view=rev
Log:
[clangd] Update code completion for #include completions in r342449

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=342453&r1=342452&r2=342453&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Sep 18 02:08:28 2018
@@ -116,9 +116,12 @@ CompletionItemKind toCompletionItemKind(
 
 CompletionItemKind
 toCompletionItemKind(CodeCompletionResult::ResultKind ResKind,
- const NamedDecl *Decl) {
+ const NamedDecl *Decl,
+ CodeCompletionContext::Kind CtxKind) {
   if (Decl)
 return toCompletionItemKind(index::getSymbolInfo(Decl).Kind);
+  if (CtxKind == CodeCompletionContext::CCC_IncludedFile)
+return CompletionItemKind::File;
   switch (ResKind) {
   case CodeCompletionResult::RK_Declaration:
 llvm_unreachable("RK_Declaration without Decl");
@@ -328,6 +331,7 @@ struct CodeCompletionBuilder {
   CodeCompletionBuilder(ASTContext &ASTCtx, const CompletionCandidate &C,
 CodeCompletionString *SemaCCS,
 const IncludeInserter &Includes, StringRef FileName,
+CodeCompletionContext::Kind ContextKind,
 const CodeCompleteOptions &Opts)
   : ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments),
 EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets) {
@@ -343,8 +347,8 @@ struct CodeCompletionBuilder {
   Completion.Scope =
   splitQualifiedName(printQualifiedName(*ND)).first;
   }
-  Completion.Kind =
-  toCompletionItemKind(C.SemaResult->Kind, C.SemaResult->Declaration);
+  Completion.Kind = toCompletionItemKind(
+  C.SemaResult->Kind, C.SemaResult->Declaration, ContextKind);
   for (const auto &FixIt : C.SemaResult->FixIts) {
 Completion.FixIts.push_back(
 toTextEdit(FixIt, ASTCtx.getSourceManager(), 
ASTCtx.getLangOpts()));
@@ -653,6 +657,7 @@ bool contextAllowsIndex(enum CodeComplet
   case CodeCompletionContext::CCC_TypeQualifiers:
   case CodeCompletionContext::CCC_ObjCInstanceMessage:
   case CodeCompletionContext::CCC_ObjCClassMessage:
+  case CodeCompletionContext::CCC_IncludedFile:
   case CodeCompletionContext::CCC_Recovery:
 return false;
   }
@@ -1547,7 +1552,8 @@ private:
   : nullptr;
   if (!Builder)
 Builder.emplace(Recorder->CCSema->getASTContext(), Item, SemaCCS,
-*Inserter, FileName, Opts);
+*Inserter, FileName, Recorder->CCContext.getKind(),
+Opts);
   else
 Builder->add(Item, SemaCCS);
 }


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


[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Glorious! Think the APIs could be simplified/clarified a little further, but up 
to you.




Comment at: clangd/index/FileIndex.cpp:24
+indexSymbols(ASTContext &AST, std::shared_ptr PP,
+ llvm::ArrayRef DeclsToIndex, bool IsIndexMainAST,
+ llvm::ArrayRef URISchemes) {

assert DeclsToIndex is empty if !IsIndexMainAST?



Comment at: clangd/index/FileIndex.h:77
+  /// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
+  void updateMain(PathRef Path, ASTContext &AST,
+  std::shared_ptr PP,

can't this just take PathRef + ParsedAST?
(same data, but clearer semantics)



Comment at: clangd/index/FileIndex.h:114
+std::pair
+indexMainDecls(ASTContext &AST, std::shared_ptr PP,
+   llvm::ArrayRef Decls,

again, take ParsedAST here?



Comment at: clangd/index/FileIndex.h:118
+
+/// Idex all declarations in \p AST and all macro definitions in \p PP.
+/// If URISchemes is empty, the default schemes in SymbolCollector will be 
used.

This isn't quite right I think - we don't index the symbols that only occur in 
the main file.



Comment at: clangd/index/FileIndex.h:120
+/// If URISchemes is empty, the default schemes in SymbolCollector will be 
used.
 std::pair
 indexAST(ASTContext &AST, std::shared_ptr PP,

this shouldn't return any refs, just return SymbolSlab here



Comment at: clangd/index/FileIndex.h:121
 std::pair
 indexAST(ASTContext &AST, std::shared_ptr PP,
  llvm::ArrayRef URISchemes = {});

indexPreamble would be clearer I think.



Comment at: unittests/clangd/TestTU.cpp:51
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();

this should return FileIndex instead I think, with both preamble and main index.
But this requires fixing callers (since FileIndex isn't an index).
Leave a fixme?

(Maybe I should just bite the bullet and expose the MergedIndex class so we 
don't have to deal with these indirections...)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D5



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


[PATCH] D52187: [clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

2018-09-18 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG with a comment.




Comment at: test/clang-tidy/bugprone-unused-return-value.cpp:81
   std::async(std::launch::async, increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function 
should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence 
this warning

I'd probably cut repeated parts of the pattern (starting from the second one) 
to make them fit 80 characters, e.g. like this:
  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used

Same for the notes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52187



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


[PATCH] D52186: [clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

2018-09-18 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52186



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


[PATCH] D52178: [clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

2018-09-18 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52178



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


Re: [clang-tools-extra] r342388 - [Clang-Tidy: modernize] Fix for modernize-redundant-void-arg: complains about variable cast to void

2018-09-18 Thread Alexander Kornienko via cfe-commits
Nope, that's fine. See my previous email.

On Mon, Sep 17, 2018 at 3:18 PM IdrissRio 
wrote:

> Yes I have already make the fix commit. It was an error in the  tests.
>
>
> https://github.com/llvm-mirror/clang-tools-extra/commit/77ed1cd838a249d6134de9a6bdbe17ef46ecf946
>
>
> Now on my Mac it compile and all the tests are ok.
> Should I try anything else ?
>
> Il giorno 17 set 2018, alle ore 15:14, Alexander Kornienko via cfe-commits
>  ha scritto:
>
> It looks like this commit breaks buildbots (e.g.
> http://lab.llvm.org:8011/builders/clang-cmake-armv8-quick/builds/6711).
> Could you take a look?
>
> On Mon, Sep 17, 2018 at 2:33 PM Idriss Riouak via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: idrissrio
>> Date: Mon Sep 17 05:29:29 2018
>> New Revision: 342388
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=342388&view=rev
>> Log:
>> [Clang-Tidy: modernize] Fix for modernize-redundant-void-arg: complains
>> about variable cast to void
>>
>> Summary:
>> Hello, i would like to suggest a fix for one of the checks in
>> clang-tidy.The bug was reported in
>> https://bugs.llvm.org/show_bug.cgi?id=32575 where you can find more
>> information.
>>
>> For example:
>> ```
>> template 
>> struct S {
>>   template 
>>   void g() const {
>> int a;
>> (void)a;
>>   }
>> };
>>
>> void f() {
>>   S().g();
>> }
>> ```
>>
>>
>> this piece of code should not trigger any warning by the check
>> modernize-redundant-void-arg but when we execute the following command
>>
>>
>> ```
>> clang_tidy -checks=-*,modernize-redundant-void-arg test.cpp -- -std=c++11
>> ```
>>
>> we obtain the following warning:
>>
>> /Users/eco419/Desktop/clang-tidy.project/void-redundand_2/test.cpp:6:6:
>> warning: redundant void argument list in function declaration
>> [modernize-redundant-void-arg]
>> (void)a;
>>  ^~~~
>>
>> Reviewers: aaron.ballman, hokein, alexfh, JonasToth
>>
>> Reviewed By: aaron.ballman, JonasToth
>>
>> Subscribers: JonasToth, lebedev.ri, cfe-commits
>>
>> Tags: #clang-tools-extra
>>
>> Differential Revision: https://reviews.llvm.org/D52135
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
>>
>> clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=342388&r1=342387&r2=342388&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Mon
>> Sep 17 05:29:29 2018
>> @@ -49,7 +49,7 @@ void RedundantVoidArgCheck::registerMatc
>>  return;
>>
>>Finder->addMatcher(functionDecl(parameterCountIs(0),
>> unless(isImplicit()),
>> -  unless(isExternC()))
>> +  unless(isInstantiated()),
>> unless(isExternC()))
>>   .bind(FunctionId),
>>   this);
>>Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
>>
>> Modified:
>> clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=342388&r1=342387&r2=342388&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
>> Mon Sep 17 05:29:29 2018
>> @@ -488,3 +488,64 @@ void lambda_expression_with_macro_test()
>>// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant void argument
>> list in lambda expression [modernize-redundant-void-arg]
>>// CHECK-FIXES: []() BODY;
>>  }
>> +
>> +struct S_1 {
>> +  void g_1(void) const {
>> +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument
>> list in function definition [modernize-redundant-void-arg]
>> +// CHECK-FIXES: void g_1() const {
>> +int a;
>> +(void)a;
>> +  }
>> +
>> +  void g_2() const {
>> +int a;
>> +(void)a;
>> +  }
>> +};
>> +
>> +template 
>> +struct S_2 {
>> +  void g_1(void) const {
>> +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument
>> list in function definition [modernize-redundant-void-arg]
>> +// CHECK-FIXES: void g_1() const {
>> +int a;
>> +(void)a;
>> +  }
>> +
>> +  void g_2() const {
>> +int a;
>> +(void)a;
>> +  }
>> +};
>> +
>> +template 
>> +struct S_3 {
>> +  template 
>> +  void g_1(void) const {
>> +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument
>> list in function definition [modernize-redundant-void-arg]
>> +// CHECK-FIXES:

[clang-tools-extra] r342456 - [clangd] dexp tool uses llvm::cl to parse its flags.

2018-09-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Sep 18 02:49:57 2018
New Revision: 342456

URL: http://llvm.org/viewvc/llvm-project?rev=342456&view=rev
Log:
[clangd] dexp tool uses llvm::cl to parse its flags.

Summary:
We can use cl::ResetCommandLineParser() to support different types of
command-lines, as long as we're careful about option lifetimes.
(I tried using subcommands, but the error messages were bad)
I found a mostly-reasonable pattern to isolate the fiddly parts.

Added -scope and -limit flags to the `find` command to demonstrate.
(Note that scope support seems to be broken in dex?)

Fixed symbol lookup to parse symbol IDs.

Caveats:
 - with command help (e.g. `find -help`), you also get some spam
   about required arguments. This is a bug in llvm::cl, which prints
   these to errs() rather than the designated stream.

Reviewers: kbobyrev

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, 
cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=342456&r1=342455&r2=342456&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Tue Sep 18 02:49:57 
2018
@@ -25,7 +25,7 @@ using clang::clangd::FuzzyFindRequest;
 using clang::clangd::loadIndex;
 using clang::clangd::Symbol;
 using clang::clangd::SymbolIndex;
-using llvm::StringRef;
+using namespace llvm;
 
 namespace {
 
@@ -52,51 +52,42 @@ void reportTime(StringRef Name, llvm::fu
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
-void fuzzyFind(llvm::StringRef UnqualifiedName, const SymbolIndex &Index) {
-  FuzzyFindRequest Request;
-  Request.Limit = 10;
-  Request.Query = UnqualifiedName;
-  // FIXME(kbobyrev): Print symbol final scores to see the distribution.
-  static const auto OutputFormat = "{0,-4} | {1,-40} | {2,-25}\n";
-  llvm::outs() << llvm::formatv(OutputFormat, "Rank", "Symbol ID",
-"Symbol Name");
-  size_t Rank = 0;
-  Index.fuzzyFind(Request, [&](const Symbol &Sym) {
-llvm::outs() << llvm::formatv(OutputFormat, Rank++, Sym.ID.str(), 
Sym.Name);
-  });
-}
-
-static const std::string HelpMessage = R"(dexp commands:
-
-> find Name
-
-Constructs fuzzy find request given unqualified symbol name and returns top 10
-symbols retrieved from index.
-
-> lookup SymbolID
-
-Retrieves symbol names given USR.
-)";
-
-void help() { llvm::outs() << HelpMessage; }
-
-void lookup(StringRef USR, const SymbolIndex &Index) {
-  llvm::DenseSet IDs{clang::clangd::SymbolID{USR}};
-  clang::clangd::LookupRequest Request{IDs};
-  bool FoundSymbol = false;
-  Index.lookup(Request, [&](const Symbol &Sym) {
-if (!FoundSymbol)
-  FoundSymbol = true;
-llvm::outs() << SymbolToYAML(Sym);
-  });
-  if (!FoundSymbol)
-llvm::outs() << "not found\n";
-}
+// REPL commands inherit from Command and contain their options as members.
+// Creating a Command populates parser options, parseAndRun() resets them.
+class Command {
+  // By resetting the parser options, we lost the standard -help flag.
+  cl::opt> Help{
+  "help", cl::desc("Display available options"), cl::ValueDisallowed,
+  cl::cat(cl::GeneralCategory)};
+  virtual void run() = 0;
+
+protected:
+  const SymbolIndex *Index;
+
+public:
+  virtual ~Command() = default;
+  virtual void parseAndRun(ArrayRef Argv, const char *Overview,
+   const SymbolIndex &Index) {
+std::string ParseErrs;
+llvm::raw_string_ostream OS(ParseErrs);
+bool Ok =
+cl::ParseCommandLineOptions(Argv.size(), Argv.data(), Overview, &OS);
+if (Help.getNumOccurrences() > 0) {
+  // Avoid printing parse errors in this case.
+  // (Well, in theory. A bunch get printed to llvm::errs() regardless!)
+  cl::PrintHelpMessage();
+} else {
+  outs() << OS.str();
+  if (Ok) {
+this->Index = &Index;
+reportTime(Argv[0], [&] { run(); });
+  }
+}
+cl::ResetCommandLineParser(); // must do this before opts are destroyed.
+  }
+};
 
-// FIXME(kbobyrev): Make this an actual REPL: probably use LLVM Command Line
-// library for parsing flags and arguments.
-// FIXME(kbobyrev): Ideas for commands:
-// * symbol lookup: print out symbol in YAML format given SymbolID
+// FIXME(kbobyrev): Ideas for more commands:
 // * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
@@ -105,39 +96,86 @@ void lookup(StringRef USR, const SymbolI
 // * show number of tokens of each 

[PATCH] D51989: [clangd] dexp tool uses llvm::cl to parse its flags.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE342456: [clangd] dexp tool uses llvm::cl to parse its 
flags. (authored by sammccall, committed by ).
Herald added a subscriber: mgorny.

Changed prior to commit:
  https://reviews.llvm.org/D51989?vs=165088&id=165912#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51989

Files:
  clangd/index/dex/dexp/Dexp.cpp
  test/CMakeLists.txt

Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -25,7 +25,7 @@
 using clang::clangd::loadIndex;
 using clang::clangd::Symbol;
 using clang::clangd::SymbolIndex;
-using llvm::StringRef;
+using namespace llvm;
 
 namespace {
 
@@ -52,92 +52,130 @@
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
-void fuzzyFind(llvm::StringRef UnqualifiedName, const SymbolIndex &Index) {
-  FuzzyFindRequest Request;
-  Request.Limit = 10;
-  Request.Query = UnqualifiedName;
-  // FIXME(kbobyrev): Print symbol final scores to see the distribution.
-  static const auto OutputFormat = "{0,-4} | {1,-40} | {2,-25}\n";
-  llvm::outs() << llvm::formatv(OutputFormat, "Rank", "Symbol ID",
-"Symbol Name");
-  size_t Rank = 0;
-  Index.fuzzyFind(Request, [&](const Symbol &Sym) {
-llvm::outs() << llvm::formatv(OutputFormat, Rank++, Sym.ID.str(), Sym.Name);
-  });
-}
-
-static const std::string HelpMessage = R"(dexp commands:
-
-> find Name
-
-Constructs fuzzy find request given unqualified symbol name and returns top 10
-symbols retrieved from index.
-
-> lookup SymbolID
-
-Retrieves symbol names given USR.
-)";
-
-void help() { llvm::outs() << HelpMessage; }
-
-void lookup(StringRef USR, const SymbolIndex &Index) {
-  llvm::DenseSet IDs{clang::clangd::SymbolID{USR}};
-  clang::clangd::LookupRequest Request{IDs};
-  bool FoundSymbol = false;
-  Index.lookup(Request, [&](const Symbol &Sym) {
-if (!FoundSymbol)
-  FoundSymbol = true;
-llvm::outs() << SymbolToYAML(Sym);
-  });
-  if (!FoundSymbol)
-llvm::outs() << "not found\n";
-}
+// REPL commands inherit from Command and contain their options as members.
+// Creating a Command populates parser options, parseAndRun() resets them.
+class Command {
+  // By resetting the parser options, we lost the standard -help flag.
+  cl::opt> Help{
+  "help", cl::desc("Display available options"), cl::ValueDisallowed,
+  cl::cat(cl::GeneralCategory)};
+  virtual void run() = 0;
+
+protected:
+  const SymbolIndex *Index;
+
+public:
+  virtual ~Command() = default;
+  virtual void parseAndRun(ArrayRef Argv, const char *Overview,
+   const SymbolIndex &Index) {
+std::string ParseErrs;
+llvm::raw_string_ostream OS(ParseErrs);
+bool Ok =
+cl::ParseCommandLineOptions(Argv.size(), Argv.data(), Overview, &OS);
+if (Help.getNumOccurrences() > 0) {
+  // Avoid printing parse errors in this case.
+  // (Well, in theory. A bunch get printed to llvm::errs() regardless!)
+  cl::PrintHelpMessage();
+} else {
+  outs() << OS.str();
+  if (Ok) {
+this->Index = &Index;
+reportTime(Argv[0], [&] { run(); });
+  }
+}
+cl::ResetCommandLineParser(); // must do this before opts are destroyed.
+  }
+};
 
-// FIXME(kbobyrev): Make this an actual REPL: probably use LLVM Command Line
-// library for parsing flags and arguments.
-// FIXME(kbobyrev): Ideas for commands:
-// * symbol lookup: print out symbol in YAML format given SymbolID
+// FIXME(kbobyrev): Ideas for more commands:
 // * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
 //   could build one)
 // * show number of tokens of each kind
 // * print out tokens with the most dense posting lists
 // * print out tokens with least dense posting lists
-void dispatch(StringRef Request, const SymbolIndex &Index) {
-  llvm::SmallVector Arguments;
-  Request.split(Arguments, ' ');
-  if (Arguments.empty()) {
-llvm::outs() << "Request can not be empty.\n";
-help();
-return;
-  }
 
-  if (Arguments.front() == "find") {
-if (Arguments.size() != 2) {
-  llvm::outs() << "find request must specify unqualified symbol name.\n";
-  return;
+class FuzzyFind : public Command {
+  cl::opt Query{
+  "query",
+  cl::Positional,
+  cl::Required,
+  cl::desc("Query string to be fuzzy-matched"),
+  };
+  cl::opt Scopes{
+  "scopes",
+  cl::desc("Allowed symbol scopes (comma-separated list)"),
+  };
+  cl::opt Limit{
+  "limit",
+  cl::init(10),
+  cl::desc("Max results to display"),
+  };
+
+  void run() override {
+FuzzyFindRequest

[clang-tools-extra] r342458 - [clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 03:15:15 2018
New Revision: 342458

URL: http://llvm.org/viewvc/llvm-project?rev=342458&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

Summary:
This patch uses CHECK-NOTES for the tests.
Its part of an effort to test *ALL* generated diagnostics in clang-tidy,
as emitted notes were previously ignored.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp?rev=342458&r1=342457&r2=342458&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
Tue Sep 18 03:15:15 2018
@@ -83,17 +83,41 @@ class MockStandalone {
 void test_gmock_expectations() {
   MockDerived m;
   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_tw=*/2));
-// CHECK-MESSAGES: [[@LINE-1]]:42: warning: argument name 'param_tw' in 
comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-1]]:42: warning: argument name 'param_tw' in comment 
does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-2]]:42: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-19]]:42: note: 'param_two' declared here
+// CHECK-NOTES: [[@LINE-15]]:3: note: actual callee ('gmock_Method') is 
declared here
+// CHECK-NOTES: [[@LINE-33]]:30: note: expanded from macro 'MOCK_METHOD2'
+// CHECK-NOTES: [[@LINE-36]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_two=*/2));
   EXPECT_CALL(m, Method2(/*p_on=*/3, /*p_two=*/4));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment 
does not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment does 
not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-27]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-23]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-41]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-45]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/3, /*p_two=*/4));
 
   #define PARAM1 11
   #define PARAM2 22
   EXPECT_CALL(m, Method2(/*p_on1=*/PARAM1, /*p_tw2=*/PARAM2));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment 
does not match parameter name 'p_one'
-// CHECK-MESSAGES: [[@LINE-2]]:44: warning: argument name 'p_tw2' in comment 
does not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment does 
not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-39]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-35]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-53]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-57]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
+// CHECK-NOTES: [[@LINE-8]]:44: warning: argument name 'p_tw2' in comment does 
not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-9]]:44: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-46]]:39: note: 'p_two' declared here
+// CHECK-NOTES: [[@LINE-42]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-60]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-64]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/PARAM1, /*p_two=*/PARAM2));
 
   MockStandalone m2;
@@ -103,6 +127,9 @@ void test_gmock_expectations() {
 void test_gmock_direct_calls() {
   MockDerived m;
   m.Method(/*param_one=*/1, /*param_tw=*/2);
-// CHECK-MESSAGES: [[@LINE-1]]:29: warning: argument name 'param_tw' in 
comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-1]]:29: warning: argument name 'param_tw' in comment 
does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-2]]:29: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[

[PATCH] D52178: [clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE342458: [clang-tidy] use CHECK-NOTES in tests for 
bugprone-argument-comment (authored by JonasToth, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52178?vs=165784&id=165916#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52178

Files:
  test/clang-tidy/bugprone-argument-comment-gmock.cpp
  test/clang-tidy/bugprone-argument-comment-strict.cpp
  test/clang-tidy/bugprone-argument-comment.cpp

Index: test/clang-tidy/bugprone-argument-comment-strict.cpp
===
--- test/clang-tidy/bugprone-argument-comment-strict.cpp
+++ test/clang-tidy/bugprone-argument-comment-strict.cpp
@@ -5,15 +5,24 @@
 void g(int x_);
 void ignores_underscores() {
   f(/*With_Underscores=*/0);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'With_Underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'With_Underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-6]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/0);
+
   f(/*with_underscores=*/1);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'with_underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'with_underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-12]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/1);
   f(/*_With_Underscores_=*/2);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name '_With_Underscores_' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name '_With_Underscores_' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-17]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/2);
   g(/*X=*/3);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'X' in comment does not match parameter name 'x_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'X' in comment does not match parameter name 'x_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-21]]:12: note: 'x_' declared here
 // CHECK-FIXES: g(/*x_=*/3);
 }
Index: test/clang-tidy/bugprone-argument-comment-gmock.cpp
===
--- test/clang-tidy/bugprone-argument-comment-gmock.cpp
+++ test/clang-tidy/bugprone-argument-comment-gmock.cpp
@@ -83,17 +83,41 @@
 void test_gmock_expectations() {
   MockDerived m;
   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_tw=*/2));
-// CHECK-MESSAGES: [[@LINE-1]]:42: warning: argument name 'param_tw' in comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-1]]:42: warning: argument name 'param_tw' in comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-2]]:42: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-19]]:42: note: 'param_two' declared here
+// CHECK-NOTES: [[@LINE-15]]:3: note: actual callee ('gmock_Method') is declared here
+// CHECK-NOTES: [[@LINE-33]]:30: note: expanded from macro 'MOCK_METHOD2'
+// CHECK-NOTES: [[@LINE-36]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_two=*/2));
   EXPECT_CALL(m, Method2(/*p_on=*/3, /*p_two=*/4));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment does not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment does not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-27]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-23]]:3: note: actual callee ('gmock_Method2') is declared here
+// CHECK-NOTES: [[@LINE-41]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-45]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/3, /*p_two=*/4));
 
   #define PARAM1 11
   #define PARAM2 22
   EXPECT_CALL(m, Method2(/*p_on1=*/PARAM1, /*p_tw2=*/PARAM2));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment does not match parameter name 'p_one'
-// CHECK-MESSAGES: [[@LINE-2]]:44: warning: argument name 'p_tw2' in comment does not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-1]]:26: wa

[PATCH] D52178: [clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342458: [clang-tidy] use CHECK-NOTES in tests for 
bugprone-argument-comment (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52178

Files:
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
@@ -5,15 +5,24 @@
 void g(int x_);
 void ignores_underscores() {
   f(/*With_Underscores=*/0);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'With_Underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'With_Underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-6]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/0);
+
   f(/*with_underscores=*/1);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'with_underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'with_underscores' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-12]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/1);
   f(/*_With_Underscores_=*/2);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name '_With_Underscores_' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name '_With_Underscores_' in comment does not match parameter name '_with_underscores_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-17]]:12: note: '_with_underscores_' declared here
 // CHECK-FIXES: f(/*_with_underscores_=*/2);
   g(/*X=*/3);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument name 'X' in comment does not match parameter name 'x_'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: argument name 'X' in comment does not match parameter name 'x_'
+// CHECK-NOTES: [[@LINE-2]]:5: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-21]]:12: note: 'x_' declared here
 // CHECK-FIXES: g(/*x_=*/3);
 }
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
@@ -7,10 +7,10 @@
 
 void f(int x, int y);
 void g() {
-  // CHECK-MESSAGES: [[@LINE+4]]:5: warning: argument name 'y' in comment does not match parameter name 'x'
-  // CHECK-MESSAGES: :[[@LINE-3]]:12: note: 'x' declared here
-  // CHECK-MESSAGES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y'
-  // CHECK-MESSAGES: :[[@LINE-5]]:19: note: 'y' declared here
+  // CHECK-NOTES: [[@LINE+4]]:5: warning: argument name 'y' in comment does not match parameter name 'x'
+  // CHECK-NOTES: [[@LINE-3]]:12: note: 'x' declared here
+  // CHECK-NOTES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y'
+  // CHECK-NOTES: [[@LINE-5]]:19: note: 'y' declared here
   f(/*y=*/0, /*z=*/0);
   // CHECK-FIXES: {{^}}  f(/*y=*/0, /*z=*/0);
 
@@ -46,14 +46,17 @@
 void templates() {
   variadic(/*xxx=*/0, /*yyy=*/1);
   variadic2(/*zzU=*/0, /*xxx=*/1, /*yyy=*/2);
-  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: argument name 'zzU' in comment does not match parameter name 'zzz'
+  // CHECK-NOTES: [[@LINE-1]]:13: warning: argument name 'zzU' in comment does not match parameter name 'zzz'
+  // CHECK-NOTES: [[@LINE-2]]:13: note: FIX-IT applied suggested code changes
+  // CHECK-NOTES: :[[@LINE-7]]:20: note: 'zzz' declared here
   // CHECK-FIXES: variadic2(/*zzz=*/0, /*xxx=*/1, /*yyy=*/2);
 }
 
 #define FALSE 0
 void qqq(bool aaa);
 void f2() { qqq(/*bbb=*/FALSE); }
-// CHECK-MESSAGES: [[@LINE-1]]:17: warning: argument name 'bbb' in comment does not match parameter name 'aaa'
+// CHECK-NOTES: [[@LINE-1]]:17: warning: argument name 'bbb' in comment does not match parameter name 'aaa'
+// CHECK-NOTES: [[@LINE-3]]:15: note: 'aaa' declared here
 // CHECK-FIXES: void f2() { qqq(/*bbb=*/FALSE); }
 
 void f3(bool _with_underscores_);
@@ -64,26 +67,32 @@
 namespace ThisEditDistanceAboveThreshold {
 void f4

[clang-tools-extra] r342459 - [clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 03:21:33 2018
New Revision: 342459

URL: http://llvm.org/viewvc/llvm-project?rev=342459&view=rev
Log:
[clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp?rev=342459&r1=342458&r2=342459&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
 Tue Sep 18 03:21:33 2018
@@ -20,27 +20,34 @@ template  constexpr bool jus
 class Test1 {
 public:
   template  Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template  Test1(T &&n, int i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template ::type>
   Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template 
   Test1(T &&n, typename foo::enable_if::type i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   Test1(const Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &&other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
 };
 
 template  class Test2 {
@@ -96,10 +103,10 @@ private:
 class Test4 {
 public:
   template  Test4(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 
   Test4(const Test4 &rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: copy constructor declared here
 };
 
 // Nothing can be hidden, the copy constructor is implicitly deleted.
@@ -114,10 +121,10 @@ public:
 class Test6 {
 public:
   template  Test6(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the move constructor
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the move constructor
 
   Test6(Test6 &&rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: move constructor declared here
 private:
   Test6(const Test6 &rhs);
 };
@@ -141,5 +148,5 @@ class variant {
 public:
   template  >
   constexpr variant(_Arg&& __arg) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding 
reference can hide the copy and move cons

[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 165918.
ioeric marked 6 inline comments as done.
ioeric added a comment.

- addressed review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D5

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,13 +45,13 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr()).first;
+  return indexHeaderSymbols(AST.getASTContext(), AST.getPreprocessorPtr());
 }
 
+// FIXME: This should return a FileIndex with both preamble and main index.
 std::unique_ptr TestTU::index() const {
   auto AST = build();
-  auto Content = indexAST(AST.getASTContext(), AST.getPreprocessorPtr(),
-  AST.getLocalTopLevelDecls());
+  auto Content = indexMainDecls(AST, AST.getLocalTopLevelDecls());
   return MemIndex::build(std::move(Content.first), std::move(Content.second));
 }
 
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -231,7 +231,7 @@
 TEST(MergeIndexTest, Refs) {
   FileIndex Dyn({"unittest"});
   FileIndex StaticIndex({"unittest"});
-  auto MergedIndex = mergeIndex(&Dyn, &StaticIndex);
+  auto MergedIndex = mergeIndex(&Dyn.index(), &StaticIndex.index());
 
   const char *HeaderCode = "class Foo;";
   auto HeaderSymbols = TestTU::withHeaderCode("class Foo;").headerSymbols();
@@ -244,29 +244,26 @@
   Test.Code = Test1Code.code();
   Test.Filename = "test.cc";
   auto AST = Test.build();
-  Dyn.update(Test.Filename, &AST.getASTContext(), AST.getPreprocessorPtr(),
- AST.getLocalTopLevelDecls());
+  Dyn.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
 
   // Build static index for test.cc.
   Test.HeaderCode = HeaderCode;
   Test.Code = "// static\nclass Foo {};";
   Test.Filename = "test.cc";
   auto StaticAST = Test.build();
   // Add stale refs for test.cc.
-  StaticIndex.update(Test.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test.Filename, StaticAST,
+ StaticAST.getLocalTopLevelDecls());
 
   // Add refs for test2.cc
   Annotations Test2Code(R"(class $Foo[[Foo]] {};)");
   TestTU Test2;
   Test2.HeaderCode = HeaderCode;
   Test2.Code = Test2Code.code();
   Test2.Filename = "test2.cc";
   StaticAST = Test2.build();
-  StaticIndex.update(Test2.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test2.Filename, StaticAST,
+ StaticAST.getLocalTopLevelDecls());
 
   RefsRequest Request;
   Request.IDs = {Foo.ID};
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -119,10 +119,10 @@
   EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
 }
 
-std::vector match(const SymbolIndex &I,
+std::vector match(const FileIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
-  I.fuzzyFind(Req, [&](const Symbol &Sym) {
+  I.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 Matches.push_back((Sym.Scope + Sym.Name).str());
   });
   return Matches;
@@ -135,7 +135,8 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = Code;
   auto AST = File.build();
-  M.update(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
+  M.updatePreamble(File.Filename, AST.getASTContext(),
+   AST.getPreprocessorPtr());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -145,7 +146,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
 SeenSymbol = true;
   });
@@ -182,25 +183,6 @@
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X", "ns::ff"));
 }
 
-TEST(FileIndexTest, RemoveAST) {
-  FileIndex M;
-  update(M, "f1", "namespace ns { void f() {} class X {}; }");
-
-  FuzzyFindRequest Req;
-  Req.Query = "";
-  Req.Scopes = {"ns::"};
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));
-
-  M.update("f1.cpp", nullptr, nullptr);
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre());
-}
-
-TEST(FileIndexTest, RemoveNonExisting) {
-  FileIndex M;
-  M.

[PATCH] D52225: [clang] Implement Override Suggestions in Sema.

2018-09-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, ilya-biryukov.
Herald added a subscriber: cfe-commits.

In clangd we had a new type of completion suggestions for cpp
class/struct/unions that will show override signatures for virtual methods in
base classes. This patch implements it in sema because it is hard to deduce more
info about completion token outside of Sema and handle itchy cases.

See the patch https://reviews.llvm.org/D50898 for more info on the 
functionality.

In addition to above patch this one also converts the suggestion into a
CK_Pattern with whole insertion text as the name of the suggestion and factors
out CodeCompletionString generation for declerations so that it can be re-used
by others.


Repository:
  rC Clang

https://reviews.llvm.org/D52225

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  lib/Sema/SemaCodeComplete.cpp

Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1596,6 +1596,66 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+static void AddOverrideResults(ResultBuilder &Results,
+   const CodeCompletionContext &CCContext,
+   CodeCompletionBuilder &Builder, Sema &S) {
+  const auto *CR = llvm::dyn_cast(S.CurContext);
+  // If not inside a class/struct/union return empty.
+  if (!CR)
+return;
+  // First store overrides within current class.
+  // These are stored by name to make querying fast in the later step.
+  llvm::StringMap> Overrides;
+  for (auto *Method : CR->methods()) {
+if (!Method->isVirtual() || !Method->getIdentifier())
+  continue;
+Overrides[Method->getName()].push_back(Method);
+  }
+
+  for (const auto &Base : CR->bases()) {
+const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
+if (!BR)
+  continue;
+for (auto *Method : BR->methods()) {
+  if (!Method->isVirtual() || !Method->getIdentifier())
+continue;
+  const auto it = Overrides.find(Method->getName());
+  bool IsOverriden = false;
+  if (it != Overrides.end()) {
+for (auto *MD : it->second) {
+  // If the method in current body is not an overload of this virtual
+  // function, then it overrides this one.
+  if (!S.IsOverload(MD, Method, false)) {
+IsOverriden = true;
+break;
+  }
+}
+  }
+  if (!IsOverriden) {
+std::string OverrideSignature;
+llvm::raw_string_ostream OS(OverrideSignature);
+CodeCompletionResult CCR(Method, 0);
+PrintingPolicy Policy =
+getCompletionPrintingPolicy(S.getASTContext(), S.getPreprocessor());
+CCR.createCodeCompletionStringForDecl(
+S.getPreprocessor(), S.getASTContext(), Builder,
+false, CCContext, Policy);
+for(const auto& C : *Builder.TakeString()) {
+  if (C.Kind == CodeCompletionString::CK_Optional)
+continue;
+  OS << C.Text;
+  if (C.Kind == CodeCompletionString::CK_ResultType)
+OS << ' ';
+}
+OS << " override";
+Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(OS.str()));
+Results.AddResult(CodeCompletionResult(Builder.TakeString(), Method,
+   CCP_CodePattern));
+  }
+}
+  }
+}
+
 /// Add language constructs that show up for "ordinary" names.
 static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
Scope *S,
@@ -1704,6 +1764,9 @@
 if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);
 Results.AddResult(Result(Builder.TakeString()));
+
+AddOverrideResults(Results, CodeCompletionContext::CCC_ClassStructUnion,
+   Builder, SemaRef);
   }
 }
 LLVM_FALLTHROUGH;
@@ -2791,48 +2854,11 @@
   return Result.TakeString();
 }
 
-/// If possible, create a new code completion string for the given
-/// result.
-///
-/// \returns Either a new, heap-allocated code completion string describing
-/// how to use this result, or NULL to indicate that the string or name of the
-/// result is all that is needed.
-CodeCompletionString *
-CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
- Preprocessor &PP,
- const CodeCompletionContext &CCContext,
-   CodeCompletionAllocator &Allocator,
-   CodeCompletionTUInfo &CCTUInfo,
-   bool IncludeBriefComments) {
-  if (Kind == RK_Macro)
-return CreateCodeCompletionStringForMacro(PP, Allocator, CCTUInfo);
-
-  CodeCompletionBuilder Result(Allocator, CC

[PATCH] D52186: [clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342459: [clang-tidy] use CHECK-NOTES in 
bugprone-forwarding-reference-overload (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52186

Files:
  
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp


Index: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
@@ -20,27 +20,34 @@
 class Test1 {
 public:
   template  Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template  Test1(T &&n, int i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template ::type>
   Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template 
   Test1(T &&n, typename foo::enable_if::type i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   Test1(const Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &&other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
 };
 
 template  class Test2 {
@@ -96,10 +103,10 @@
 class Test4 {
 public:
   template  Test4(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 
   Test4(const Test4 &rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: copy constructor declared here
 };
 
 // Nothing can be hidden, the copy constructor is implicitly deleted.
@@ -114,10 +121,10 @@
 class Test6 {
 public:
   template  Test6(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the move constructor
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the move constructor
 
   Test6(Test6 &&rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: move constructor declared here
 private:
   Test6(const Test6 &rhs);
 };
@@ -141,5 +148,5 @@
 public:
   template  >
   constexpr variant(_Arg&& __arg) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 };


Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-over

[PATCH] D52186: [clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE342459: [clang-tidy] use CHECK-NOTES in 
bugprone-forwarding-reference-overload (authored by JonasToth, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52186?vs=165806&id=165920#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52186

Files:
  test/clang-tidy/bugprone-forwarding-reference-overload.cpp


Index: test/clang-tidy/bugprone-forwarding-reference-overload.cpp
===
--- test/clang-tidy/bugprone-forwarding-reference-overload.cpp
+++ test/clang-tidy/bugprone-forwarding-reference-overload.cpp
@@ -20,27 +20,34 @@
 class Test1 {
 public:
   template  Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template  Test1(T &&n, int i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template ::type>
   Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template 
   Test1(T &&n, typename foo::enable_if::type i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   Test1(const Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &&other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
 };
 
 template  class Test2 {
@@ -96,10 +103,10 @@
 class Test4 {
 public:
   template  Test4(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 
   Test4(const Test4 &rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: copy constructor declared here
 };
 
 // Nothing can be hidden, the copy constructor is implicitly deleted.
@@ -114,10 +121,10 @@
 class Test6 {
 public:
   template  Test6(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the move constructor
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the move constructor
 
   Test6(Test6 &&rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: move constructor declared here
 private:
   Test6(const Test6 &rhs);
 };
@@ -141,5 +148,5 @@
 public:
   template  >
   constexpr variant(_Arg&& __arg) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 };


Index: test/clang-tidy/bugprone-forwarding-reference-overload.cpp
===
--- test/clang-tidy/bugprone-forwarding-reference-overload.cpp
+++ test/clang-tidy/bugprone-forwarding-reference-overload.cpp
@@ -20,27 +20,34 @@
 class Test1 {
 public:
   template  Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning:

[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/index/FileIndex.h:121
 std::pair
 indexAST(ASTContext &AST, std::shared_ptr PP,
  llvm::ArrayRef URISchemes = {});

sammccall wrote:
> indexPreamble would be clearer I think.
What about `indexHeaderSymbols`? `indexPreamble` seems to require understanding 
of how preamble is built, but it doesn't seem to matter here if `AST` was built 
from preamble or not. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D5



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


[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/FileIndex.h:121
 std::pair
 indexAST(ASTContext &AST, std::shared_ptr PP,
  llvm::ArrayRef URISchemes = {});

ioeric wrote:
> sammccall wrote:
> > indexPreamble would be clearer I think.
> What about `indexHeaderSymbols`? `indexPreamble` seems to require 
> understanding of how preamble is built, but it doesn't seem to matter here if 
> `AST` was built from preamble or not. 
`indexHeaderSymbols` is better, SGTM.

I kind of meant the "conceptual" preamble here - but headers is more accurate 
(mid-file #includes are possible), and has no risk of confusion with the 
concrete cacheable preamble.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D5



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


[clang-tools-extra] r342460 - [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Sep 18 03:30:44 2018
New Revision: 342460

URL: http://llvm.org/viewvc/llvm-project?rev=342460&view=rev
Log:
[clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

Summary:
FileIndex now provides explicit interfaces for preamble and main file updates.
This avoids growing parameter list when preamble and main symbols diverge
further (e.g. D52078). This also gets rid of the hack in `indexAST` that
inferred main file index based on `TopLevelDecls`.

Also separate `indexMainDecls` from `indexAST`.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=342460&r1=342459&r2=342460&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Sep 18 03:30:44 2018
@@ -14,6 +14,7 @@
 #include "SourceCode.h"
 #include "Trace.h"
 #include "XRefs.h"
+#include "index/FileIndex.h"
 #include "index/Merge.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -70,59 +71,23 @@ public:
 };
 } // namespace
 
-/// The dynamic index tracks symbols visible in open files.
-/// For boring reasons, it doesn't implement SymbolIndex directly - use 
index().
-class ClangdServer::DynamicIndex {
-public:
-  DynamicIndex(std::vector URISchemes)
-  : PreambleIdx(URISchemes), MainFileIdx(URISchemes),
-MergedIndex(mergeIndex(&MainFileIdx, &PreambleIdx)) {}
-
-  const SymbolIndex &index() const { return *MergedIndex; }
-
-  // Returns callbacks that can be used to update the index with new ASTs.
-  // Index() presents a merged view of the supplied main-file and preamble 
ASTs.
-  std::unique_ptr makeUpdateCallbacks() {
-struct CB : public ParsingCallbacks {
-  CB(ClangdServer::DynamicIndex *This) : This(This) {}
-  DynamicIndex *This;
-
-  void onPreambleAST(PathRef Path, ASTContext &Ctx,
- std::shared_ptr PP) override {
-This->PreambleIdx.update(Path, &Ctx, std::move(PP));
-  }
-
-  void onMainAST(PathRef Path, ParsedAST &AST) override {
-This->MainFileIdx.update(Path, &AST.getASTContext(),
- AST.getPreprocessorPtr(),
- AST.getLocalTopLevelDecls());
-  }
-};
-return llvm::make_unique(this);
+// Returns callbacks that can be used to update the FileIndex with new ASTs.
+std::unique_ptr makeUpdateCallbacks(FileIndex *FIndex) {
+  struct CB : public ParsingCallbacks {
+CB(FileIndex *FIndex) : FIndex(FIndex) {}
+FileIndex *FIndex;
+
+void onPreambleAST(PathRef Path, ASTContext &Ctx,
+   std::shared_ptr PP) override {
+  FIndex->updatePreamble(Path, Ctx, std::move(PP));
+}
+
+void onMainAST(PathRef Path, ParsedAST &AST) override {
+  FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls());
+}
   };
-
-private:
-  // Contains information from each file's preamble only.
-  // These are large, but update fairly infrequently (preambles are stable).
-  // Missing information:
-  //  - symbol refs (these are always "from the main file")
-  //  - definition locations in the main file
-  //
-  // FIXME: Because the preambles for different TUs have large overlap and
-  // FileIndex doesn't deduplicate, this uses lots of extra RAM.
-  // The biggest obstacle in fixing this: the obvious approach of partitioning
-  // by declaring file (rather than main file) fails if headers provide
-  // different symbols based on preprocessor state.
-  FileIndex PreambleIdx;
-  // Contains information from each file's main AST.
-  // These are updated frequently (on file change), but are relatively small.
-  // Mostly contains:
-  //  - refs to symbols declared in the preamble and referenced from main
-  //  - symbols declared both in the main file and the preamble
-  // (Note that symbols *only* in the main file are not indexed).
-  FileIndex MainFileIdx;
-  std::unique_ptr MergedIndex;
-};
+  return llvm::make_unique(FIndex);
+}
 
 ClangdServer::Options ClangdServer::optsForTest() {
   ClangdServer::Options Opts;
@@ -139,9 +104,8 @@ ClangdServer::ClangdServer(GlobalCompila
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
   ResourceDir(Opts.ResourceDir ? Opts.ResourceDi

[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE342460: [clangd] Merge ClangdServer::DynamicIndex into 
FileIndex. NFC. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D5?vs=165918&id=165923#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D5

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,13 +45,13 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr()).first;
+  return indexHeaderSymbols(AST.getASTContext(), AST.getPreprocessorPtr());
 }
 
+// FIXME: This should return a FileIndex with both preamble and main index.
 std::unique_ptr TestTU::index() const {
   auto AST = build();
-  auto Content = indexAST(AST.getASTContext(), AST.getPreprocessorPtr(),
-  AST.getLocalTopLevelDecls());
+  auto Content = indexMainDecls(AST, AST.getLocalTopLevelDecls());
   return MemIndex::build(std::move(Content.first), std::move(Content.second));
 }
 
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -119,10 +119,10 @@
   EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
 }
 
-std::vector match(const SymbolIndex &I,
+std::vector match(const FileIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
-  I.fuzzyFind(Req, [&](const Symbol &Sym) {
+  I.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 Matches.push_back((Sym.Scope + Sym.Name).str());
   });
   return Matches;
@@ -135,7 +135,8 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = Code;
   auto AST = File.build();
-  M.update(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
+  M.updatePreamble(File.Filename, AST.getASTContext(),
+   AST.getPreprocessorPtr());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -145,7 +146,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
 SeenSymbol = true;
   });
@@ -182,25 +183,6 @@
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X", "ns::ff"));
 }
 
-TEST(FileIndexTest, RemoveAST) {
-  FileIndex M;
-  update(M, "f1", "namespace ns { void f() {} class X {}; }");
-
-  FuzzyFindRequest Req;
-  Req.Query = "";
-  Req.Scopes = {"ns::"};
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));
-
-  M.update("f1.cpp", nullptr, nullptr);
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre());
-}
-
-TEST(FileIndexTest, RemoveNonExisting) {
-  FileIndex M;
-  M.update("no.cpp", nullptr, nullptr);
-  EXPECT_THAT(match(M, FuzzyFindRequest()), UnorderedElementsAre());
-}
-
 TEST(FileIndexTest, ClassMembers) {
   FileIndex M;
   update(M, "f1", "class X { static int m1; int m2; static void f(); };");
@@ -218,7 +200,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 EXPECT_TRUE(Sym.IncludeHeaders.empty());
 SeenSymbol = true;
   });
@@ -242,7 +224,7 @@
   Req.Query = "";
   bool SeenVector = false;
   bool SeenMakeVector = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 if (Sym.Name == "vector") {
   EXPECT_EQ(Sym.Signature, "");
   EXPECT_EQ(Sym.CompletionSnippetSuffix, "<${1:class Ty}>");
@@ -296,7 +278,7 @@
   [&](ASTContext &Ctx, std::shared_ptr PP) {
 EXPECT_FALSE(IndexUpdated) << "Expected only a single index update";
 IndexUpdated = true;
-Index.update(FooCpp, &Ctx, std::move(PP));
+Index.updatePreamble(FooCpp, Ctx, std::move(PP));
   });
   ASSERT_TRUE(IndexUpdated);
 
@@ -332,18 +314,16 @@
   Test.Code = MainCode.code();
   Test.Filename = "test.cc";
   auto AST = Test.build();
-  Index.update(Test.Filename, &AST.getASTContext(), AST.getPreprocessorPtr(),
-   AST.getLocalTopLevelDecls());
+  Index.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
   // Add test2.cc
   TestTU Test2;
   Test2.HeaderCode = HeaderCode;
   Test2.Code = MainCode.code();
   Test2.Filename = "test2.cc";
   AST = Test2.build();
-  Index.update(Test2.Filename, &AST.getASTContext(), AST.getPreprocessorPtr(),
-   AST.getLocalTopLevelDecls());
+  Index.updateMain(Test2.Filename

[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342460: [clangd] Merge ClangdServer::DynamicIndex into 
FileIndex. NFC. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D5

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/index/FileIndex.cpp
  clang-tools-extra/trunk/clangd/index/FileIndex.h
  clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
  clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
  clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Index: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
@@ -231,7 +231,7 @@
 TEST(MergeIndexTest, Refs) {
   FileIndex Dyn({"unittest"});
   FileIndex StaticIndex({"unittest"});
-  auto MergedIndex = mergeIndex(&Dyn, &StaticIndex);
+  auto MergedIndex = mergeIndex(&Dyn.index(), &StaticIndex.index());
 
   const char *HeaderCode = "class Foo;";
   auto HeaderSymbols = TestTU::withHeaderCode("class Foo;").headerSymbols();
@@ -244,29 +244,26 @@
   Test.Code = Test1Code.code();
   Test.Filename = "test.cc";
   auto AST = Test.build();
-  Dyn.update(Test.Filename, &AST.getASTContext(), AST.getPreprocessorPtr(),
- AST.getLocalTopLevelDecls());
+  Dyn.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
 
   // Build static index for test.cc.
   Test.HeaderCode = HeaderCode;
   Test.Code = "// static\nclass Foo {};";
   Test.Filename = "test.cc";
   auto StaticAST = Test.build();
   // Add stale refs for test.cc.
-  StaticIndex.update(Test.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test.Filename, StaticAST,
+ StaticAST.getLocalTopLevelDecls());
 
   // Add refs for test2.cc
   Annotations Test2Code(R"(class $Foo[[Foo]] {};)");
   TestTU Test2;
   Test2.HeaderCode = HeaderCode;
   Test2.Code = Test2Code.code();
   Test2.Filename = "test2.cc";
   StaticAST = Test2.build();
-  StaticIndex.update(Test2.Filename, &StaticAST.getASTContext(),
- StaticAST.getPreprocessorPtr(),
- StaticAST.getLocalTopLevelDecls());
+  StaticIndex.updateMain(Test2.Filename, StaticAST,
+ StaticAST.getLocalTopLevelDecls());
 
   RefsRequest Request;
   Request.IDs = {Foo.ID};
Index: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
@@ -119,10 +119,10 @@
   EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
 }
 
-std::vector match(const SymbolIndex &I,
+std::vector match(const FileIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
-  I.fuzzyFind(Req, [&](const Symbol &Sym) {
+  I.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 Matches.push_back((Sym.Scope + Sym.Name).str());
   });
   return Matches;
@@ -135,7 +135,8 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = Code;
   auto AST = File.build();
-  M.update(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
+  M.updatePreamble(File.Filename, AST.getASTContext(),
+   AST.getPreprocessorPtr());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -145,7 +146,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
 SeenSymbol = true;
   });
@@ -182,25 +183,6 @@
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X", "ns::ff"));
 }
 
-TEST(FileIndexTest, RemoveAST) {
-  FileIndex M;
-  update(M, "f1", "namespace ns { void f() {} class X {}; }");
-
-  FuzzyFindRequest Req;
-  Req.Query = "";
-  Req.Scopes = {"ns::"};
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));
-
-  M.update("f1.cpp", nullptr, nullptr);
-  EXPECT_THAT(match(M, Req), UnorderedElementsAre());
-}
-
-TEST(FileIndexTest, RemoveNonExisting) {
-  FileIndex M;
-  M.update("no.cpp", nullptr, nullptr);
-  EXPECT_THAT(match(M, FuzzyFindRequest()), UnorderedElementsAre());
-}
-
 TEST(FileIndexTest, ClassMembers) {
   FileIndex M;
   update(M, "f1", "class X { static int m1; int m2; static void f(); };");
@@ -218,7 +200,7 @@
   FuzzyFindRequest Req;
   Req.Query = "";
   bool SeenSymbol = false;
-  M.fuzzyFind(Req, [&](const Symbol &Sym) {
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
 E

[PATCH] D52226: [clangd] Remove override result handling logic from clangd

2018-09-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
kadircet added a dependency: D52225: [clang] Implement Override Suggestions in 
Sema..

Since we plan to move handling of override suggestions to Sema with
https://reviews.llvm.org/D52225 this patch just makes sure clangd-side has no 
logic related to that
anymore and updates tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52226

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -1806,6 +1806,58 @@
   )cpp");
 }
 
+TEST(CompletionTest, SuggestOverridesWithPartialMatches) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto File = testPath("foo.cpp");
+  const Annotations Test(R"cpp(
+  class A {
+   public:
+virtual void vfunc(bool param);
+virtual void vfunc(bool param, int p);
+void func(bool param);
+  };
+  class B : public A {
+  virtual int ttt(bool param) const;
+  void vfunc(bool param, int p) override;
+  };
+  class C : public B {
+   public:
+void vfunc(bool param) override;
+$1^vo$2^id $3^
+  };
+  )cpp");
+  runAddDocument(Server, File, Test.code());
+  {
+const auto Results = completions(Server, Test.code(), Test.point("1"));
+EXPECT_THAT(
+Results.Completions,
+AllOf(Contains(Labeled("void vfunc(bool param, int p) override")),
+  Not(Contains(Labeled("void vfunc(bool param) override"))),
+  Contains(Labeled("int ttt(bool param) const override";
+  }
+  {
+const auto Results = completions(Server, Test.code(), Test.point("2"));
+EXPECT_THAT(
+Results.Completions,
+AllOf(Contains(Labeled("void vfunc(bool param, int p) override")),
+  Not(Contains(Labeled("void vfunc(bool param) override"))),
+  Not(Contains(Labeled("int ttt(bool param) const override");
+  }
+  {
+const auto Results = completions(Server, Test.code(), Test.point("3"));
+EXPECT_THAT(
+Results.Completions,
+AllOf(Not(Contains(Labeled("void vfunc(bool param, int p) override"))),
+  Not(Contains(Labeled("void vfunc(bool param) override"))),
+  Not(Contains(Labeled("int ttt(bool param) const override");
+  }
+}
+
+
 TEST(SpeculateCompletionFilter, Filters) {
   Annotations F(R"cpp($bof^
   $bol^
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -195,55 +195,6 @@
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
 }
 
-// First traverses all method definitions inside current class/struct/union
-// definition. Than traverses base classes to find virtual methods that haven't
-// been overriden within current context.
-// FIXME(kadircet): Currently we cannot see declarations below completion point.
-// It is because Sema gets run only upto completion point. Need to find a
-// solution to run it for the whole class/struct/union definition.
-static std::vector
-getNonOverridenMethodCompletionResults(const DeclContext *DC, Sema *S) {
-  const auto *CR = llvm::dyn_cast(DC);
-  // If not inside a class/struct/union return empty.
-  if (!CR)
-return {};
-  // First store overrides within current class.
-  // These are stored by name to make querying fast in the later step.
-  llvm::StringMap> Overrides;
-  for (auto *Method : CR->methods()) {
-if (!Method->isVirtual() || !Method->getIdentifier())
-  continue;
-Overrides[Method->getName()].push_back(Method);
-  }
-
-  std::vector Results;
-  for (const auto &Base : CR->bases()) {
-const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
-if (!BR)
-  continue;
-for (auto *Method : BR->methods()) {
-  if (!Method->isVirtual() || !Method->getIdentifier())
-continue;
-  const auto it = Overrides.find(Method->getName());
-  bool IsOverriden = false;
-  if (it != Overrides.end()) {
-for (auto *MD : it->second) {
-  // If the method in current body is not an overload of this virtual
-  // function, then it overrides this one.
-  if (!S->IsOverload(MD, Method, false)) {
-IsOverriden = true;
-break;
-  }
-}
-  }
-  if (!IsOverriden)
-Results.emplace_back(Method, 0);
-}
-  }
-
-  return Results;
-}
-
 /// A code completion result, in clang-native form.
 /// It may be promoted to a CompletionItem if it's among the top-ranked results.
 struct CompletionCandidate {
@@ -253,9 +204,6 @@
   const Symbol *IndexResult = nullptr;
   llvm::SmallVec

[PATCH] D52187: [clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 165926.
JonasToth added a comment.

- shorten warning checks


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52187

Files:
  test/clang-tidy/bugprone-unused-return-value-custom.cpp
  test/clang-tidy/bugprone-unused-return-value.cpp

Index: test/clang-tidy/bugprone-unused-return-value.cpp
===
--- test/clang-tidy/bugprone-unused-return-value.cpp
+++ test/clang-tidy/bugprone-unused-return-value.cpp
@@ -74,93 +74,116 @@
 
 void warning() {
   std::async(increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning
 
   std::async(std::launch::async, increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   Foo F;
   std::launder(&F);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::remove_if(nullptr, nullptr, nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::unique(nullptr, nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::unique_ptr UPtr;
   UPtr.release();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::string Str;
   Str.empty();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::vector Vec;
   Vec.empty();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   // test discarding return values inside different kinds of statements
 
   auto Lambda = [] { std::remove(nullptr, nullptr, 1); };
-  // CHECK-MESSAGES: [[@LINE-1]]:22: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:22: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:22: note: cast {{.*}} this warning
 
   if (true)
 std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   else if (true)
 std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   else
 std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
 
   while (true)
 std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} shoul

[PATCH] D52228: [clang-tidy] use CHECK-NOTES in tests for bugprone-use-after-move

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth created this revision.
JonasToth added reviewers: alexfh, aaron.ballman, hokein.
Herald added subscribers: cfe-commits, xazax.hun.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52228

Files:
  test/clang-tidy/bugprone-use-after-move.cpp

Index: test/clang-tidy/bugprone-use-after-move.cpp
===
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -125,18 +125,18 @@
   a.foo();
   A other_a = std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:15: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
   a.foo();
   A other_a = std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:15: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
   a.foo();
 }
 
@@ -146,28 +146,28 @@
 A a;
 std::move(a);
 std::move(a);
-// CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'a' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:15: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   // This is also true if the move itself turns into the use on the second loop
   // iteration.
   {
 A a;
 for (int i = 0; i < 10; ++i) {
   std::move(a);
-  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-2]]:7: note: move occurred here
-  // CHECK-MESSAGES: [[@LINE-3]]:17: note: the use happens in a later loop
+  // CHECK-NOTES: [[@LINE-1]]:17: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-2]]:7: note: move occurred here
+  // CHECK-NOTES: [[@LINE-3]]:17: note: the use happens in a later loop
 }
   }
 }
 
 // Checks also works on function parameters that have a use-after move.
 void parameters(A a) {
   std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:3: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:3: note: move occurred here
 }
 
 void standardSmartPtr() {
@@ -180,38 +180,38 @@
 ptr.get();
 static_cast(ptr);
 *ptr;
-// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-5]]:5: note: move occurred here
   }
   {
 std::unique_ptr ptr;
 std::move(ptr);
 ptr->foo();
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 std::unique_ptr ptr;
 std::move(ptr);
 ptr[0];
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 std::shared_ptr ptr;
 std::move(ptr);
 ptr.get();
 static_cast(ptr);
 *ptr;
-// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-5]]:5: note: move occurred here
   }
   {
 std::shared_ptr ptr;
 std::move(ptr);
 ptr->foo();
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 // std::weak_ptr<> cannot be dereferenced directly, so we only check that
@@ -252,8 +252,8 @@
 } ptr;
 std::move(ptr);
 ptr.get();
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
 }
 
@@ -263,18 +263,18 @@
 A a;
 std::move(a);
 a.foo();
-// CHECK-MESSAGES: [[@

[clang-tools-extra] r342468 - [clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 04:49:20 2018
New Revision: 342468

URL: http://llvm.org/viewvc/llvm-project?rev=342468&view=rev
Log:
[clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp?rev=342468&r1=342467&r2=342468&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp 
Tue Sep 18 04:49:20 2018
@@ -47,32 +47,40 @@ void fun(int);
 
 void warning() {
   fun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function 
should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence 
this warning
 
   (fun());
-  // CHECK-MESSAGES: [[@LINE-1]]:4: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:4: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:4: note: cast {{.*}} this warning
 
   ns::Outer::Inner ObjA1;
   ObjA1.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::AliasName::Inner ObjA2;
   ObjA2.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Derived ObjA3;
   ObjA3.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Type::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate ObjA4;
   ObjA4.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp?rev=342468&r1=342467&r2=342468&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp 
Tue Sep 18 04:49:20 2018
@@ -74,93 +74,116 @@ void useFuture(const std::future &fut);
 
 void warning() {
   std::async(increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function 
should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence 
this warning
 
   std::async(std::launch::async, increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   Foo F;
   std::launder(&F);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
f

[PATCH] D52187: [clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342468: [clang-tidy] use CHECK-NOTES in 
bugprone-unused-return-value (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52187

Files:
  
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
@@ -47,32 +47,40 @@
 
 void warning() {
   fun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning
 
   (fun());
-  // CHECK-MESSAGES: [[@LINE-1]]:4: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:4: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:4: note: cast {{.*}} this warning
 
   ns::Outer::Inner ObjA1;
   ObjA1.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::AliasName::Inner ObjA2;
   ObjA2.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Derived ObjA3;
   ObjA3.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Type::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate ObjA4;
   ObjA4.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
@@ -74,93 +74,116 @@
 
 void warning() {
   std::async(increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning
 
   std::async(std::launch::async, increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   Foo F;
   std::launder(&F);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::remove(nullptr, nullptr, 1);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   std::remove_if(nullptr, nullptr, nullptr);
-  // CHEC

[PATCH] D52229: [clang-tidy] use CHECK-NOTES in tests for bugprone suspicious-enum-usage

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth created this revision.
JonasToth added reviewers: alexfh, aaron.ballman, hokein.
Herald added subscribers: cfe-commits, xazax.hun.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52229

Files:
  test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
  test/clang-tidy/bugprone-suspicious-enum-usage.cpp


Index: test/clang-tidy/bugprone-suspicious-enum-usage.cpp
===
--- test/clang-tidy/bugprone-suspicious-enum-usage.cpp
+++ test/clang-tidy/bugprone-suspicious-enum-usage.cpp
@@ -54,10 +54,10 @@
   int emptytest = EmptyVal | B;
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
   if (I | Y)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum 
types
 }
 
 int dont_trigger() {
Index: test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
===
--- test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
+++ test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
@@ -10,23 +10,23 @@
   G = 63
 };
 
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but a literal is not power-of-2
-// CHECK-MESSAGES: :76:7: note: used here as a bitmask
+// CHECK-NOTES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but a literal is not power-of-2
+// CHECK-NOTES: :76:7: note: used here as a bitmask
 enum X {
   X = 8,
   Y = 16,
   Z = 4,
   ZZ = 3
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2 
[bugprone-suspicious-enum-usage]
-// CHECK-MESSAGES: :70:13: note: used here as a bitmask
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2 
[bugprone-suspicious-enum-usage]
+// CHECK-NOTES: :70:13: note: used here as a bitmask
 };
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but some literals are not power-of-2
-// CHECK-MESSAGES: :73:8: note: used here as a bitmask
+// CHECK-NOTES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but some literals are not power-of-2
+// CHECK-NOTES: :73:8: note: used here as a bitmask
 enum PP {
   P = 2,
   Q = 3,
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2
-  // CHECK-MESSAGES: :65:11: note: used here as a bitmask
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2
+  // CHECK-NOTES: :65:11: note: used here as a bitmask
   R = 4,
   S = 8,
   T = 16,
@@ -58,10 +58,10 @@
 int trigger() {
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
   if (I | Y)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum 
types
   if (P + Q == R)
 return 1;
   else if ((S | R) == T)


Index: test/clang-tidy/bugprone-suspicious-enum-usage.cpp
===
--- test/clang-tidy/bugprone-suspicious-enum-usage.cpp
+++ test/clang-tidy/bugprone-suspicious-enum-usage.cpp
@@ -54,10 +54,10 @@
   int emptytest = EmptyVal | B;
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different enum types
+  // CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different enum types
   if (I | Y)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different enum types
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum types
 }
 
 int dont_trigger() {
Index: test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
===
--- test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
+++ test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
@@ -10,23 +10,23 @@
   G = 63
 };
 
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask (contains mostly power-of-2 literals) but a literal is not power-of-2
-// CHECK-MESSAGES: :76:7: note: used here as a bitmask
+// CHECK-NOTES: :[[@LINE+2]]:1: warning: enum t

[PATCH] D52230: [clang-tidy] use CHECK-NOTES in tests for bugprone-macro-repeated-side-effects

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth created this revision.
JonasToth added reviewers: alexfh, aaron.ballman, hokein.
Herald added subscribers: cfe-commits, xazax.hun.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52230

Files:
  test/clang-tidy/bugprone-macro-repeated-side-effects.c

Index: test/clang-tidy/bugprone-macro-repeated-side-effects.c
===
--- test/clang-tidy/bugprone-macro-repeated-side-effects.c
+++ test/clang-tidy/bugprone-macro-repeated-side-effects.c
@@ -3,45 +3,59 @@
 #define badA(x,y)  ((x)+((x)+(y))+(y))
 void bad(int ret, int a, int b) {
   ret = badA(a++, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
+  // CHECK-NOTES: :[[@LINE-4]]:9: note: macro 'badA' defined here
   ret = badA(++a, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-7]]:9: note: macro 'badA' defined here
   ret = badA(a--, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-10]]:9: note: macro 'badA' defined here
   ret = badA(--a, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
+  // CHECK-NOTES: :[[@LINE-13]]:9: note: macro 'badA' defined here
   ret = badA(a, b++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-16]]:9: note: macro 'badA' defined here
   ret = badA(a, ++b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-19]]:9: note: macro 'badA' defined here
   ret = badA(a, b--);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-22]]:9: note: macro 'badA' defined here
   ret = badA(a, --b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro argument 'y'
+  // CHECK-NOTES: :[[@LINE-25]]:9: note: macro 'badA' defined here
 }
 
 
 #define MIN(A,B) ((A) < (B) ? (A) : (B))// single ?:
 #define LIMIT(X,A,B) ((X) < (A) ? (A) : ((X) > (B) ? (B) : (X)))// two ?:
 void question(int x) {
   MIN(x++, 12);
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: side effects in the 1st macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-1]]:7: warning: side effects in the 1st macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-5]]:9: note: macro 'MIN' defined here
   MIN(34, x++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: side effects in the 2nd macro argument 'B'
+  // CHECK-NOTES: :[[@LINE-1]]:11: warning: side effects in the 2nd macro argument 'B'
+  // CHECK-NOTES: :[[@LINE-8]]:9: note: macro 'MIN' defined here
   LIMIT(x++, 0, 100);
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: side effects in the 1st macro argument 'X'
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: side effects in the 1st macro argument 'X'
+  // CHECK-NOTES: :[[@LINE-10]]:9: note: macro 'LIMIT' defined here
   LIMIT(20, x++, 100);
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: side effects in the 2nd macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: side effects in the 2nd macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-13]]:9: note: macro 'LIMIT' defined here
   LIMIT(20, 0, x++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: side effects in the 3rd macro argument 'B'
+  // CHECK-NOTES: :[[@LINE-1]]:16: warning: side effects in the 3rd macro argument 'B'
+  // CHECK-NOTES: :[[@LINE-16]]:9: note: macro 'LIMIT' defined here
 }
 
 // False positive: Repeated side effects is intentional.
 // It is hard to know when it's done by intention so right now we warn.
 #define UNROLL(A){A A}
 void fp1(int i) {
   UNROLL({ i++; });
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: side effects in the 1st macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-1]]:10: warning: side effects in the 1st macro argument 'A'
+  // CHECK-NOTES: :[[@LINE-4]]:9: note: macro 'UNROLL' defined here
 }
 
 // Do not produce a false positive on a strchr() macro. Explanation; Currently the '?'
@@ -66,11 

[PATCH] D52179: [clang-tidy] Replace redundant checks with an assert().

2018-09-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:551-552
 if (Decl->isMain() || !Decl->isUserProvided() ||
-Decl->isUsualDeallocationFunction() ||
-Decl->isCopyAssignmentOperator() || Decl->isMoveAssignmentOperator() ||
 Decl->size_overridden_methods() > 0)

tra wrote:
> aaron.ballman wrote:
> > Why are these being removed?
> D51808 changes signature of isUsualDeallocationFunction(), which made me 
> update the code here, which lead to @rsmith suggesting that this change is 
> redundant and could use cleaning up, which led to this change.
> 
> Any Decl which would return true for isUsualDeallocationFunction()  or for 
> is*Operator(), will always return nullptr for getIdentifier() because 
> D->getName().isIdentifier() would be false.
> 
> Speaking of which, the result of getIdentifier() is never used, so the check 
> should probably be D->isIdentifier() both in this function and in the caller.
> 
Ah, thank you for the explanation -- that makes sense.


https://reviews.llvm.org/D52179



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


[PATCH] D52200: Thread safety analysis: Handle ObjCIvarRefExpr in SExprBuilder::translate

2018-09-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rjmccall.
aaron.ballman added a comment.

Adding a reviewer who knows more about ObjC than I do.




Comment at: include/clang/Analysis/Analyses/ThreadSafetyCommon.h:400
   til::SExpr *translateMemberExpr(const MemberExpr *ME, CallingContext *Ctx);
+  til::SExpr *translateObjCIVarRefExpr(const ObjCIvarRefExpr *ME,
+   CallingContext *Ctx);

`ME` is kind of a poor name; can you switch to `IVRE` like you used in the 
implementation?



Comment at: lib/Analysis/ThreadSafetyCommon.cpp:362
+  til::Project *P = new (Arena) til::Project(E, D);
+  if (hasCppPointerType(BE))
+P->setArrow(true);

I feel like this will always return false. However, I wonder if 
`IVRE->getBase()->isArrow()` is more appropriate here?


Repository:
  rC Clang

https://reviews.llvm.org/D52200



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


[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/FileIndex.h:77
+  /// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
+  void updateMain(PathRef Path, ASTContext &AST,
+  std::shared_ptr PP,

sammccall wrote:
> can't this just take PathRef + ParsedAST?
> (same data, but clearer semantics)
You're still taking the top-level decls, these can just come from the ParsedAST 
though?


Repository:
  rL LLVM

https://reviews.llvm.org/D5



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


[PATCH] D50948: lambdas in modules: change storage for LambdaDefinitionData

2018-09-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande updated this revision to Diff 165947.
elsteveogrande added a comment.

Rebase past dependency commit C341499, fix a conflict


Repository:
  rC Clang

https://reviews.llvm.org/D50948

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/DeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp

Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -6010,7 +6010,7 @@
 
 void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
   auto &Data = D->data();
-  Record->push_back(Data.IsLambda);
+  Record->push_back(Data.hasLambdaData());  // lambda-specific data added below
   Record->push_back(Data.UserDeclaredConstructor);
   Record->push_back(Data.UserDeclaredSpecialMembers);
   Record->push_back(Data.Aggregate);
@@ -6068,8 +6068,6 @@
   if (ModulesDebugInfo)
 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D));
 
-  // IsLambda bit is already saved.
-
   Record->push_back(Data.NumBases);
   if (Data.NumBases > 0)
 AddCXXBaseSpecifiers(Data.bases());
@@ -6085,8 +6083,8 @@
   AddDeclRef(D->getFirstFriend());
 
   // Add lambda-specific data.
-  if (Data.IsLambda) {
-auto &Lambda = D->getLambdaData();
+  if (Data.hasLambdaData()) {
+auto &Lambda = *Data.LambdaData;
 Record->push_back(Lambda.Dependent);
 Record->push_back(Lambda.IsGenericLambda);
 Record->push_back(Lambda.CaptureDefault);
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1636,7 +1636,7 @@
 
 void ASTDeclReader::ReadCXXDefinitionData(
 struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) {
-  // Note: the caller has deserialized the IsLambda bit already.
+  // Note: the caller has deserialized the bit for `isLambda()` already.
   Data.UserDeclaredConstructor = Record.readInt();
   Data.UserDeclaredSpecialMembers = Record.readInt();
   Data.Aggregate = Record.readInt();
@@ -1703,10 +1703,10 @@
   assert(Data.Definition && "Data.Definition should be already set!");
   Data.FirstFriend = ReadDeclID();
 
-  if (Data.IsLambda) {
+  if (Data.hasLambdaData()) {
 using Capture = LambdaCapture;
 
-auto &Lambda = static_cast(Data);
+auto &Lambda = *Data.LambdaData;
 Lambda.Dependent = Record.readInt();
 Lambda.IsGenericLambda = Record.readInt();
 Lambda.CaptureDefault = Record.readInt();
@@ -1761,7 +1761,8 @@
   PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
 // We faked up this definition data because we found a class for which we'd
 // not yet loaded the definition. Replace it with the real thing now.
-assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
+assert(!DD.hasLambdaData() && !MergeDD.hasLambdaData() &&
+   "faked up lambda definition?");
 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
 
 // Don't change which declaration is the definition; that is required
@@ -1826,7 +1827,6 @@
   MATCH_FIELD(ImplicitCopyAssignmentHasConstParam)
   OR_FIELD(HasDeclaredCopyConstructorWithConstParam)
   OR_FIELD(HasDeclaredCopyAssignmentWithConstParam)
-  MATCH_FIELD(IsLambda)
 #undef OR_FIELD
 #undef MATCH_FIELD
 
@@ -1845,7 +1845,7 @@
   // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
   // lazily load it.
 
-  if (DD.IsLambda) {
+  if (DD.hasLambdaData()) {
 // FIXME: ODR-checking for merging lambdas (this happens, for instance,
 // when they occur within the body of a function template specialization).
   }
@@ -1860,17 +1860,17 @@
 }
 
 void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) {
-  struct CXXRecordDecl::DefinitionData *DD;
   ASTContext &C = Reader.getContext();
 
+  struct CXXRecordDecl::DefinitionData *DD =
+  new (C) struct CXXRecordDecl::DefinitionData(D);
+
   // Determine whether this is a lambda closure type, so that we can
-  // allocate the appropriate DefinitionData structure.
-  bool IsLambda = Record.readInt();
-  if (IsLambda)
-DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false,
- LCD_None);
-  else
-DD = new (C) struct CXXRecordDecl::DefinitionData(D);
+  // set the LambdaDefinitionData (into optional \c LambdaData field) as well.
+  bool isLambda = Record.readInt();
+  if (isLambda) {
+DD->SetLambdaDefinitionData(nullptr, false, false, LCD_None);
+  }
 
   CXXRecordDecl *Canon = D->getCanonicalDecl();
   // Set decl definition data before reading it, so that during deserialization
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -102,7 +102,7 @@
   ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
 

[PATCH] D50949: lambdas in modules: handle lambdas in .pcm [de]serialization

2018-09-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande updated this revision to Diff 165948.
elsteveogrande added a comment.

Rebase atop updated dependency https://reviews.llvm.org/D50948.  Small cleanups 
to this diff.


Repository:
  rC Clang

https://reviews.llvm.org/D50949

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/LambdaCapture.h
  lib/AST/DeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/Modules/merge-lambdas.cpp

Index: test/Modules/merge-lambdas.cpp
===
--- test/Modules/merge-lambdas.cpp
+++ test/Modules/merge-lambdas.cpp
@@ -49,3 +49,25 @@
 
 #pragma clang module import A
 void (*p)() = f();
+
+#pragma clang module build PR38531
+module PR38531 {}
+#pragma clang module contents
+#pragma clang module begin PR38531
+template 
+struct S {};
+struct Fun {
+  template ())>
+  Fun(F) {}
+};
+template 
+void foo(Fun=[]{}) {}
+struct T {
+  void func() {
+foo();
+  }
+};
+#pragma clang module end
+#pragma clang module endbuild
+#pragma clang module import PR38531
+S s;
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -6010,7 +6010,7 @@
 
 void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
   auto &Data = D->data();
-  Record->push_back(Data.IsLambda);
+  Record->push_back(Data.hasLambdaData());  // lambda-specific data added below
   Record->push_back(Data.UserDeclaredConstructor);
   Record->push_back(Data.UserDeclaredSpecialMembers);
   Record->push_back(Data.Aggregate);
@@ -6068,8 +6068,6 @@
   if (ModulesDebugInfo)
 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D));
 
-  // IsLambda bit is already saved.
-
   Record->push_back(Data.NumBases);
   if (Data.NumBases > 0)
 AddCXXBaseSpecifiers(Data.bases());
@@ -6085,8 +6083,8 @@
   AddDeclRef(D->getFirstFriend());
 
   // Add lambda-specific data.
-  if (Data.IsLambda) {
-auto &Lambda = D->getLambdaData();
+  if (Data.hasLambdaData()) {
+auto &Lambda = *Data.LambdaData;
 Record->push_back(Lambda.Dependent);
 Record->push_back(Lambda.IsGenericLambda);
 Record->push_back(Lambda.CaptureDefault);
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1636,7 +1636,7 @@
 
 void ASTDeclReader::ReadCXXDefinitionData(
 struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) {
-  // Note: the caller has deserialized the IsLambda bit already.
+  // Note: the caller has deserialized the bit for `isLambda()` already.
   Data.UserDeclaredConstructor = Record.readInt();
   Data.UserDeclaredSpecialMembers = Record.readInt();
   Data.Aggregate = Record.readInt();
@@ -1703,10 +1703,10 @@
   assert(Data.Definition && "Data.Definition should be already set!");
   Data.FirstFriend = ReadDeclID();
 
-  if (Data.IsLambda) {
+  if (Data.hasLambdaData()) {
 using Capture = LambdaCapture;
 
-auto &Lambda = static_cast(Data);
+auto &Lambda = *Data.LambdaData;
 Lambda.Dependent = Record.readInt();
 Lambda.IsGenericLambda = Record.readInt();
 Lambda.CaptureDefault = Record.readInt();
@@ -1761,7 +1761,6 @@
   PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
 // We faked up this definition data because we found a class for which we'd
 // not yet loaded the definition. Replace it with the real thing now.
-assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
 
 // Don't change which declaration is the definition; that is required
@@ -1826,7 +1825,6 @@
   MATCH_FIELD(ImplicitCopyAssignmentHasConstParam)
   OR_FIELD(HasDeclaredCopyConstructorWithConstParam)
   OR_FIELD(HasDeclaredCopyAssignmentWithConstParam)
-  MATCH_FIELD(IsLambda)
 #undef OR_FIELD
 #undef MATCH_FIELD
 
@@ -1845,9 +1843,41 @@
   // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
   // lazily load it.
 
-  if (DD.IsLambda) {
-// FIXME: ODR-checking for merging lambdas (this happens, for instance,
-// when they occur within the body of a function template specialization).
+  assert (DD.hasLambdaData() == MergeDD.hasLambdaData() &&
+  "Merging definitions, one of which is a lambda, the other not?");
+  if (DD.hasLambdaData() && MergeDD.hasLambdaData()) {
+auto &LDD = *DD.LambdaData;
+auto &MergeLDD = *MergeDD.LambdaData;
+
+#define MATCH_LAM_FIELD(Field) \
+DetectedOdrViolation |= LDD.Field != MergeLDD.Field;
+MATCH_LAM_FIELD(Dependent)
+MATCH_LAM_FIELD(IsGenericLambda)
+MATCH_LAM_FIELD(CaptureDefault)
+MATCH_LAM_FIELD(NumCaptures)
+MATCH_LAM_FIELD(NumExplicitCaptures)
+MATCH_LAM_FIELD(ManglingNumber)
+#undef MATCH_LAM_FIELD
+
+auto *C1 = LDD.Captures;

r342470 - cl-options.c: Fix negative -cfguard check

2018-09-18 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Sep 18 06:07:55 2018
New Revision: 342470

URL: http://llvm.org/viewvc/llvm-project?rev=342470&view=rev
Log:
cl-options.c: Fix negative -cfguard check

Modified:
cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/test/Driver/cl-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=342470&r1=342469&r2=342470&view=diff
==
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Tue Sep 18 06:07:55 2018
@@ -562,7 +562,7 @@
 
 // RUN: %clang_cl  -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s
 // RUN: %clang_cl /guard:cf- -### -- %s 2>&1 | FileCheck 
-check-prefix=NOCFGUARD %s
-// NOCFGUARD-NOT: -guardcf
+// NOCFGUARD-NOT: -cfguard
 
 // RUN: %clang_cl /guard:cf -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD 
%s
 // RUN: %clang_cl /guard:cf,nochecks -### -- %s 2>&1 | FileCheck 
-check-prefix=CFGUARD %s


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


Re: [PATCH] D52193: RFC: [clang] Multithreaded compilation support

2018-09-18 Thread Zachary Turner via cfe-commits
In an ideal world yes, but the reality is that many people still use
MSBuild, and in that world /MP presumably helps quite a bit. And given that
many people already depend on this functionality of cl, it’s a potential
showstopper for migrating if we don’t support it. That said, if the benefit
isn’t significant that’s a stronger argument for not supporting it imo
On Tue, Sep 18, 2018 at 12:45 AM Hans Wennborg via Phabricator <
revi...@reviews.llvm.org> wrote:

> hans added a comment.
>
> In https://reviews.llvm.org/D52193#1237468, @zturner wrote:
>
> > What about the timings of clang-cl without /MP?
>
>
> And one using Ninja rather than msbuild.
>
> I think the real question is whether we want clang and clang-cl to do
> this. I'm not sure we do as it adds complexity for solving a problem that's
> better solved at the build system level.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D52193
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51789: [clang] Add the exclude_from_explicit_instantiation attribute

2018-09-18 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I'm thinking about this some more, and I'm wondering whether it would be a 
viable solution to just exclude members marked with hidden visibility from 
explicit template instantiations (and declarations thereof). I thought I had 
been convinced by Hubert 
 that visibility 
and this attribute should be left separate, but now I'm not sure anymore. I 
don't think there's a single case of a member function with hidden visibility 
that we don't want to exclude from explicit instantiations. @rsmith Thoughts?


Repository:
  rC Clang

https://reviews.llvm.org/D51789



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


[PATCH] D52193: RFC: [clang] Multithreaded compilation support

2018-09-18 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a subscriber: aganea.
zturner added a comment.

In an ideal world yes, but the reality is that many people still use
MSBuild, and in that world /MP presumably helps quite a bit. And given that
many people already depend on this functionality of cl, it’s a potential
showstopper for migrating if we don’t support it. That said, if the benefit
isn’t significant that’s a stronger argument for not supporting it imo


Repository:
  rC Clang

https://reviews.llvm.org/D52193



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


[clang-tools-extra] r342473 - [clangd] Get rid of Decls parameter in indexMainDecls. NFC

2018-09-18 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Sep 18 06:35:16 2018
New Revision: 342473

URL: http://llvm.org/viewvc/llvm-project?rev=342473&view=rev
Log:
[clangd] Get rid of Decls parameter in indexMainDecls. NFC

It's already available in ParsedAST.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=342473&r1=342472&r2=342473&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Sep 18 06:35:16 2018
@@ -83,7 +83,7 @@ std::unique_ptr makeUp
 }
 
 void onMainAST(PathRef Path, ParsedAST &AST) override {
-  FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls());
+  FIndex->updateMain(Path, AST);
 }
   };
   return llvm::make_unique(FIndex);

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=342473&r1=342472&r2=342473&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Tue Sep 18 06:35:16 2018
@@ -65,10 +65,9 @@ indexSymbols(ASTContext &AST, std::share
 }
 
 std::pair
-indexMainDecls(ParsedAST &AST, llvm::ArrayRef TopLevelDecls,
-   llvm::ArrayRef URISchemes) {
+indexMainDecls(ParsedAST &AST, llvm::ArrayRef URISchemes) {
   return indexSymbols(AST.getASTContext(), AST.getPreprocessorPtr(),
-  TopLevelDecls,
+  AST.getLocalTopLevelDecls(),
   /*IsIndexMainAST=*/true, URISchemes);
 }
 
@@ -163,9 +162,8 @@ void FileIndex::updatePreamble(PathRef P
   PreambleIndex.reset(PreambleSymbols.buildMemIndex());
 }
 
-void FileIndex::updateMain(PathRef Path, ParsedAST &AST,
-   llvm::ArrayRef TopLevelDecls) {
-  auto Contents = indexMainDecls(AST, TopLevelDecls, URISchemes);
+void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
+  auto Contents = indexMainDecls(AST, URISchemes);
   MainFileSymbols.update(
   Path, llvm::make_unique(std::move(Contents.first)),
   llvm::make_unique(std::move(Contents.second)));

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.h?rev=342473&r1=342472&r2=342473&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.h Tue Sep 18 06:35:16 2018
@@ -73,9 +73,9 @@ public:
   void updatePreamble(PathRef Path, ASTContext &AST,
   std::shared_ptr PP);
 
-  /// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
-  void updateMain(PathRef Path, ParsedAST &AST,
-  llvm::ArrayRef TopLevelDecls);
+  /// Update symbols and references from main file \p Path with
+  /// `indexMainDecls`.
+  void updateMain(PathRef Path, ParsedAST &AST);
 
 private:
   std::vector URISchemes;
@@ -106,12 +106,12 @@ private:
   std::unique_ptr MergedIndex;  // Merge preamble and main index.
 };
 
-/// Retrieves symbols and refs of \p Decls in \p AST.
+/// Retrieves symbols and refs of local top level decls in \p AST (i.e.
+/// `AST.getLocalTopLevelDecls()`).
 /// Exposed to assist in unit tests.
 /// If URISchemes is empty, the default schemes in SymbolCollector will be 
used.
 std::pair
-indexMainDecls(ParsedAST &AST, llvm::ArrayRef Decls,
-   llvm::ArrayRef URISchemes = {});
+indexMainDecls(ParsedAST &AST, llvm::ArrayRef URISchemes = {});
 
 /// Idex declarations from \p AST and macros from \p PP that are declared in
 /// included headers.

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=342473&r1=342472&r2=342473&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Tue Sep 18 
06:35:16 2018
@@ -314,14 +314,14 @@ TEST(FileIndexTest, Refs) {
   Test.Code = MainCode.code();
   Test.Filename = "test.cc";
   auto AST = Test.build();
-  Index.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
+  Index.updateMain(Test.Filename, AST);
   // Add tes

[PATCH] D52222: [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/index/FileIndex.h:77
+  /// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
+  void updateMain(PathRef Path, ASTContext &AST,
+  std::shared_ptr PP,

sammccall wrote:
> sammccall wrote:
> > can't this just take PathRef + ParsedAST?
> > (same data, but clearer semantics)
> You're still taking the top-level decls, these can just come from the 
> ParsedAST though?
Ah right. Sorry! Sent rL342473.


Repository:
  rL LLVM

https://reviews.llvm.org/D5



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


[PATCH] D52078: [clangd] Store preamble macros in dynamic index.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 165959.
ioeric added a comment.

- merge with origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52078

Files:
  clangd/index/FileIndex.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/FileIndexTests.cpp

Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -15,6 +15,7 @@
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "gtest/gtest.h"
@@ -330,6 +331,21 @@
  FileURI("unittest:///test2.cc"))}));
 }
 
+TEST(FileIndexTest, CollectMacros) {
+  FileIndex M;
+  update(M, "f", "#define CLANGD 1");
+
+  FuzzyFindRequest Req;
+  Req.Query = "";
+  bool SeenSymbol = false;
+  M.index().fuzzyFind(Req, [&](const Symbol &Sym) {
+EXPECT_EQ(Sym.Name, "CLANGD");
+EXPECT_EQ(Sym.SymInfo.Kind, index::SymbolKind::Macro);
+SeenSymbol = true;
+  });
+  EXPECT_TRUE(SeenSymbol);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -223,12 +223,13 @@
 void TestAfterDotCompletion(clangd::CodeCompleteOptions Opts) {
   auto Results = completions(
   R"cpp(
-  #define MACRO X
-
   int global_var;
 
   int global_func();
 
+  // Make sure this is not in preamble.
+  #define MACRO X
+
   struct GlobalClass {};
 
   struct ClassWithMembers {
@@ -276,11 +277,12 @@
 void TestGlobalScopeCompletion(clangd::CodeCompleteOptions Opts) {
   auto Results = completions(
   R"cpp(
-  #define MACRO X
-
   int global_var;
   int global_func();
 
+  // Make sure this is not in preamble.
+  #define MACRO X
+
   struct GlobalClass {};
 
   struct ClassWithMembers {
@@ -430,10 +432,11 @@
 TEST(CompletionTest, Kinds) {
   auto Results = completions(
   R"cpp(
-  #define MACRO X
   int variable;
   struct Struct {};
   int function();
+  // make sure MACRO is not included in preamble.
+  #define MACRO 10
   int X = ^
   )cpp",
   {func("indexFunction"), var("indexVariable"), cls("indexClass")});
@@ -1921,6 +1924,21 @@
   UnorderedElementsAre(Named("Clangd_Macro_Test")));
 }
 
+TEST(CompletionTest, NoMacroFromPreambleIfIndexIsSet) {
+  auto Results = completions(
+  R"cpp(#define CLANGD_PREAMBLE x
+
+  int x = 0;
+  #define CLANGD_MAIN x
+  void f() { CLANGD_^ }
+  )cpp",
+  {func("CLANGD_INDEX")});
+  // Index is overriden in code completion options, so the preamble symbol is
+  // not seen.
+  EXPECT_THAT(Results.Completions, UnorderedElementsAre(Named("CLANGD_MAIN"),
+Named("CLANGD_INDEX")));
+}
+
 TEST(CompletionTest, DeprecatedResults) {
   std::string Body = R"cpp(
 void TestClangd();
Index: clangd/index/FileIndex.cpp
===
--- clangd/index/FileIndex.cpp
+++ clangd/index/FileIndex.cpp
@@ -14,6 +14,7 @@
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "clang/Index/IndexingAction.h"
+#include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include 
 
@@ -41,10 +42,13 @@
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly;
   IndexOpts.IndexFunctionLocals = false;
-
-  if (IsIndexMainAST)
+  if (IsIndexMainAST) {
 // We only collect refs when indexing main AST.
 CollectorOpts.RefFilter = RefKind::All;
+  }else {
+IndexOpts.IndexMacrosInPreprocessor = true;
+CollectorOpts.CollectMacro = true;
+  }
 
   SymbolCollector Collector(std::move(CollectorOpts));
   Collector.setPreprocessor(PP);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52047: [clangd] Add a "benchmark" for tracking memory

2018-09-18 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 165962.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Rebase on top of master, move logging to symbol index `build()` caller side.


https://reviews.llvm.org/D52047

Files:
  clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
  clang-tools-extra/clangd/index/SymbolYAML.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp

Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -124,9 +124,6 @@
   for (const auto &TokenToPostingList : TempInvertedIndex)
 InvertedIndex.insert({TokenToPostingList.first,
   PostingList(move(TokenToPostingList.second))});
-
-  vlog("Built Dex with estimated memory usage {0} bytes.",
-   estimateMemoryUsage());
 }
 
 /// Constructs iterators over tokens extracted from the query and exhausts it
@@ -239,7 +236,7 @@
   Bytes += LookupTable.getMemorySize();
   Bytes += InvertedIndex.getMemorySize();
   for (const auto &P : InvertedIndex)
-Bytes += P.second.bytes();
+Bytes += P.first.Data.size() + P.second.bytes() * sizeof(DocID);
   return Bytes + BackingDataSize;
 }
 
Index: clang-tools-extra/clangd/index/SymbolYAML.cpp
===
--- clang-tools-extra/clangd/index/SymbolYAML.cpp
+++ clang-tools-extra/clangd/index/SymbolYAML.cpp
@@ -9,6 +9,7 @@
 
 #include "SymbolYAML.h"
 #include "Index.h"
+#include "Logger.h"
 #include "Serialization.h"
 #include "Trace.h"
 #include "dex/Dex.h"
@@ -225,8 +226,12 @@
   if (!Slab)
 return nullptr;
   trace::Span Tracer("BuildIndex");
-  return UseDex ? dex::Dex::build(std::move(*Slab), URISchemes)
-: MemIndex::build(std::move(*Slab), RefSlab());
+  auto Index = UseDex ? dex::Dex::build(std::move(*Slab), URISchemes)
+  : MemIndex::build(std::move(*Slab), RefSlab());
+  vlog("Loaded {0} from {1} with estimated memory usage {2}",
+   UseDex ? "Dex" : "MemIndex", SymbolFilename,
+   Index->estimateMemoryUsage());
+  return Index;
 }
 
 } // namespace clangd
Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
===
--- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
+++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
@@ -66,23 +66,44 @@
   return Requests;
 }
 
+// This is not a *real* benchmark: it shows size of built MemIndex (in bytes).
+// Same for the next "benchmark".
+// FIXME(kbobyrev): Should this be separated into the BackingMemorySize
+// (underlying SymbolSlab size) and Symbol Index (MemIndex/Dex) overhead?
+static void MemSize(benchmark::State &State) {
+  const auto Mem = buildMem();
+  for (auto _ : State)
+// Divide size of Mem by 1000 so that it will be correctly displayed in the
+// benchmark report (possible options for time units are ms, ns and us).
+State.SetIterationTime(/*double Seconds=*/Mem->estimateMemoryUsage() /
+   1000);
+}
+BENCHMARK(MemSize)->UseManualTime()->Unit(benchmark::kMillisecond);
+
+static void DexSize(benchmark::State &State) {
+  const auto Dex = buildDex();
+  for (auto _ : State)
+State.SetIterationTime(Dex->estimateMemoryUsage() / 1000);
+}
+BENCHMARK(DexSize)->UseManualTime()->Unit(benchmark::kMillisecond);
+
 static void MemQueries(benchmark::State &State) {
   const auto Mem = buildMem();
   const auto Requests = extractQueriesFromLogs();
   for (auto _ : State)
 for (const auto &Request : Requests)
   Mem->fuzzyFind(Request, [](const Symbol &S) {});
 }
-BENCHMARK(MemQueries);
+BENCHMARK(MemQueries)->Unit(benchmark::kMillisecond);
 
 static void DexQueries(benchmark::State &State) {
   const auto Dex = buildDex();
   const auto Requests = extractQueriesFromLogs();
   for (auto _ : State)
 for (const auto &Request : Requests)
   Dex->fuzzyFind(Request, [](const Symbol &S) {});
 }
-BENCHMARK(DexQueries);
+BENCHMARK(DexQueries)->Unit(benchmark::kMillisecond);
 
 } // namespace
 } // namespace clangd
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52084: [clangd] NFC: Update documentation of Iterator's dump format

2018-09-18 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 165964.
kbobyrev added a comment.

@ioeric does this format look better?


https://reviews.llvm.org/D52084

Files:
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  clang-tools-extra/unittests/clangd/DexTests.cpp


Index: clang-tools-extra/unittests/clangd/DexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexTests.cpp
@@ -262,13 +262,15 @@
   const PostingList L4({0, 1, 5});
   const PostingList L5({});
 
-  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4]");
+  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4 ...]");
 
   auto Nested =
   createAnd(createAnd(L1.iterator(), L2.iterator()),
 createOr(L3.iterator(), L4.iterator(), L5.iterator()));
 
-  EXPECT_EQ(llvm::to_string(*Nested), "(& (| [5] [1] [END]) (& [1] [1]))");
+  EXPECT_EQ(
+  llvm::to_string(*Nested),
+  "(& (| [... 5 ...] [... 1 ...] [END]) (& [1 ...] [1 ...]))");
 }
 
 TEST(DexIterators, Limit) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -61,8 +61,10 @@
 private:
   llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
 OS << '[';
+if (Index != std::begin(Documents))
+  OS << "... ";
 if (Index != std::end(Documents))
-  OS << *Index;
+  OS << *Index << " ...";
 else
   OS << "END";
 OS << ']';
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -93,9 +93,8 @@
   ///
   /// Where Type is the iterator type representation: "&" for And, "|" for Or,
   /// ChildN is N-th iterator child. Raw iterators over PostingList are
-  /// represented as "[ID1, ID2, ..., {IDN}, ... END]" where IDN is N-th
-  /// PostingList entry and the element which is pointed to by the PostingList
-  /// iterator is enclosed in {} braces.
+  /// represented as "[... ID ...]" where ID is the element under iterator
+  /// cursor.
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const Iterator &Iterator) {
 return Iterator.dump(OS);


Index: clang-tools-extra/unittests/clangd/DexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexTests.cpp
@@ -262,13 +262,15 @@
   const PostingList L4({0, 1, 5});
   const PostingList L5({});
 
-  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4]");
+  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4 ...]");
 
   auto Nested =
   createAnd(createAnd(L1.iterator(), L2.iterator()),
 createOr(L3.iterator(), L4.iterator(), L5.iterator()));
 
-  EXPECT_EQ(llvm::to_string(*Nested), "(& (| [5] [1] [END]) (& [1] [1]))");
+  EXPECT_EQ(
+  llvm::to_string(*Nested),
+  "(& (| [... 5 ...] [... 1 ...] [END]) (& [1 ...] [1 ...]))");
 }
 
 TEST(DexIterators, Limit) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -61,8 +61,10 @@
 private:
   llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
 OS << '[';
+if (Index != std::begin(Documents))
+  OS << "... ";
 if (Index != std::end(Documents))
-  OS << *Index;
+  OS << *Index << " ...";
 else
   OS << "END";
 OS << ']';
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -93,9 +93,8 @@
   ///
   /// Where Type is the iterator type representation: "&" for And, "|" for Or,
   /// ChildN is N-th iterator child. Raw iterators over PostingList are
-  /// represented as "[ID1, ID2, ..., {IDN}, ... END]" where IDN is N-th
-  /// PostingList entry and the element which is pointed to by the PostingList
-  /// iterator is enclosed in {} braces.
+  /// represented as "[... ID ...]" where ID is the element under iterator
+  /// cursor.
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const Iterator &Iterator) {
 return Iterator.dump(OS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51340: [WIP] Add /Zc:DllexportInlines option to clang-cl

2018-09-18 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta updated this revision to Diff 165966.
takuto.ikuta edited the summary of this revision.
takuto.ikuta added a comment.

Current implementation cannot build chrome when pch is enabled.
undefined symbol error happens during linking blink_modules.dll


https://reviews.llvm.org/D51340

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/CLCompatOptions.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport-import-fvisibility-inlines-hidden.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp

Index: clang/test/CodeGenCXX/hidden-dllimport.cpp
===
--- clang/test/CodeGenCXX/hidden-dllimport.cpp
+++ clang/test/CodeGenCXX/hidden-dllimport.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -fvisibility-inlines-hidden -o - %s | FileCheck %s
 
-// We used to declare this hidden dllimport, which is contradictory.
+// We don't declare this hidden dllimport.
 
 // CHECK: declare dllimport void @"?bar@foo@@QEAAXXZ"(%struct.foo*)
 
Index: clang/test/CodeGenCXX/dllexport-import-fvisibility-inlines-hidden.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dllexport-import-fvisibility-inlines-hidden.cpp
@@ -0,0 +1,161 @@
+// RUN: %clang_cc1 %s -fms-extensions -triple x86_64-windows-msvc   \
+// RUN: -fno-dllexport-inlines -emit-llvm -O0 -o - |\
+// RUN: FileCheck --check-prefix=DEFAULT --check-prefix=NOINLINE %s
+
+// RUN: %clang_cc1 %s -fms-extensions -triple x86_64-windows-msvc   \
+// RUN: -emit-llvm -O0 -o - |   \
+// RUN: FileCheck --check-prefix=DEFAULT --check-prefix=INLINE %s
+
+
+// Function
+
+// DEFAULT-DAG: define dso_local dllexport void @"?NormalFunction@@YAXXZ"()
+void __declspec(dllexport) NormalFunction() {}
+
+
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?AlwaysInlineFunction@@YAXXZ"
+__forceinline void __declspec(dllexport) AlwaysInlineFunction() {}
+
+// DEFAULT-DAG: @"?static_variable@?1??AlwaysInlineWithStaticVariableExported@@YAHXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
+__forceinline int __declspec(dllexport) AlwaysInlineWithStaticVariableExported() {
+  static int static_variable = 0;
+  ++static_variable;
+  return static_variable;
+}
+
+// DEFAULT-DAG: @"?static_variable@?1??AlwaysInlineWithStaticVariableImported@@YAHXZ@4HA" = available_externally dllimport global i32 0, align 4
+__forceinline int __declspec(dllimport) AlwaysInlineWithStaticVariableImported() {
+  static int static_variable = 0;
+  ++static_variable;
+  return static_variable;
+}
+
+int ImportedFunctionUser() {
+  return AlwaysInlineWithStaticVariableImported();
+}
+
+// Class member function
+
+// check for local static variables
+// NOINLINE-DAG: @"?static_variable@?1??InclassDefFuncWithStaticVariable@NoTemplateExportedClass@@QEAAHXZ@4HA" = linkonce_odr dso_local global i32 0, comdat, align 4
+// INLINE-DAG: @"?static_variable@?1??InclassDefFuncWithStaticVariable@NoTemplateExportedClass@@QEAAHXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
+
+// DEFAULT-DAG: @"?static_variable@?1??InlineOutclassDefFuncWithStaticVariable@NoTemplateExportedClass@@QEAAHXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
+
+class __declspec(dllexport) NoTemplateExportedClass {
+ public:
+  // DEFAULT-NOT: NoTemplateExportedClass@NoTemplateExportedClass@@
+  NoTemplateExportedClass() = default;
+
+  // NOINLINE-NOT: InclassDefFunc@NoTemplateExportedClass
+  // INLINE-DAG: define weak_odr dso_local dllexport void @"?InclassDefFunc@NoTemplateExportedClass@@
+  void InclassDefFunc() {}
+
+  int f();
+
+  // DEFAULT-DAG: define weak_odr dso_local dllexport i32 @"?InclassDefFuncWithStaticVariable@NoTemplateExportedClass@@QEAAHXZ"
+  int InclassDefFuncWithStaticVariable() {
+static int static_variable = 0;
+++static_variable;
+return static_variable;
+  }
+
+  // DEFAULT-NOT: InlineOutclassDefFuncWihtoutDefinition
+  __forceinline void InlineOutclassDefFuncWihtoutDefinition();
+
+  // DEFAULT-NOT: InlineOutclassDefFunc@NoTemplateExportedClass@@
+  __forceinline void InlineOutclassDefFunc();
+
+  // DEFAULT-NOT: InlineOutclassDefFuncWithStaticVariable@NoTemplateExportedClass@@
+  __forceinline int InlineOutclassDefFuncWithStaticVariable();
+
+  // DEFAULT-DAG: define dso_local dllexport void @"?OutclassDefFunc@NoTemplateExportedClass@@QEAAXXZ"
+  void OutclassDefFunc();
+
+
+  // Copy assignment operator.
+  // DEFAULT-DAG: define weak_odr dso_local dllexport dereferenceable(1) %class.NoTemplateExportedClass* @"??4NoTemplateExportedClass@@QEAAAEAV0@AEBV0@@Z"
+};
+
+void NoTemplateExportedClass::OutclassDefFunc() {}
+
+__forceinline void N

[PATCH] D52084: [clangd] NFC: Update documentation of Iterator's dump format

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/PostingList.cpp:66
+  OS << "... ";
 if (Index != std::end(Documents))
+  OS << *Index << " ...";

nit: should we drop the trailing `...` if Index is the last element?


https://reviews.llvm.org/D52084



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


[PATCH] D52079: [Sema] Do not load macros from preamble when LoadExternal is false.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 165969.
ioeric added a comment.

- added lit test


Repository:
  rC Clang

https://reviews.llvm.org/D52079

Files:
  include/clang/Sema/CodeCompleteOptions.h
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-pch-skip.cpp

Index: test/Index/complete-pch-skip.cpp
===
--- test/Index/complete-pch-skip.cpp
+++ test/Index/complete-pch-skip.cpp
@@ -4,19 +4,26 @@
 
 int main() { return ns:: }
 int main2() { return ns::foo(). }
+int main3() { PREAMBLE_ }
 
-// RUN: echo "namespace ns { struct foo { int baz }; }" > %t.h
+// RUN: printf "namespace ns { struct foo { int baz }; }\n#define PREAMBLE_MAC" > %t.h
 // RUN: c-index-test -write-pch %t.h.pch -x c++-header %t.h
 //
 // RUN: c-index-test -code-completion-at=%s:5:26 -include %t.h %s | FileCheck -check-prefix=WITH-PCH %s
 // WITH-PCH: {TypedText bar}
 // WITH-PCH: {TypedText foo}
 
+// RUN: c-index-test -code-completion-at=%s:7:24 -include %t.h %s | FileCheck -check-prefix=WITH-PCH-MACRO %s
+// WITH-PCH-MACRO: {TypedText PREAMBLE_MAC}
+
 // RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:5:26 -include %t.h %s | FileCheck -check-prefix=SKIP-PCH %s
 // SKIP-PCH-NOT: foo
 // SKIP-PCH: {TypedText bar}
 // SKIP-PCH-NOT: foo
 
+// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:7:24 -include %t.h %s | FileCheck -check-prefix=SKIP-PCH-MACRO %s
+// SKIP-PCH-MACRO-NOT: {TypedText PREAMBLE_MAC}
+
 // Verify that with *no* preamble (no -include flag) we still get local results.
 // SkipPreamble used to break this, by making lookup *too* lazy.
 // RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:5:26 %s | FileCheck -check-prefix=NO-PCH %s
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3304,14 +3304,14 @@
 }
 
 static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results,
-bool IncludeUndefined,
+bool LoadExternal, bool IncludeUndefined,
 bool TargetTypeIsPointer = false) {
   typedef CodeCompletionResult Result;
 
   Results.EnterNewScope();
 
-  for (Preprocessor::macro_iterator M = PP.macro_begin(),
- MEnd = PP.macro_end();
+  for (Preprocessor::macro_iterator M = PP.macro_begin(LoadExternal),
+MEnd = PP.macro_end(LoadExternal);
M != MEnd; ++M) {
 auto MD = PP.getMacroDefinition(M->first);
 if (IncludeUndefined || MD) {
@@ -3327,7 +3327,6 @@
   }
 
   Results.ExitScope();
-
 }
 
 static void AddPrettyFunctionResults(const LangOptions &LangOpts,
@@ -3611,7 +3610,7 @@
   }
 
   if (CodeCompleter->includeMacros())
-AddMacroResults(PP, Results, false);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
 
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
 Results.data(),Results.size());
@@ -3749,7 +3748,8 @@
 AddPrettyFunctionResults(getLangOpts(), Results);
 
   if (CodeCompleter->includeMacros())
-AddMacroResults(PP, Results, false, PreferredTypeIsPointer);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false,
+PreferredTypeIsPointer);
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
 Results.data(), Results.size());
 }
@@ -4372,7 +4372,7 @@
   Results.ExitScope();
 
   if (CodeCompleter->includeMacros()) {
-AddMacroResults(PP, Results, false);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
   }
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
 Results.data(), Results.size());
@@ -4688,7 +4688,7 @@
 AddPrettyFunctionResults(getLangOpts(), Results);
 
   if (CodeCompleter->includeMacros())
-AddMacroResults(PP, Results, false);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
 
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
 Results.data(),Results.size());
@@ -5722,7 +5722,7 @@
  CodeCompleter->loadExternal());
 
   if (CodeCompleter->includeMacros())
-AddMacroResults(PP, Results, false);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
 
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
 Results.data(), Results.size());
@@ -5951,10 +5951,9 @@
   Results.ExitScope();
 
   if (CodeCompleter->includeMacros())
-AddMacroResults(PP, Results, false);
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
   HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionConte

[PATCH] D52078: [clangd] Store preamble macros in dynamic index.

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Something not listed in cons: because macros aren't namespaced and we don't 
have lots of signals, they can be really spammy. 
Potentially, offering macros that aren't in the TU could be a loss even if it's 
a win for other types of signals.

We could always e.g. postfilter index macro results using the include structure 
of the preamble, so no concern for this patch, just something to think about 
for the followup.

We also need to make sure that we're not indexing/serving header guards as code 
completions (e.g. if SemaCodeComplete is currently taking care of this)




Comment at: clangd/index/FileIndex.cpp:48
 CollectorOpts.RefFilter = RefKind::All;
+  }else {
+IndexOpts.IndexMacrosInPreprocessor = true;

nit: please clang-format


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52078



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


[PATCH] D52084: [clangd] Improve PostingList iterator string representation

2018-09-18 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 165973.
kbobyrev marked an inline comment as done.

https://reviews.llvm.org/D52084

Files:
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  clang-tools-extra/unittests/clangd/DexTests.cpp


Index: clang-tools-extra/unittests/clangd/DexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexTests.cpp
@@ -262,13 +262,15 @@
   const PostingList L4({0, 1, 5});
   const PostingList L5({});
 
-  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4]");
+  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4 ...]");
 
   auto Nested =
   createAnd(createAnd(L1.iterator(), L2.iterator()),
 createOr(L3.iterator(), L4.iterator(), L5.iterator()));
 
-  EXPECT_EQ(llvm::to_string(*Nested), "(& (| [5] [1] [END]) (& [1] [1]))");
+  EXPECT_EQ(
+  llvm::to_string(*Nested),
+  "(& (| [... 5] [... 1 ...] [END]) (& [1 ...] [1 ...]))");
 }
 
 TEST(DexIterators, Limit) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -61,10 +61,14 @@
 private:
   llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
 OS << '[';
+if (Index != std::begin(Documents))
+  OS << "... ";
 if (Index != std::end(Documents))
   OS << *Index;
 else
   OS << "END";
+if (Index != std::end(Documents) && Index != std::end(Documents) - 1)
+  OS << " ...";
 OS << ']';
 return OS;
   }
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -93,9 +93,8 @@
   ///
   /// Where Type is the iterator type representation: "&" for And, "|" for Or,
   /// ChildN is N-th iterator child. Raw iterators over PostingList are
-  /// represented as "[ID1, ID2, ..., {IDN}, ... END]" where IDN is N-th
-  /// PostingList entry and the element which is pointed to by the PostingList
-  /// iterator is enclosed in {} braces.
+  /// represented as "[... ID ...]" where ID is the element under iterator
+  /// cursor.
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const Iterator &Iterator) {
 return Iterator.dump(OS);


Index: clang-tools-extra/unittests/clangd/DexTests.cpp
===
--- clang-tools-extra/unittests/clangd/DexTests.cpp
+++ clang-tools-extra/unittests/clangd/DexTests.cpp
@@ -262,13 +262,15 @@
   const PostingList L4({0, 1, 5});
   const PostingList L5({});
 
-  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4]");
+  EXPECT_EQ(llvm::to_string(*(L0.iterator())), "[4 ...]");
 
   auto Nested =
   createAnd(createAnd(L1.iterator(), L2.iterator()),
 createOr(L3.iterator(), L4.iterator(), L5.iterator()));
 
-  EXPECT_EQ(llvm::to_string(*Nested), "(& (| [5] [1] [END]) (& [1] [1]))");
+  EXPECT_EQ(
+  llvm::to_string(*Nested),
+  "(& (| [... 5] [... 1 ...] [END]) (& [1 ...] [1 ...]))");
 }
 
 TEST(DexIterators, Limit) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -61,10 +61,14 @@
 private:
   llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
 OS << '[';
+if (Index != std::begin(Documents))
+  OS << "... ";
 if (Index != std::end(Documents))
   OS << *Index;
 else
   OS << "END";
+if (Index != std::end(Documents) && Index != std::end(Documents) - 1)
+  OS << " ...";
 OS << ']';
 return OS;
   }
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -93,9 +93,8 @@
   ///
   /// Where Type is the iterator type representation: "&" for And, "|" for Or,
   /// ChildN is N-th iterator child. Raw iterators over PostingList are
-  /// represented as "[ID1, ID2, ..., {IDN}, ... END]" where IDN is N-th
-  /// PostingList entry and the element which is pointed to by the PostingList
-  /// iterator is enclosed in {} braces.
+  /// represented as "[... ID ...]" where ID is the element under iterator
+  /// cursor.
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const Iterator &Iterator) {
 return Iterator.dump(OS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailm

[PATCH] D52233: [dexp] Allow users to dump JSON representations of fuzzy find requests

2018-09-18 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added reviewers: ioeric, ilya-biryukov.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, jkorous.

This might be useful for benchmark construction.


https://reviews.llvm.org/D52233

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -113,6 +113,11 @@
   cl::init(10),
   cl::desc("Max results to display"),
   };
+  cl::opt ShowJSONRequest{
+  "show-json",
+  cl::desc("Print Fuzzy Find Request in JSON format"),
+  cl::init(false),
+  };
 
   void run() override {
 FuzzyFindRequest Request;
@@ -123,6 +128,8 @@
   StringRef(this->Scopes).split(Scopes, ',');
   Request.Scopes = {Scopes.begin(), Scopes.end()};
 }
+if (ShowJSONRequest)
+  llvm::outs() << llvm::formatv("Request:\n{0}\n\n", toJSON(Request));
 // FIXME(kbobyrev): Print symbol final scores to see the distribution.
 static const auto OutputFormat = "{0,-4} | {1,-40} | {2,-25}\n";
 llvm::outs() << llvm::formatv(OutputFormat, "Rank", "Symbol ID",


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -113,6 +113,11 @@
   cl::init(10),
   cl::desc("Max results to display"),
   };
+  cl::opt ShowJSONRequest{
+  "show-json",
+  cl::desc("Print Fuzzy Find Request in JSON format"),
+  cl::init(false),
+  };
 
   void run() override {
 FuzzyFindRequest Request;
@@ -123,6 +128,8 @@
   StringRef(this->Scopes).split(Scopes, ',');
   Request.Scopes = {Scopes.begin(), Scopes.end()};
 }
+if (ShowJSONRequest)
+  llvm::outs() << llvm::formatv("Request:\n{0}\n\n", toJSON(Request));
 // FIXME(kbobyrev): Print symbol final scores to see the distribution.
 static const auto OutputFormat = "{0,-4} | {1,-40} | {2,-25}\n";
 llvm::outs() << llvm::formatv(OutputFormat, "Rank", "Symbol ID",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52078: [clangd] Store preamble macros in dynamic index.

2018-09-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D52078#1238301, @sammccall wrote:

> Something not listed in cons: because macros aren't namespaced and we don't 
> have lots of signals, they can be really spammy. 
>  Potentially, offering macros that aren't in the TU could be a loss even if 
> it's a win for other types of signals.


Aren't they already spammy from Sema? Sema can provide thousands of macros in 
the TU.

We penalize quality of macro symbols in the global index. Maybe we can do the 
same thing for dynamic index?

> We could always e.g. postfilter index macro results using the include 
> structure of the preamble, so no concern for this patch, just something to 
> think about for the followup.

Sounds good.

> We also need to make sure that we're not indexing/serving header guards as 
> code completions (e.g. if SemaCodeComplete is currently taking care of this)

These symbols are already filtered out in `SymbolCollector`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52078



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


r342484 - [index] Enhance indexing for module references

2018-09-18 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Tue Sep 18 08:02:56 2018
New Revision: 342484

URL: http://llvm.org/viewvc/llvm-project?rev=342484&view=rev
Log:
[index] Enhance indexing for module references

* Create a USR for the occurrences of the 'module' symbol kind
* Record module references for each identifier in an import declaration

Added:
cfe/trunk/test/Index/Core/Inputs/module/SubModA.h
cfe/trunk/test/Index/Core/Inputs/module/SubSubModA.h
Modified:
cfe/trunk/include/clang/Index/IndexDataConsumer.h
cfe/trunk/include/clang/Index/USRGeneration.h
cfe/trunk/lib/Index/IndexingAction.cpp
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/Core/Inputs/module/module.modulemap
cfe/trunk/test/Index/Core/index-with-module.m
cfe/trunk/tools/c-index-test/core_main.cpp
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
cfe/trunk/tools/libclang/CXIndexDataConsumer.h

Modified: cfe/trunk/include/clang/Index/IndexDataConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexDataConsumer.h?rev=342484&r1=342483&r2=342484&view=diff
==
--- cfe/trunk/include/clang/Index/IndexDataConsumer.h (original)
+++ cfe/trunk/include/clang/Index/IndexDataConsumer.h Tue Sep 18 08:02:56 2018
@@ -50,7 +50,12 @@ public:
 SourceLocation Loc);
 
   /// \returns true to continue indexing, or false to abort.
+  ///
+  /// This will be called for each module reference in an import decl.
+  /// For "@import MyMod.SubMod", there will be a call for 'MyMod' with the
+  /// 'reference' role, and a call for 'SubMod' with the 'declaration' role.
   virtual bool handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
  SymbolRoleSet Roles, SourceLocation Loc);
 
   virtual void finish() {}

Modified: cfe/trunk/include/clang/Index/USRGeneration.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/USRGeneration.h?rev=342484&r1=342483&r2=342484&view=diff
==
--- cfe/trunk/include/clang/Index/USRGeneration.h (original)
+++ cfe/trunk/include/clang/Index/USRGeneration.h Tue Sep 18 08:02:56 2018
@@ -16,6 +16,7 @@
 namespace clang {
 class Decl;
 class MacroDefinitionRecord;
+class Module;
 class SourceLocation;
 class SourceManager;
 
@@ -70,6 +71,22 @@ bool generateUSRForMacro(const MacroDefi
 bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
  const SourceManager &SM, SmallVectorImpl &Buf);
 
+/// Generate a USR for a module, including the USR prefix.
+/// \returns true on error, false on success.
+bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS);
+
+/// Generate a USR for a top-level module name, including the USR prefix.
+/// \returns true on error, false on success.
+bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS);
+
+/// Generate a USR fragment for a module.
+/// \returns true on error, false on success.
+bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS);
+
+/// Generate a USR fragment for a module name.
+/// \returns true on error, false on success.
+bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS);
+
 } // namespace index
 } // namespace clang
 

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=342484&r1=342483&r2=342484&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Tue Sep 18 08:02:56 2018
@@ -37,6 +37,7 @@ bool IndexDataConsumer::handleMacroOccur
 }
 
 bool IndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
+  const Module *Mod,
   SymbolRoleSet Roles,
   SourceLocation Loc) {
   return true;

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=342484&r1=342483&r2=342484&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Tue Sep 18 08:02:56 2018
@@ -80,11 +80,27 @@ bool IndexingContext::handleReference(co
   RefE, RefD, DC);
 }
 
+static void reportModuleReferences(const Module *Mod,
+   ArrayRef IdLocs,
+   const ImportDecl *ImportD,
+   IndexDataConsumer &DataConsumer) {
+  if (!Mod)
+return;
+  reportModuleReferenc

[PATCH] D50948: lambdas in modules: change storage for LambdaDefinitionData

2018-09-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

We don't want to allocate storage for the lambda fields for non-lambda classes, 
which is why we use distinct base classes. Is the problem you're trying to 
solve here that we fake a definition in AST deserialization before we know 
whether the class is a lambda? If so, that seems solvable by moving the 
IsLambda flag out of DefinitionData into CXXRecordData (perhaps as a distinct 
TagTypeKind?).


Repository:
  rC Clang

https://reviews.llvm.org/D50948



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


Re: [PATCH] D52078: [clangd] Store preamble macros in dynamic index.

2018-09-18 Thread Sam McCall via cfe-commits
On Tue, Sep 18, 2018, 16:28 Eric Liu via Phabricator <
revi...@reviews.llvm.org> wrote:

> ioeric added a comment.
>
> In https://reviews.llvm.org/D52078#1238301, @sammccall wrote:
>
> > Something not listed in cons: because macros aren't namespaced and we
> don't have lots of signals, they can be really spammy.
> >  Potentially, offering macros that aren't in the TU could be a loss even
> if it's a win for other types of signals.
>
>
> Aren't they already spammy from Sema? Sema can provide thousands of macros
> in the TU.
>
Indeed, but Sema will at least implicitly restrict to the transitive
headers!

Agree with everything you say, looking forward to this change!

We penalize quality of macro symbols in the global index. Maybe we can do
> the same thing for dynamic index?
>
> > We could always e.g. postfilter index macro results using the include
> structure of the preamble, so no concern for this patch, just something to
> think about for the followup.
>
> Sounds good.
>
> > We also need to make sure that we're not indexing/serving header guards
> as code completions (e.g. if SemaCodeComplete is currently taking care of
> this)
>
> These symbols are already filtered out in `SymbolCollector`.
>
>
> Repository:
>   rCTE Clang Tools Extra
>
> https://reviews.llvm.org/D52078
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52078: [clangd] Store preamble macros in dynamic index.

2018-09-18 Thread Mailing List "cfe-commits" via Phabricator via cfe-commits
cfe-commits added a comment.



- F7238787: msg-7222-125.txt 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52078



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


[PATCH] D51789: [clang] Add the exclude_from_explicit_instantiation attribute

2018-09-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

That may work for libc++'s purposes, but it's clearly inappropriate as a 
compiler rule.  There are good reasons why something with hidden visibility 
would need to be explicitly instantiated.  For many programmers, hidden 
visibility means "this is private to my library", not "this is actually public 
to my library, but I'm walking an ABI tightrope".


Repository:
  rC Clang

https://reviews.llvm.org/D51789



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


[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2018-09-18 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

This is intended, IIUC. The syntax of the clang-tidy-diff.py mirrors the syntax 
of clang-tidy itself, and the `--` option is used in the same way as in 
clang-tidy - to denote the start of compiler arguments (and switch to the fixed 
compilation database). Do you have a use case that would require passing 
clang-tidy options beyond the list already supported by clang-tidy-diff.py?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49864



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


[PATCH] D51789: [clang] Add the exclude_from_explicit_instantiation attribute

2018-09-18 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In https://reviews.llvm.org/D51789#1238396, @rjmccall wrote:

> That may work for libc++'s purposes, but it's clearly inappropriate as a 
> compiler rule.  There are good reasons why something with hidden visibility 
> would need to be explicitly instantiated.


I take your word for it, but I can't think of any example. For my education, do 
you have a specific example in mind?

> For many programmers, hidden visibility means "this is private to my 
> library", not "this is actually public to my library, but I'm walking an ABI 
> tightrope".

In libc++'s case, the functions we will annotate with 
`exclude_from_explicit_instantiation` are private to libc++ too (in the sense 
that we don't want them part of the ABI and they are not exported from the 
dylib). Those functions were previously marked with `__always_inline__` to make 
sure they were not part of the ABI.

Note that I'm quite happy with `exclude_from_explicit_instantiation` as it 
solves libc++'s problem -- I'm trying to see whether another solution would 
serve people better while still solving libc++'s problem. (Appart from 
explicitly exporting functions, typeinfos and vtables like we've talked about 
on cfe-dev, which is a superior solution to everything else but is left as a 
future improvement for the time being).


Repository:
  rC Clang

https://reviews.llvm.org/D51789



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


[PATCH] D52200: Thread safety analysis: Handle ObjCIvarRefExpr in SExprBuilder::translate

2018-09-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Analysis/ThreadSafetyCommon.cpp:362
+  til::Project *P = new (Arena) til::Project(E, D);
+  if (hasCppPointerType(BE))
+P->setArrow(true);

aaron.ballman wrote:
> I feel like this will always return false. However, I wonder if 
> `IVRE->getBase()->isArrow()` is more appropriate here?
The base of an `ObjCIvarRefExpr` will never directly be a C pointer type.  I 
don't know whether this data structure looks through casts, but it's certainly 
*possible* to cast arbitrarily weird C stuff to ObjC pointer type.  On the 
other hand, by and large nobody actually ever does that, so I wouldn't make a 
special case for it here.

`ObjCIvarRefExpr` just has an `isArrow()` method directly if this is just 
supposed to be capturing the difference between `.` and `->`.  But then, so 
does `MemberExpr`, and in that case you're doing this odd analysis of the base 
instead of trusting `isArrow()`, so I don't know what to tell you to do.

Overall it is appropriate to treat an ObjC ivar reference as a perfectly 
ordinary projection.  The only thing that's special about it is that the actual 
offset isn't necessarily statically known, but ivars still behave as if they're 
all independently declared, so I wouldn't worry about it.


Repository:
  rC Clang

https://reviews.llvm.org/D52200



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


[PATCH] D52219: [analyzer] (1/n) Support pointee mutation analysis in ExprMutationAnalyzer.

2018-09-18 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Looks like a good start! I think getting the pointers right will be most 
difficult, because of the multiple levels of indirection they allow. Do you 
think it would be possible to the analysis for `>const?< int ***`-cases? 
(recursively checking through the pointer levels)




Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:198
 const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
+  // `Exp` can be *directly* mutated if the type of `Exp` is not const.
+  // Bail out early otherwise.

Just to be sure that i understand:
the changes here are more performance optimizations then directly related to 
detect pointee mutations?



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:440
+  return nullptr;
+  } else if (const auto *RT = Exp->getType()->getAs()) {
+if (const CXXRecordDecl *RecordDecl = RT->getAsCXXRecordDecl()) {

no `else` after return. this makes the short circuit logic clearer



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:442
+if (const CXXRecordDecl *RecordDecl = RT->getAsCXXRecordDecl()) {
+  const bool ExpIsConst = Exp->getType().isConstant(Context);
+  if (llvm::any_of(

values are not marked as const by the llvm code guideline



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:459
+  }
+  const bool ExpIsPointer = Exp->getType()->getAs();
+

implicit conversion from pointer to bool? Please make that better visible and 
please dont use const on values. 
Not sure for the matchers, I have seen both, but they should be treated as 
values as well i think.



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:463
+  // A member function is assumed to be non-const when it is unresolved.
+  // We don't handle pointer-like type here as non-const member function of
+  // pointee can't be directly invoked without dereferencing the pointer-like

Please make that sentence clearer, i could not understand it (only interpret :D)



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:481
+  const auto AsArg =
+  anyOf(callExpr(hasAnyArgument(equalsNode(Exp))),
+cxxConstructExpr(hasAnyArgument(equalsNode(Exp))),

shouldn't be the constness of the argument considered here?



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:488
+
+  // Returned.
+  const auto AsReturnValue = returnStmt(hasReturnValue(equalsNode(Exp)));

Either remove the comment or make it a full sentence please. I think the 
variable naming is clear enough to elide



Comment at: lib/Analysis/ExprMutationAnalyzer.cpp:500
+const Stmt *ExprMutationAnalyzer::findPointeeCastMutation(const Expr *Exp) {
+  // Only handling LValueToRValue for now for easier unit testing during
+  // implementation.

Please add a todo to ensure the missing casts are not forgotten



Comment at: unittests/Analysis/ExprMutationAnalyzerTest.cpp:43
   const auto *const E = selectFirst("expr", Results);
+  assert(E);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);

maybe even `assert(E && S)`?



Comment at: unittests/Analysis/ExprMutationAnalyzerTest.cpp:67
+if (const auto *DRE = dyn_cast(E)) {
+  if (DRE->getNameInfo().getAsString()[0] == 'p')
+Finder = PointeeMutationFinder;

That doesn't look like a super idea. It is super hidden that variable 'p*' will 
be analyzed for pointee mutation and others aren't. Especially in 12 months and 
when someone else wants to change something, this will be the source of 
headaches.

Don't you think there could be a better way of doing this switch?



Comment at: unittests/Analysis/ExprMutationAnalyzerTest.cpp:156
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()"));
+
+  AST = tooling::buildASTFromCode(

I feel that there a multiple tests missing:

- multiple levels of pointers `int ***`, `int * const *`
- pointers to references `int &*`
- references to pointers `int *&`
- ensure that having a const pointer does no influence the pointee analysis 
`int * const p = &i; *p = 42;`
- a class with `operator*` + `operator->` const/non-const and the analysis for 
pointers to that class
- pointer returned from a function
- non-const reference returned 
```
int& foo(int *p) {
  return *p;
}
```




Comment at: unittests/Analysis/ExprMutationAnalyzerTest.cpp:175
+  Results = match(withEnclosingCompound(declRefTo("p")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("p->mf()"));
 

Could you please add the `EXPECT_FALSE(isMutated()) && 
EXPECT_TRUE(isPointeeMutated()`?
Maybe a short helper for that like `isOnlyPointeeMutated()` would be nice.

Here and the other cases as well


==

[PATCH] D52058: Add Parameters to DW_AT_name Attribute of Template Variables

2018-09-18 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

In https://reviews.llvm.org/D52058#1237868, @JDevlieghere wrote:

> Generally this looks good, but I'd like for the other to have a look first 
> (at this and the other patch) before accepting.


Sounds good. Thanks for your comments!




Comment at: lib/CodeGen/CGDebugInfo.cpp:1783
+  if (auto *TS = dyn_cast(VL)) {
+if (TS->getSpecializedTemplateOrPartial()
+.is()) {

JDevlieghere wrote:
> JDevlieghere wrote:
> > Might be nice to add a comment here saying what you're doing in this block 
> > and below. Looks like the top one is for partial specialization and the 
> > bottom one for the general case?
> I also suggest to extract `TS->getSpecializedTemplateOrPartial()` into a 
> variable to make this a little less dense.
Hmm... Yeah. I'll take a look at clarifying this section.


Repository:
  rC Clang

https://reviews.llvm.org/D52058



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


[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2018-09-18 Thread Jano Simas via Phabricator via cfe-commits
janosimas added a comment.

To use in a git pre-commit I wanted to use the flags:
-warnings-as-errors=*
-header-filter=.*

I wanted that the script returned an error value for my selected checks, even 
if they are just warnings.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49864



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


[PATCH] D51372: FENV_ACCESS support for libm-style constrained intrinsics

2018-09-18 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn updated this revision to Diff 165995.
kpn added a comment.

Rebase.

Correct obvious error with powi. Fix test and test both C and (partial) C++.

Ping.


https://reviews.llvm.org/D51372

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/Analysis/BodyFarm.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Frontend/Rewrite/RewriteModernObjC.cpp
  lib/Frontend/Rewrite/RewriteObjC.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/TreeTransform.h
  test/CodeGen/fenv-access-pragma.c
  test/CodeGen/fenv-access-pragma.cpp
  test/CodeGen/fenv-math-builtins.c

Index: test/CodeGen/fenv-math-builtins.c
===
--- test/CodeGen/fenv-math-builtins.c
+++ test/CodeGen/fenv-math-builtins.c
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm  %s | FileCheck %s 
+
+// Test codegen of math builtins when using FENV_ACCESS ON.
+// Derived from math-builtins.c and keeps calls in the same order.
+#pragma STDC FENV_ACCESS ON
+
+void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {
+  __builtin_pow(f,f);__builtin_powf(f,f);   __builtin_powl(f,f);
+
+// CHECK: declare double @llvm.experimental.constrained.pow.f64(double, double, metadata, metadata) [[MATH_INTRINSIC:#[0-9]+]]
+// CHECK: declare float @llvm.experimental.constrained.pow.f32(float, float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.pow.f80(x86_fp80, x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_powi(f,f);__builtin_powif(f,f);   __builtin_powil(f,f);
+
+// CHECK: declare double @llvm.experimental.constrained.powi.f64(double, i32, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.powi.f32(float, i32, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.powi.f80(x86_fp80, i32, metadata, metadata) [[MATH_INTRINSIC]]
+
+  /* math */
+  __builtin_cos(f);__builtin_cosf(f);   __builtin_cosl(f); 
+// CHECK: declare double @llvm.experimental.constrained.cos.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.cos.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.cos.f80(x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_exp(f);__builtin_expf(f);   __builtin_expl(f);
+// CHECK: declare double @llvm.experimental.constrained.exp.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.exp.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.exp.f80(x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_exp2(f);   __builtin_exp2f(f);  __builtin_exp2l(f); 
+
+// CHECK: declare double @llvm.experimental.constrained.exp2.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.exp2.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.exp2.f80(x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_fma(f,f,f);__builtin_fmaf(f,f,f);   __builtin_fmal(f,f,f);
+
+// CHECK: declare double @llvm.experimental.constrained.fma.f64(double, double, double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.fma.f32(float, float, float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.fma.f80(x86_fp80, x86_fp80, x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_log(f);__builtin_logf(f);   __builtin_logl(f);
+
+// CHECK: declare double @llvm.experimental.constrained.log.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.log.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.log.f80(x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_log10(f);  __builtin_log10f(f); __builtin_log10l(f);
+
+// CHECK: declare double @llvm.experimental.constrained.log10.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.log10.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare x86_fp80 @llvm.experimental.constrained.log10.f80(x86_fp80, metadata, metadata) [[MATH_INTRINSIC]]
+
+  __builtin_nearbyint(f);  __builtin_nearbyintf(f); __builtin_nearbyintl(f);
+
+// CHECK: declare double @llvm.experimental.constrained.nearbyint.f64(double, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: declare float @llvm.experimental.constrained.nearbyint.f32(float, metadata, metadata) [[MATH_INTRINSIC]]
+// CHECK: de

[PATCH] D50766: Fix false positive unsequenced access and modification warning in array subscript expression.

2018-09-18 Thread Mateusz Janek via Phabricator via cfe-commits
stryku added a comment.

Friendly ping (:


https://reviews.llvm.org/D50766



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


[PATCH] D52084: [clangd] Improve PostingList iterator string representation

2018-09-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

This change seems fine but...

This representation with the raw DocIDs and position dumped seems mostly useful 
for debugging buggy iterator implementations, but not really useful for 
understanding query structure and behavior.

I thought we might be replacing this soon. Of course there's no fundamental 
reason we can't keep both but I'm curious why this is an area of focus :-)


https://reviews.llvm.org/D52084



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


r342499 - [Modules] Add platform and environment features to requires clause

2018-09-18 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Sep 18 10:11:13 2018
New Revision: 342499

URL: http://llvm.org/viewvc/llvm-project?rev=342499&view=rev
Log:
[Modules] Add platform and environment features to requires clause

Allows module map writers to add build requirements based on
platform/os. This helps when target features and language dialects
aren't enough to conditionalize building a module, among other things,
it allow module maps for different platforms to live in the same file.

rdar://problem/43909745

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

Added:
cfe/trunk/test/Modules/target-platform-features.m
Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/lib/Basic/Module.cpp

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=342499&r1=342498&r2=342499&view=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Tue Sep 18 10:11:13 2018
@@ -411,7 +411,7 @@ A *requires-declaration* specifies the r
   *feature*:
 ``!``:sub:`opt` *identifier*
 
-The requirements clause allows specific modules or submodules to specify that 
they are only accessible with certain language dialects or on certain 
platforms. The feature list is a set of identifiers, defined below. If any of 
the features is not available in a given translation unit, that translation 
unit shall not import the module. When building a module for use by a 
compilation, submodules requiring unavailable features are ignored. The 
optional ``!`` indicates that a feature is incompatible with the module.
+The requirements clause allows specific modules or submodules to specify that 
they are only accessible with certain language dialects, platforms, 
environments and target specific features. The feature list is a set of 
identifiers, defined below. If any of the features is not available in a given 
translation unit, that translation unit shall not import the module. When 
building a module for use by a compilation, submodules requiring unavailable 
features are ignored. The optional ``!`` indicates that a feature is 
incompatible with the module.
 
 The following features are defined:
 
@@ -466,6 +466,11 @@ tls
 *target feature*
   A specific target feature (e.g., ``sse4``, ``avx``, ``neon``) is available.
 
+*platform/os*
+  A os/platform variant (e.g. ``freebsd``, ``win32``, ``windows``, ``linux``, 
``ios``, ``macos``, ``iossimulator``) is available.
+
+*environment*
+  A environment variant (e.g. ``gnu``, ``gnueabi``, ``android``, ``msvc``) is 
available.
 
 **Example:** The ``std`` module can be extended to also include C++ and C++11 
headers using a *requires-declaration*:
 

Modified: cfe/trunk/lib/Basic/Module.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=342499&r1=342498&r2=342499&view=diff
==
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Tue Sep 18 10:11:13 2018
@@ -71,6 +71,37 @@ Module::~Module() {
   }
 }
 
+static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) 
{
+  StringRef Platform = Target.getPlatformName();
+  StringRef Env = Target.getTriple().getEnvironmentName();
+
+  // Attempt to match platform and environment.
+  if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
+  Env == Feature)
+return true;
+
+  auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
+auto Pos = LHS.find("-");
+if (Pos == StringRef::npos)
+  return false;
+SmallString<128> NewLHS = LHS.slice(0, Pos);
+NewLHS += LHS.slice(Pos+1, LHS.size());
+return NewLHS == RHS;
+  };
+
+  SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
+  // Darwin has different but equivalent variants for simulators, example:
+  //   1. x86_64-apple-ios-simulator
+  //   2. x86_64-apple-iossimulator
+  // where both are valid examples of the same platform+environment but in the
+  // variant (2) the simulator is hardcoded as part of the platform name. Both
+  // forms above should match for "iossimulator" requirement.
+  if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
+return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
+
+  return PlatformEnv == Feature;
+}
+
 /// Determine whether a translation unit built using the current
 /// language options has the given feature.
 static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
@@ -93,7 +124,8 @@ static bool hasFeature(StringRef Feature
 .Case("opencl", LangOpts.OpenCL)
 .Case("tls", Target.isTLSSupported())
 .Case("zvector", LangOpts.ZVector)
-.Default(Target.hasFeature(Feature));
+.Default(Target.hasFeature(Feature) ||
+   

[PATCH] D51910: [Modules] Add platform feature to requires clause

2018-09-18 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC342499: [Modules] Add platform and environment features to 
requires clause (authored by bruno, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51910?vs=165861&id=165998#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51910

Files:
  docs/Modules.rst
  lib/Basic/Module.cpp
  test/Modules/target-platform-features.m

Index: lib/Basic/Module.cpp
===
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -71,6 +71,37 @@
   }
 }
 
+static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
+  StringRef Platform = Target.getPlatformName();
+  StringRef Env = Target.getTriple().getEnvironmentName();
+
+  // Attempt to match platform and environment.
+  if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
+  Env == Feature)
+return true;
+
+  auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
+auto Pos = LHS.find("-");
+if (Pos == StringRef::npos)
+  return false;
+SmallString<128> NewLHS = LHS.slice(0, Pos);
+NewLHS += LHS.slice(Pos+1, LHS.size());
+return NewLHS == RHS;
+  };
+
+  SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
+  // Darwin has different but equivalent variants for simulators, example:
+  //   1. x86_64-apple-ios-simulator
+  //   2. x86_64-apple-iossimulator
+  // where both are valid examples of the same platform+environment but in the
+  // variant (2) the simulator is hardcoded as part of the platform name. Both
+  // forms above should match for "iossimulator" requirement.
+  if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
+return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
+
+  return PlatformEnv == Feature;
+}
+
 /// Determine whether a translation unit built using the current
 /// language options has the given feature.
 static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
@@ -93,7 +124,8 @@
 .Case("opencl", LangOpts.OpenCL)
 .Case("tls", Target.isTLSSupported())
 .Case("zvector", LangOpts.ZVector)
-.Default(Target.hasFeature(Feature));
+.Default(Target.hasFeature(Feature) ||
+ isPlatformEnvironment(Target, Feature));
   if (!HasFeature)
 HasFeature = std::find(LangOpts.ModuleFeatures.begin(),
LangOpts.ModuleFeatures.end(),
Index: docs/Modules.rst
===
--- docs/Modules.rst
+++ docs/Modules.rst
@@ -411,7 +411,7 @@
   *feature*:
 ``!``:sub:`opt` *identifier*
 
-The requirements clause allows specific modules or submodules to specify that they are only accessible with certain language dialects or on certain platforms. The feature list is a set of identifiers, defined below. If any of the features is not available in a given translation unit, that translation unit shall not import the module. When building a module for use by a compilation, submodules requiring unavailable features are ignored. The optional ``!`` indicates that a feature is incompatible with the module.
+The requirements clause allows specific modules or submodules to specify that they are only accessible with certain language dialects, platforms, environments and target specific features. The feature list is a set of identifiers, defined below. If any of the features is not available in a given translation unit, that translation unit shall not import the module. When building a module for use by a compilation, submodules requiring unavailable features are ignored. The optional ``!`` indicates that a feature is incompatible with the module.
 
 The following features are defined:
 
@@ -466,6 +466,11 @@
 *target feature*
   A specific target feature (e.g., ``sse4``, ``avx``, ``neon``) is available.
 
+*platform/os*
+  A os/platform variant (e.g. ``freebsd``, ``win32``, ``windows``, ``linux``, ``ios``, ``macos``, ``iossimulator``) is available.
+
+*environment*
+  A environment variant (e.g. ``gnu``, ``gnueabi``, ``android``, ``msvc``) is available.
 
 **Example:** The ``std`` module can be extended to also include C++ and C++11 headers using a *requires-declaration*:
 
Index: test/Modules/target-platform-features.m
===
--- test/Modules/target-platform-features.m
+++ test/Modules/target-platform-features.m
@@ -0,0 +1,79 @@
+// Clear and create directories
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/cache
+// RUN: mkdir %t/InputsA
+
+// RUN: echo "module RequiresMacOS {"   >> %t/InputsA/module.map
+// RUN: echo "  requires macos" >> %t/InputsA/module.map
+// RUN: echo "}">> %t/InputsA/module.map
+// RUN: echo "mod

[PATCH] D51910: [Modules] Add platform feature to requires clause

2018-09-18 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342499: [Modules] Add platform and environment features to 
requires clause (authored by bruno, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51910?vs=165861&id=165999#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51910

Files:
  cfe/trunk/docs/Modules.rst
  cfe/trunk/lib/Basic/Module.cpp
  cfe/trunk/test/Modules/target-platform-features.m

Index: cfe/trunk/test/Modules/target-platform-features.m
===
--- cfe/trunk/test/Modules/target-platform-features.m
+++ cfe/trunk/test/Modules/target-platform-features.m
@@ -0,0 +1,79 @@
+// Clear and create directories
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/cache
+// RUN: mkdir %t/InputsA
+
+// RUN: echo "module RequiresMacOS {"   >> %t/InputsA/module.map
+// RUN: echo "  requires macos" >> %t/InputsA/module.map
+// RUN: echo "}">> %t/InputsA/module.map
+// RUN: echo "module RequiresNotiOS {"  >> %t/InputsA/module.map
+// RUN: echo "  requires !ios"  >> %t/InputsA/module.map
+// RUN: echo "}">> %t/InputsA/module.map
+// RUN: echo "module RequiresMain {">> %t/InputsA/module.map
+// RUN: echo "  module SubRequiresNotiOS {" >> %t/InputsA/module.map
+// RUN: echo "requires !ios">> %t/InputsA/module.map
+// RUN: echo "  }"  >> %t/InputsA/module.map
+// RUN: echo "}">> %t/InputsA/module.map
+
+// RUN: %clang_cc1 -triple=x86_64-apple-macosx10.6 -DENABLE_DARWIN -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsA -verify %s 
+// expected-no-diagnostics
+
+// RUN: not %clang_cc1 -triple=arm64-apple-ios -DENABLE_DARWIN -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsA %s  2> %t/notios
+// RUN: FileCheck %s -check-prefix=CHECK-IOS < %t/notios
+#ifdef ENABLE_DARWIN
+// CHECK-IOS: module 'RequiresMacOS' requires feature 'macos'
+@import RequiresMacOS;
+// CHECK-IOS: module 'RequiresNotiOS' is incompatible with feature 'ios'
+@import RequiresNotiOS;
+// We should never get errors for submodules that don't match
+// CHECK-IOS-NOT: module 'RequiresMain'
+@import RequiresMain;
+#endif
+
+// RUN: mkdir %t/InputsB
+// RUN: echo "module RequiresiOSSim {" >> %t/InputsB/module.map
+// RUN: echo "  requires iossimulator"  >> %t/InputsB/module.map
+// RUN: echo "}">> %t/InputsB/module.map
+// RUN: %clang_cc1 -triple=x86_64-apple-iossimulator -DENABLE_IOSSIM -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsB %s  -verify
+// RUN: %clang_cc1 -triple=x86_64-apple-ios-simulator -DENABLE_IOSSIM -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsB %s  -verify
+
+#ifdef ENABLE_IOSSIM
+@import RequiresiOSSim;
+#endif
+
+// RUN: mkdir %t/InputsC
+// RUN: echo "module RequiresLinuxEABIA {"  >> %t/InputsC/module.map
+// RUN: echo "  requires linux, gnueabi">> %t/InputsC/module.map
+// RUN: echo "}">> %t/InputsC/module.map
+// RUN: echo "module RequiresLinuxEABIB {"  >> %t/InputsC/module.map
+// RUN: echo "  requires gnueabi"   >> %t/InputsC/module.map
+// RUN: echo "}">> %t/InputsC/module.map
+// RUN: echo "module RequiresLinuxEABIC {"  >> %t/InputsC/module.map
+// RUN: echo "  requires linux" >> %t/InputsC/module.map
+// RUN: echo "}">> %t/InputsC/module.map
+// RUN: %clang_cc1 -triple=armv8r-none-linux-gnueabi -DENABLE_LINUXEABI -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsC %s -verify
+
+#ifdef ENABLE_LINUXEABI
+@import RequiresLinuxEABIA;
+@import RequiresLinuxEABIB;
+@import RequiresLinuxEABIC;
+#endif
+
+// RUN: mkdir %t/InputsD
+// RUN: echo "module RequiresWinMSVCA {"  >> %t/InputsD/module.map
+// RUN: echo "  requires windows" >> %t/InputsD/module.map
+// RUN: echo "}"  >> %t/InputsD/module.map
+// RUN: echo "module RequiresWinMSVCB {"  >> %t/InputsD/module.map
+// RUN: echo "  requires windows, msvc"   >> %t/InputsD/module.map
+// RUN: echo "}"  >> %t/InputsD/module.map
+// RUN: echo "module RequiresWinMSVCC {"  >> %t/InputsD/module.map
+// RUN: echo "  requires msvc">> %t/InputsD/module.map
+// RUN: echo "}"  >> %t/InputsD/module.map
+// RUN: %clang_cc1 -triple=thumbv7-unknown-windows-msvc -DENABLE_WINMSVC -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/InputsD %s  -verify
+
+#ifdef ENABLE_WINMSVC
+@import RequiresWinMSVCA;
+@import RequiresWinMSVCB;
+@import RequiresWinMSVCC;
+#endif
Index: cfe/trunk/lib/Basic/Module.cpp
===

[PATCH] D51789: [clang] Add the exclude_from_explicit_instantiation attribute

2018-09-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D51789#1238410, @ldionne wrote:

> In https://reviews.llvm.org/D51789#1238396, @rjmccall wrote:
>
> > That may work for libc++'s purposes, but it's clearly inappropriate as a 
> > compiler rule.  There are good reasons why something with hidden visibility 
> > would need to be explicitly instantiated.
>
>
> I take your word for it, but I can't think of any example. For my education, 
> do you have a specific example in mind?


I mean, most code doesn't use explicit instantiations to begin with, but — the 
general idea would be someone using an explicit instantiation, either for 
compile-time or seperate-compilation reasons, for some type that's entirely 
private to their library.

Here's an example of it from Swift that happened to be easy to find:

  
https://github.com/apple/swift/blob/master/lib/SILOptimizer/ARC/RCStateTransitionVisitors.h

The entire template being instantiated there is private to the SILOptimizer 
library.  Swift doesn't use explicit visibility attributes much, preferring to 
globally assume `-fvisibility=hidden`, but if we used them, there would 
definitely be an attribute on that template.

>> For many programmers, hidden visibility means "this is private to my 
>> library", not "this is actually public to my library, but I'm walking an ABI 
>> tightrope".
> 
> In libc++'s case, the functions we will annotate with 
> `exclude_from_explicit_instantiation` are private to libc++ too (in the sense 
> that we don't want them part of the ABI and they are not exported from the 
> dylib). Those functions were previously marked with `__always_inline__` to 
> make sure they were not part of the ABI.

Yeah, I understand the use case.  That's what I was calling an ABI tightrope.  
The functions you're annotating are still part of libc++'s *logical* interface, 
they're just not exported by the dylib.

> Note that I'm quite happy with `exclude_from_explicit_instantiation` as it 
> solves libc++'s problem -- I'm trying to see whether another solution would 
> serve people better while still solving libc++'s problem. (Appart from 
> explicitly exporting functions, typeinfos and vtables like we've talked about 
> on cfe-dev, which is a superior solution to everything else but is left as a 
> future improvement for the time being).

Understood.

John.


Repository:
  rC Clang

https://reviews.llvm.org/D51789



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


Re: [PATCH] D51438: [clangd] Run SignatureHelp using an up-to-date preamble, waiting if needed.

2018-09-18 Thread Yvan Roux via cfe-commits
Hi Sam,

It took a very long time to identify it, but this commit broke ARMv7
bots, where this test hangs.  Logs are available here (initial ones
are too old):

http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/3685/steps/ninja%20check%201/logs/stdiohttp://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/3685/steps/ninja%20check%201/logs/stdio

Thanks,
YvanOn Thu, 30 Aug 2018 at 17:15, Sam McCall via Phabricator via
cfe-commits  wrote:
>
> sammccall added inline comments.
>
>
> 
> Comment at: clangd/TUScheduler.cpp:474
> +llvm::unique_function)> 
> Callback) {
> +  if (RunSync)
> +return Callback(getPossiblyStalePreamble());
> 
> ilya-biryukov wrote:
> > It seems we could remove the special-casing of `RunSync` and still get 
> > correct results (the Requests queue is always empty).
> > But feel free to keep it for clarity.
> Right, of course :-)
> Replaced this with an assert before we write to the queue.
>
>
> 
> Comment at: clangd/TUScheduler.h:123
> +  /// Controls whether preamble reads wait for the preamble to be up-to-date.
> +  enum PreambleConsistency {
> +/// The preamble is generated from the current version of the file.
> 
> ilya-biryukov wrote:
> > Maybe use a strongly-typed enum outside the class?
> > `TUScheduler::Stale` will turn into `PreambleConsistency::Stale` at the 
> > call-site. The main upside is that it does not pollute completions inside 
> > the class with enumerators.
> >
> > Just a suggestion, feel free to ignore.
> Yeah, the downside to that is that it *does* pollute the clangd:: namespace. 
> So both are a bit sad.
>
> This header is fairly widely visible (since it's included by clangdserver) 
> and this API is fairly narrowly interesting, so as far as completion goes I 
> think I prefer it being hidden in TUScheduler.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D51438
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52084: [clangd] Improve PostingList iterator string representation

2018-09-18 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

In https://reviews.llvm.org/D52084#1238537, @sammccall wrote:

> This change seems fine but...
>
> This representation with the raw DocIDs and position dumped seems mostly 
> useful for debugging buggy iterator implementations, but not really useful 
> for understanding query structure and behavior.


I agree; There is another issue that I was looking into: I think that it might 
be useful to understand the structure of fuzzy find query when using `dexp` 
tool and I thought that it would be great if we could dump the iterator tree 
structure along with the results (which is an extension of 
https://reviews.llvm.org/D52233). For `dexp` usecase, it would be great to dump 
the size and the origin of each piece of iterator tree (e.g. labels), but I 
also think that it might be useful to have "debugging" format so I couldn't 
figure out what's the best approach here.

> I thought we might be replacing this soon. Of course there's no fundamental 
> reason we can't keep both but I'm curious why this is an area of focus :-)

Yes, we are. Initially, this wasn't an area of focus: I just forgot to update 
the comment in `Iterator.h` when moving `PostingList` to a separate file and 
slightly changing the format, but then Eric had a good proposal and I thought 
that it's a good improvement. Also, even though the implementation will be 
different, the dumping format could be the same, so it's not really 
implementation-specific.


https://reviews.llvm.org/D52084



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


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sure, looks good. Though my other/vague concern is why does this case error 
about fomit-frame-pointer having no effect, but other things (like using 
-fomit-frame-pointer on a target that requires frame pointers) that ignore 
-fomit-frame-pointer don't? Weird. But it probably makes sense somehow.


Repository:
  rC Clang

https://reviews.llvm.org/D52191



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


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Stephen Hines via Phabricator via cfe-commits
srhines added a comment.

In https://reviews.llvm.org/D52191#1238628, @dblaikie wrote:

> Sure, looks good. Though my other/vague concern is why does this case error 
> about fomit-frame-pointer having no effect, but other things (like using 
> -fomit-frame-pointer on a target that requires frame pointers) that ignore 
> -fomit-frame-pointer don't? Weird. But it probably makes sense somehow.


I think the original issue is that one should not **explicitly** say "omit 
frame pointers" and "instrument for profiling with mcount". It's possible that 
there should be other errors for using "omit frame pointers" on targets that 
require them, but that should be checked independently elsewhere. Do we have 
many (any) of these kinds of targets? I'm going to submit this patch, but am 
happy to add a diagnostic later on for the other case, if you think that is 
worthwhile.


Repository:
  rC Clang

https://reviews.llvm.org/D52191



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


r342501 - Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Stephen Hines via cfe-commits
Author: srhines
Date: Tue Sep 18 11:34:33 2018
New Revision: 342501

URL: http://llvm.org/viewvc/llvm-project?rev=342501&view=rev
Log:
Fix logic around determining use of frame pointer with -pg.

Summary:
As part of r342165, I rewrote the logic to check whether
-fno-omit-frame-pointer was passed after a -fomit-frame-pointer
argument. This CL switches that logic to use the consolidated
shouldUseFramePointer() function. This fixes a potential issue where -pg
gets used with -fomit-frame-pointer on a platform that must always retain
frame pointers.

Reviewers: dblaikie

Reviewed By: dblaikie

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=342501&r1=342500&r2=342501&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Sep 18 11:34:33 2018
@@ -4956,8 +4956,7 @@ void Clang::ConstructJob(Compilation &C,
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-if (Args.hasFlag(options::OPT_fomit_frame_pointer,
- options::OPT_fno_omit_frame_pointer, /*default=*/false))
+if (shouldUseFramePointer(Args, Triple))
   D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
   << A->getAsString(Args);
 


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


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Stephen Hines via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342501: Fix logic around determining use of frame pointer 
with -pg. (authored by srhines, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52191

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp


Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4956,8 +4956,7 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-if (Args.hasFlag(options::OPT_fomit_frame_pointer,
- options::OPT_fno_omit_frame_pointer, /*default=*/false))
+if (shouldUseFramePointer(Args, Triple))
   D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
   << A->getAsString(Args);
 


Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4956,8 +4956,7 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-if (Args.hasFlag(options::OPT_fomit_frame_pointer,
- options::OPT_fno_omit_frame_pointer, /*default=*/false))
+if (shouldUseFramePointer(Args, Triple))
   D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
   << A->getAsString(Args);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Stephen Hines via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC342501: Fix logic around determining use of frame pointer 
with -pg. (authored by srhines, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52191?vs=165826&id=166007#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52191

Files:
  lib/Driver/ToolChains/Clang.cpp


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4956,8 +4956,7 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-if (Args.hasFlag(options::OPT_fomit_frame_pointer,
- options::OPT_fno_omit_frame_pointer, /*default=*/false))
+if (shouldUseFramePointer(Args, Triple))
   D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
   << A->getAsString(Args);
 


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4956,8 +4956,7 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-if (Args.hasFlag(options::OPT_fomit_frame_pointer,
- options::OPT_fno_omit_frame_pointer, /*default=*/false))
+if (shouldUseFramePointer(Args, Triple))
   D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
   << A->getAsString(Args);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r342505 - [clangd] Fix error handling for SymbolID parsing (notably YAML and dexp)

2018-09-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Sep 18 12:00:59 2018
New Revision: 342505

URL: http://llvm.org/viewvc/llvm-project?rev=342505&view=rev
Log:
[clangd] Fix error handling for SymbolID parsing (notably YAML and dexp)

Modified:
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=342505&r1=342504&r2=342505&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Tue Sep 18 12:00:59 2018
@@ -41,8 +41,13 @@ SymbolID SymbolID::fromRaw(llvm::StringR
 
 std::string SymbolID::str() const { return toHex(raw()); }
 
-void operator>>(StringRef Str, SymbolID &ID) {
-  ID = SymbolID::fromRaw(fromHex(Str));
+llvm::Expected SymbolID::fromStr(llvm::StringRef Str) {
+  if (Str.size() != RawSize * 2)
+return createStringError(llvm::inconvertibleErrorCode(), "Bad ID length");
+  for (char C : Str)
+if (!isHexDigit(C))
+  return createStringError(llvm::inconvertibleErrorCode(), "Bad hex ID");
+  return fromRaw(fromHex(Str));
 }
 
 raw_ostream &operator<<(raw_ostream &OS, SymbolOrigin O) {

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=342505&r1=342504&r2=342505&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Tue Sep 18 12:00:59 2018
@@ -91,12 +91,12 @@ public:
 return StringRef(reinterpret_cast(HashValue.data()), 
RawSize);
   }
   static SymbolID fromRaw(llvm::StringRef);
+
   // Returns a 40-bytes hex encoded string.
   std::string str() const;
+  static llvm::Expected fromStr(llvm::StringRef);
 
 private:
-  friend void operator>>(llvm::StringRef Str, SymbolID &ID);
-
   std::array HashValue;
 };
 
@@ -108,15 +108,9 @@ inline llvm::hash_code hash_value(const
   return llvm::hash_code(Result);
 }
 
-// Write SymbolID into the given stream. SymbolID is encoded as a 40-bytes
-// hex string.
+// Write SymbolID into the given stream. SymbolID is encoded as ID.str().
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID);
 
-// Construct SymbolID from a hex string.
-// The HexStr is required to be a 40-bytes hex string, which is encoded from 
the
-// "<<" operator.
-void operator>>(llvm::StringRef HexStr, SymbolID &ID);
-
 } // namespace clangd
 } // namespace clang
 namespace llvm {

Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=342505&r1=342504&r2=342505&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Tue Sep 18 12:00:59 2018
@@ -40,10 +40,13 @@ struct NormalizedSymbolID {
 OS << ID;
   }
 
-  SymbolID denormalize(IO &) {
-SymbolID ID;
-HexString >> ID;
-return ID;
+  SymbolID denormalize(IO &I) {
+auto ID = SymbolID::fromStr(HexString);
+if (!ID) {
+  I.setError(llvm::toString(ID.takeError()));
+  return SymbolID();
+}
+return *ID;
   }
 
   std::string HexString;

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=342505&r1=342504&r2=342505&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Tue Sep 18 12:00:59 
2018
@@ -144,14 +144,14 @@ class Lookup : public Command {
   };
 
   void run() override {
-auto Raw = fromHex(ID);
-if (Raw.size() != clang::clangd::SymbolID::RawSize) {
-  llvm::outs() << "invalid SymbolID\n";
+auto SID = clang::clangd::SymbolID::fromStr(ID);
+if (!SID) {
+  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
   return;
 }
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {clang::clangd::SymbolID::fromRaw(Raw)};
+Request.IDs = {*SID};
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;

Modified: clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp?rev=342505&r1=342504&r2=342505&view=diff
===

[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In https://reviews.llvm.org/D52191#1238648, @srhines wrote:

> In https://reviews.llvm.org/D52191#1238628, @dblaikie wrote:
>
> > Sure, looks good. Though my other/vague concern is why does this case error 
> > about fomit-frame-pointer having no effect, but other things (like using 
> > -fomit-frame-pointer on a target that requires frame pointers) that ignore 
> > -fomit-frame-pointer don't? Weird. But it probably makes sense somehow.
>
>
> I think the original issue is that one should not **explicitly** say "omit 
> frame pointers" and "instrument for profiling with mcount". It's possible 
> that there should be other errors for using "omit frame pointers" on targets 
> that require them, but that should be checked independently elsewhere. Do we 
> have many (any) of these kinds of targets? I'm going to submit this patch, 
> but am happy to add a diagnostic later on for the other case, if you think 
> that is worthwhile.


Yeah, looks like the other cases (targets, specifically - and yeah, I didn't 
look at the implementation of shouldUseFramePointer far enough to see which 
targets, etc - OK, I just looked now, and it's Darwin ARM & Thumb - so arguably 
on those targets, since -fomit-frame-pointer has no effect, maybe it's not 
important to error on -fomit-frame-pointer -pg)

Also I just realized you probably want/need "!shouldUseFramePointer" on your 
error. (missed the inversion) - sorry I didn't catch that in review. Should 
catch that with your test from the previous change?


Repository:
  rL LLVM

https://reviews.llvm.org/D52191



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


Re: [clang-tools-extra] r342227 - [clangd] NFC: Fix IndexBenchmark CLI arguments handling

2018-09-18 Thread Kirill Bobyrev via cfe-commits
Hi Roman,

Is there any benefit of doing so? Also, I’m not sure whether I understood you 
correctly. Consuming benchmark options *before* trimming would probably not be 
the desired behaviour since the first two arguments arguments are passed 
directly to the tool driver.

I might have misunderstood you, could you please elaborate on the proposed idea?

Kind regards,
Kirill

> On 14 Sep 2018, at 14:46, Roman Lebedev  wrote:
> 
> On Fri, Sep 14, 2018 at 3:21 PM, Kirill Bobyrev via cfe-commits
>  wrote:
>> Author: omtcyfz
>> Date: Fri Sep 14 05:21:09 2018
>> New Revision: 342227
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=342227&view=rev
>> Log:
>> [clangd] NFC: Fix IndexBenchmark CLI arguments handling
>> 
>> Modified:
>>clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
>> 
>> Modified: clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp?rev=342227&r1=342226&r2=342227&view=diff
>> ==
>> --- clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp Fri Sep 14 
>> 05:21:09 2018
>> @@ -101,9 +101,11 @@ int main(int argc, char *argv[]) {
>>   }
> 
>>   IndexFilename = argv[1];
>>   RequestsFilename = argv[2];
>> -  // Trim first two arguments of the benchmark invocation.
>> -  argv += 3;
>> -  argc -= 3;
>> +  // Trim first two arguments of the benchmark invocation and pretend no
>> +  // arguments were passed in the first place.
>> +  argv[2] = argv[0];
>> +  argv += 2;
>> +  argc -= 2;
>>   ::benchmark::Initialize(&argc, argv);
> Passing-by thought: why is this being done in *this* order?
> Why not first let the ::benchmark::Initialize() consume it's flags first?
> 
>>   ::benchmark::RunSpecifiedBenchmarks();
>> }
>> 
> Roman.
> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


Re: [clang-tools-extra] r342227 - [clangd] NFC: Fix IndexBenchmark CLI arguments handling

2018-09-18 Thread Roman Lebedev via cfe-commits
On Tue, Sep 18, 2018 at 10:09 PM, Kirill Bobyrev
 wrote:
> Hi Roman,
>
> Is there any benefit of doing so? Also, I’m not sure whether I understood you 
> correctly. Consuming benchmark options *before* trimming would probably not 
> be the desired behaviour since the first two arguments arguments are passed 
> directly to the tool driver.
Currently, you have to call it like
$ IndexBenchmark IndexFilename RequestsFilename --benchmark_something

If you do
$ IndexBenchmark --benchmark_something IndexFilename RequestsFilename
your code will still consume argv[1] (i.e. "--benchmark_something") as
IndexFilename

But if you do call  ::benchmark::Initialize(&argc, argv);  first it
will work as you'd expect,
i.e. you would still consume argv[1], but it then would have been
adjusted to IndexFilename

> I might have misunderstood you, could you please elaborate on the proposed 
> idea?
>
> Kind regards,
> Kirill
Roman.

>> On 14 Sep 2018, at 14:46, Roman Lebedev  wrote:
>>
>> On Fri, Sep 14, 2018 at 3:21 PM, Kirill Bobyrev via cfe-commits
>>  wrote:
>>> Author: omtcyfz
>>> Date: Fri Sep 14 05:21:09 2018
>>> New Revision: 342227
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=342227&view=rev
>>> Log:
>>> [clangd] NFC: Fix IndexBenchmark CLI arguments handling
>>>
>>> Modified:
>>>clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
>>>
>>> Modified: clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp?rev=342227&r1=342226&r2=342227&view=diff
>>> ==
>>> --- clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp (original)
>>> +++ clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp Fri Sep 14 
>>> 05:21:09 2018
>>> @@ -101,9 +101,11 @@ int main(int argc, char *argv[]) {
>>>   }
>>
>>>   IndexFilename = argv[1];
>>>   RequestsFilename = argv[2];
>>> -  // Trim first two arguments of the benchmark invocation.
>>> -  argv += 3;
>>> -  argc -= 3;
>>> +  // Trim first two arguments of the benchmark invocation and pretend no
>>> +  // arguments were passed in the first place.
>>> +  argv[2] = argv[0];
>>> +  argv += 2;
>>> +  argc -= 2;
>>>   ::benchmark::Initialize(&argc, argv);
>> Passing-by thought: why is this being done in *this* order?
>> Why not first let the ::benchmark::Initialize() consume it's flags first?
>>
>>>   ::benchmark::RunSpecifiedBenchmarks();
>>> }
>>>
>> Roman.
>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r342227 - [clangd] NFC: Fix IndexBenchmark CLI arguments handling

2018-09-18 Thread Kirill Bobyrev via cfe-commits
Thanks for the explanation! I didn’t know that benchmark’s Initialize does 
that, that was probably the source of my confusion. The suggestion looks 
reasonable, I should try this approach, it looks to be cleaner.

-Kirill

> On 18 Sep 2018, at 21:16, Roman Lebedev  wrote:
> 
> On Tue, Sep 18, 2018 at 10:09 PM, Kirill Bobyrev
>  wrote:
>> Hi Roman,
>> 
>> Is there any benefit of doing so? Also, I’m not sure whether I understood 
>> you correctly. Consuming benchmark options *before* trimming would probably 
>> not be the desired behaviour since the first two arguments arguments are 
>> passed directly to the tool driver.
> Currently, you have to call it like
> $ IndexBenchmark IndexFilename RequestsFilename --benchmark_something
> 
> If you do
> $ IndexBenchmark --benchmark_something IndexFilename RequestsFilename
> your code will still consume argv[1] (i.e. "--benchmark_something") as
> IndexFilename
> 
> But if you do call  ::benchmark::Initialize(&argc, argv);  first it
> will work as you'd expect,
> i.e. you would still consume argv[1], but it then would have been
> adjusted to IndexFilename
> 
>> I might have misunderstood you, could you please elaborate on the proposed 
>> idea?
>> 
>> Kind regards,
>> Kirill
> Roman.
> 
>>> On 14 Sep 2018, at 14:46, Roman Lebedev  wrote:
>>> 
>>> On Fri, Sep 14, 2018 at 3:21 PM, Kirill Bobyrev via cfe-commits
>>>  wrote:
 Author: omtcyfz
 Date: Fri Sep 14 05:21:09 2018
 New Revision: 342227
 
 URL: http://llvm.org/viewvc/llvm-project?rev=342227&view=rev
 Log:
 [clangd] NFC: Fix IndexBenchmark CLI arguments handling
 
 Modified:
   clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
 
 Modified: clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp
 URL: 
 http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp?rev=342227&r1=342226&r2=342227&view=diff
 ==
 --- clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp (original)
 +++ clang-tools-extra/trunk/clangd/benchmarks/IndexBenchmark.cpp Fri Sep 
 14 05:21:09 2018
 @@ -101,9 +101,11 @@ int main(int argc, char *argv[]) {
  }
>>> 
  IndexFilename = argv[1];
  RequestsFilename = argv[2];
 -  // Trim first two arguments of the benchmark invocation.
 -  argv += 3;
 -  argc -= 3;
 +  // Trim first two arguments of the benchmark invocation and pretend no
 +  // arguments were passed in the first place.
 +  argv[2] = argv[0];
 +  argv += 2;
 +  argc -= 2;
  ::benchmark::Initialize(&argc, argv);
>>> Passing-by thought: why is this being done in *this* order?
>>> Why not first let the ::benchmark::Initialize() consume it's flags first?
>>> 
  ::benchmark::RunSpecifiedBenchmarks();
 }
 
>>> Roman.
>>> 
 ___
 cfe-commits mailing list
 cfe-commits@lists.llvm.org
 http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>> 

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


[PATCH] D52200: Thread safety analysis: Handle ObjCIvarRefExpr in SExprBuilder::translate

2018-09-18 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert planned changes to this revision.
aaronpuchert added a comment.

Thanks to both of you for the reviews. I'll see what I can do about the arrows. 
My gut feeling is that using `{Member,ObjCIVarRef}Expr::isArrow` is the right 
way, but it's not yet obvious to me how.




Comment at: include/clang/Analysis/Analyses/ThreadSafetyCommon.h:400
   til::SExpr *translateMemberExpr(const MemberExpr *ME, CallingContext *Ctx);
+  til::SExpr *translateObjCIVarRefExpr(const ObjCIvarRefExpr *ME,
+   CallingContext *Ctx);

aaron.ballman wrote:
> `ME` is kind of a poor name; can you switch to `IVRE` like you used in the 
> implementation?
Of course, that's a copy-and-paste error.



Comment at: lib/Analysis/ThreadSafetyCommon.cpp:362
+  til::Project *P = new (Arena) til::Project(E, D);
+  if (hasCppPointerType(BE))
+P->setArrow(true);

rjmccall wrote:
> aaron.ballman wrote:
> > I feel like this will always return false. However, I wonder if 
> > `IVRE->getBase()->isArrow()` is more appropriate here?
> The base of an `ObjCIvarRefExpr` will never directly be a C pointer type.  I 
> don't know whether this data structure looks through casts, but it's 
> certainly *possible* to cast arbitrarily weird C stuff to ObjC pointer type.  
> On the other hand, by and large nobody actually ever does that, so I wouldn't 
> make a special case for it here.
> 
> `ObjCIvarRefExpr` just has an `isArrow()` method directly if this is just 
> supposed to be capturing the difference between `.` and `->`.  But then, so 
> does `MemberExpr`, and in that case you're doing this odd analysis of the 
> base instead of trusting `isArrow()`, so I don't know what to tell you to do.
> 
> Overall it is appropriate to treat an ObjC ivar reference as a perfectly 
> ordinary projection.  The only thing that's special about it is that the 
> actual offset isn't necessarily statically known, but ivars still behave as 
> if they're all independently declared, so I wouldn't worry about it.
I had wondered about this as well, but when I changed `hasCppPointerType(BE)` 
to `ME->isArrow()` in the `MemberExpr` case, I got some test failures. For 
example:

```
struct Foo {
  int a __attribute__((guarded_by(mu)));
  Mutex mu;
};

void f() {
  Foo foo;
  foo.a = 5; // \
// expected-warning{{writing variable 'a' requires holding mutex 'foo.mu' 
exclusively}}
}
```

Instead we warn `writing variable 'a' requires holding mutex 'foo->mu' 
exclusively`. That's not right.

The expression (`ME`) we are processing is `mu` from the attribute on `a`, 
which the compiler sees as `this->mu`. So we get `ME->isArrow() == true` and 
`ME->getBase()` is a `CXXThisExpr`.

Basically the `translate*` functions do a substitution. They try to derive 
`foo.mu` from `this->mu` on the `a` member and the expression `foo.a`. The 
annotation `this->mu` is the expression we get as parameter, and `foo.a` is 
encoded in the `CallingContext`.

The information whether `foo.a` is an arrow (it isn't) seems to be in the 
`CallingContext`'s `SelfArrow` member.


Repository:
  rC Clang

https://reviews.llvm.org/D52200



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


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Seems like this change causes 2 test failures:

  Clang :: Driver/clang_f_opts.c
  Clang :: Frontend/gnu-mcount.c

Some of the failing bots are

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/15363/
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/53328/


Repository:
  rL LLVM

https://reviews.llvm.org/D52191



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


[PATCH] D50901: [clang][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks

2018-09-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@rsmith - ping.
This one should be rather uncontroversial i think? Is this moving in the 
direction you suggested? :)


Repository:
  rC Clang

https://reviews.llvm.org/D50901



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


[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Rumeet Dhindsa via Phabricator via cfe-commits
rdhindsa added a comment.

It seems that following tests are broken with this change:

clang/test/Driver/clang_f_opts.c
clang/test/Frontend/gnu-mcount.c


Repository:
  rL LLVM

https://reviews.llvm.org/D52191



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


RE: r342501 - Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread via cfe-commits
Hi Stephen,

Your change is causing a test failure on the PS4 linux bot, can you please take 
a look?

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/36712/steps/test/logs/stdio

FAIL: Clang :: Driver/clang_f_opts.c (8141 of 44013)
 TEST 'Clang :: Driver/clang_f_opts.c' FAILED 

...
Command Output (stderr):
--
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/Driver/clang_f_opts.c:537:29:
 error: CHECK-NO-MIX-OMIT-FP-PG: expected string not found in input
// CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
^
:1:1: note: scanning from here
clang version 8.0.0 (trunk 342502)
^
:5:934: note: possible intended match here
 
"/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang-8"
 "-cc1" "-triple" "x86_64-scei-ps4" "-S" "-disable-free" "-main-file-name" 
"clang_f_opts.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" 
"posix" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" 
"btver2" "-debugger-tuning=sce" "-mllvm" "-generate-arange-section" 
"-debug-forward-template-params" "-dwarf-explicit-import" 
"-coverage-notes-file" 
"/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/test/Driver/clang_f_opts.gcno"
 "-resource-dir" 
"/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/lib/clang/8.0.0"
 "-fdebug-compilation-dir" 
"/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/test/Driver"
 "-fstack-size-section" "-ferror-limit" "19" "-fmessage-length" "0" "-pg" 
"-stack-protector" "2" "-fdeclspec" "-fobjc-runtime=gnustep" 
"-fdiagnostics-show-option" "-o" "clang_f_opts.s" "-x" "c" 
"/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/Driver/clang_f_opts.c"
 "-faddrsig"











 ^

Douglas Yung

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of Stephen Hines via cfe-commits
> Sent: Tuesday, September 18, 2018 11:35
> To: cfe-commits@lists.llvm.org
> Subject: r342501 - Fix logic around determining use of frame pointer
> with -pg.
> 
> Author: srhines
> Date: Tue Sep 18 11:34:33 2018
> New Revision: 342501
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=342501&view=rev
> Log:
> Fix logic around determining use of frame pointer with -pg.
> 
> Summary:
> As part of r342165, I rewrote the logic to check whether
> -fno-omit-frame-pointer was passed after a -fomit-frame-pointer
> argument. This CL switches that logic to use the consolidated
> shouldUseFramePointer() function. This fixes a potential issue where -
> pg
> gets used with -fomit-frame-pointer on a platform that must always
> retain
> frame pointers.
> 
> Reviewers: dblaikie
> 
> Reviewed By: dblaikie
> 
> Subscribers: cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D52191
> 
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> 
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=342501&r1=342500&
> r2=342501&view=diff
> ===
> ===
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Sep 18 11:34:33 2018
> @@ -4956,8 +4956,7 @@ void Clang::ConstructJob(Compilation &C,
>}
> 
>if (Arg *A = Args.getLastArg(options::OPT_pg))
> -if (Args.hasFlag(options::OPT_fomit_frame_pointer,
> - options::OPT_fno_omit_frame_pointer,
> /*default=*/false))
> +if (shouldUseFramePointer(Args, Triple))
>D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-
> frame-pointer"
><< A-
> >getAsString(Args);
> 
> 
> 
> ___

[PATCH] D52191: Fix logic around determining use of frame pointer with -pg.

2018-09-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Confirm that reverting the change locally fixes the tests. If nobody beats me 
to it, I plan to revert the change in 30-60 minutes. @srhines, if you want to 
fix it in another way and need more time, please let me know.


Repository:
  rL LLVM

https://reviews.llvm.org/D52191



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


  1   2   >