[PATCH] D41345: [clangd] Add more symbol information for code completion.

2017-12-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/Index.h:92
 
+  // Documentation including comment for the symbol declaration.
+  std::string Documentation;

AFAIK this information isn't needed for retrieval/scoring, just for display.

LSP has `completionItem/resolve` that adds additional info to a completion 
item. This allows us to avoid sending a bunch of bulky comments, most of which 
will never be looked at.

In practice, there's nothing we particularly want to do differently for the 
memory index: we have to load the data into memory, and so including a pointer 
to it right away is no extra work.

However Symbol has two roles, and being the in-memory representation for 
MemIndex is only secondary. Its primary role is defining the protocol between 
indexes and clangd, including remote indexes where returning all documentation 
*is* expensive.

One option is to have Symbol just have the "core stuff" that's suitable for 
returning in bulk, and have an index method to retrieve more details that would 
be a point lookup only. (Maybe this is just the getSymbol method we've thought 
about). I'm not sure what it means for the data structure. OK if we discuss 
offline?



Comment at: clangd/index/Index.h:99
+  // Detail about the symbol. For example, the result type of a function.
+  std::string CompletionDetail;
+  // The placeholder text for function parameters in order.

What are you planning to put here other than the return type of a function?
It's probably OK if we explicitly want this to be "whatever should go in the 
LSP detail field" but we should think about whether there's something more 
specific we can say.



Comment at: clangd/index/Index.h:100
+  std::string CompletionDetail;
+  // The placeholder text for function parameters in order.
+  std::vector Params;

How are you planning to use this?

This seems to be related to the completion text/edits. We had some early 
discussions about whether we'd encode something like CodeCompletionString, or 
LSP snippets, or something else entirely.
Honestly it would be great to have a doc describing this mapping between source 
-> index -> LSP for completion data.



Comment at: clangd/index/SymbolCollector.cpp:61
+
+std::string getDocumentation(const CodeCompletionString &CCS) {
+  // Things like __attribute__((nonnull(1,3))) and [[noreturn]]. Present this

it seems we'll want to share the(some?) doc logic between hover, AST-based 
complete, and indexing... See D35894 (which is ... complicated, no idea if 
it'll land soon).

Among other things:
 - we may not want to make the logic too elaborate until we're able to merge 
interfaces
 - we may want to consume AST nodes rather than CCS in the long run



Comment at: clangd/index/SymbolCollector.cpp:67
+  if (AnnotationCount > 0) {
+Result += "Annotation";
+if (AnnotationCount == 1) {

Should these annotations go at the end?



Comment at: clangd/index/SymbolCollector.cpp:90
+
+void ProcessChunks(const CodeCompletionString &CCS, Symbol *Sym) {
+  for (const auto &Chunk : CCS) {

nit: lowercase



Comment at: clangd/index/SymbolCollector.cpp:90
+
+void ProcessChunks(const CodeCompletionString &CCS, Symbol *Sym) {
+  for (const auto &Chunk : CCS) {

sammccall wrote:
> nit: lowercase
How does this relate to the code in AST-based completion?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41345



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


[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

Thanks for addressing the comments quickly.
I took another look and added a few more comments.
This moves in the right direction, though, this is really close to landing.




Comment at: clangd/ClangdServer.cpp:25
 #include 
+#include 
 

Is this include redundant now? Can we remove it?



Comment at: clangd/ClangdServer.cpp:430
+  Resources->getAST().get()->runUnderLock([Pos, &Result, &Ctx,
+   this](ParsedAST *AST) {
 if (!AST)

Capturing `this` seems redundant. Remove it?



Comment at: clangd/ClangdUnit.cpp:85
+
+if (SourceMgr.getMainFileID() == 
SourceMgr.getFileID(FilenameRange.getAsRange().getBegin()) && 
SourceMgr.isInMainFile(FilenameRange.getAsRange().getBegin())) {
+  // Only inclusion directives in the main file make sense. The user cannot

`clang-format` please



Comment at: clangd/ClangdUnit.cpp:85
+
+if (SourceMgr.getMainFileID() == 
SourceMgr.getFileID(FilenameRange.getAsRange().getBegin()) && 
SourceMgr.isInMainFile(FilenameRange.getAsRange().getBegin())) {
+  // Only inclusion directives in the main file make sense. The user cannot

ilya-biryukov wrote:
> `clang-format` please
Do we need both checks? Doesn't `SourceMgr.isInMainFile` handles all the cases?



Comment at: clangd/ClangdUnit.cpp:113
 
+  CppFilePreambleCallbacks(IncludeReferenceMap &IRM)
+  : IRM(IRM) {}

Let's create a new empty map inside this class and have a 
`takeIncludeReferences` method (similar to `TopLevelDeclIDs` and 
`takeTopLevelDeclIDs`)



Comment at: clangd/ClangdUnit.cpp:147
+  IncludeReferenceMap &IRM;
+  std::vector> 
TempPreambleIncludeLocations;
 };

We should have `SourceMgr` at all the proper places now, let's store 
`IncludeReferenceMap` directly



Comment at: clangd/ClangdUnit.cpp:281
+ IntrusiveRefCntPtr VFS,
+ IncludeReferenceMap IRM) {
 

What reference does this `IncludeReferenceMap` contain? Includes from the 
preamble? 



Comment at: clangd/ClangdUnit.cpp:347
  const SourceLocation &SearchedLocation,
- ASTContext &AST, Preprocessor &PP)
-  : SearchedLocation(SearchedLocation), AST(AST), PP(PP) {}
+ ASTContext &AST, Preprocessor &PP, const 
IncludeReferenceMap &IncludeLocationMap)
+  : SearchedLocation(SearchedLocation), AST(AST), PP(PP), 
IncludeLocationMap(IncludeLocationMap) {}

This class handles processing AST and preprocessor, it does not need to get 
`IncludeLocationMap` in constructor or store it at all.
Remove `IncludeLocationMap` from this class and handle getting references from 
`IncludeLocationMap` outside this class instead.



Comment at: clangd/ClangdUnit.h:97
 
+  IncludeReferenceMap &getIRM() { return IRM; };
+

Make it all const?

`const IncludeReferenceMap &getIRM() const { return IRM; }`



Comment at: clangd/ClangdUnit.h:276
+std::vector
+findDefinitions(const Context &Ctx, ParsedAST &AST, Position Pos);
+

This function moved without need and lost a comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639



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


[PATCH] D41237: [Frontend] Handle skipped bodies in template instantiations

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:12184
 Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
-  if (FunctionDecl *FD = dyn_cast_or_null(Decl))
+  if (FunctionDecl *FD = Decl->getAsFunction())
 FD->setHasSkippedBody();

sepavloff wrote:
> In the case of `Decl == nullptr` this code would crash. Probably it makes 
> sense to check for this condition at the beginning of the function and use 
> `dyn_cast` instead of `dyn_cast_or_null` in the next check.
> 
Do we have callsites that pass null to this function? I don't see a meaningful 
semantics for this function if we pass null here.
I thought that `Decl`s are always passed via pointers by convention, but I may 
be wrong.


Repository:
  rC Clang

https://reviews.llvm.org/D41237



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


[PATCH] D41237: [Frontend] Handle skipped bodies in template instantiations

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:12184
 Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
-  if (FunctionDecl *FD = dyn_cast_or_null(Decl))
+  if (FunctionDecl *FD = Decl->getAsFunction())
 FD->setHasSkippedBody();

ilya-biryukov wrote:
> sepavloff wrote:
> > In the case of `Decl == nullptr` this code would crash. Probably it makes 
> > sense to check for this condition at the beginning of the function and use 
> > `dyn_cast` instead of `dyn_cast_or_null` in the next check.
> > 
> Do we have callsites that pass null to this function? I don't see a 
> meaningful semantics for this function if we pass null here.
> I thought that `Decl`s are always passed via pointers by convention, but I 
> may be wrong.
After looking at the callsites, they actually suggest that nulls can be passed. 
Tried adding an assert and it didn't fire when running `check-all`, though.

But it's better to be on the safe side. Added a check for null, updated the 
patch accordingly.


Repository:
  rC Clang

https://reviews.llvm.org/D41237



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


[PATCH] D41237: [Frontend] Handle skipped bodies in template instantiations

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 127473.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Added a check for null in ActOnSkippedBody


Repository:
  rC Clang

https://reviews.llvm.org/D41237

Files:
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/Index/skipped-bodies-templates.cpp


Index: test/Index/skipped-bodies-templates.cpp
===
--- /dev/null
+++ test/Index/skipped-bodies-templates.cpp
@@ -0,0 +1,27 @@
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source 
all %s 2>&1 \
+// RUN: | FileCheck %s
+
+
+template 
+struct Foo {
+  inline int with_body() {
+return 100;
+  }
+
+  inline int without_body();
+};
+
+
+int bar = Foo().with_body() + Foo().without_body();
+// CHECK-NOT: warning: inline function 'Foo::with_body' is not defined
+// CHECK: warning: inline function 'Foo::without_body' is not defined
+
+template 
+inline int with_body() { return 10; }
+
+template 
+inline int without_body();
+
+int baz = with_body() + without_body();
+// CHECK-NOT: warning: inline function 'with_body' is not defined
+// CHECK: warning: inline function 'without_body' is not defined
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3855,7 +3855,8 @@
   }
 
   // Note, we should never try to instantiate a deleted function template.
-  assert((Pattern || PatternDecl->isDefaulted()) &&
+  assert((Pattern || PatternDecl->isDefaulted() ||
+  PatternDecl->hasSkippedBody()) &&
  "unexpected kind of function template definition");
 
   // C++1y [temp.explicit]p10:
@@ -3940,16 +3941,20 @@
   }
 }
 
-// Instantiate the function body.
-StmtResult Body = SubstStmt(Pattern, TemplateArgs);
+if (PatternDecl->hasSkippedBody()) {
+  ActOnSkippedFunctionBody(Function);
+} else {
+  // Instantiate the function body.
+  StmtResult Body = SubstStmt(Pattern, TemplateArgs);
 
-if (Body.isInvalid())
-  Function->setInvalidDecl();
+  if (Body.isInvalid())
+Function->setInvalidDecl();
 
-// FIXME: finishing the function body while in an expression evaluation
-// context seems wrong. Investigate more.
-ActOnFinishFunctionBody(Function, Body.get(),
-/*IsInstantiation=*/true);
+  // FIXME: finishing the function body while in an expression evaluation
+  // context seems wrong. Investigate more.
+  ActOnFinishFunctionBody(Function, Body.get(),
+  /*IsInstantiation=*/true);
+}
 
 PerformDependentDiagnostics(PatternDecl, TemplateArgs);
 
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12179,9 +12179,11 @@
 }
 
 Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
-  if (FunctionDecl *FD = dyn_cast_or_null(Decl))
+  if (!Decl)
+return nullptr;
+  if (FunctionDecl *FD = Decl->getAsFunction())
 FD->setHasSkippedBody();
-  else if (ObjCMethodDecl *MD = dyn_cast_or_null(Decl))
+  else if (ObjCMethodDecl *MD = dyn_cast(Decl))
 MD->setHasSkippedBody();
   return Decl;
 }


Index: test/Index/skipped-bodies-templates.cpp
===
--- /dev/null
+++ test/Index/skipped-bodies-templates.cpp
@@ -0,0 +1,27 @@
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s 2>&1 \
+// RUN: | FileCheck %s
+
+
+template 
+struct Foo {
+  inline int with_body() {
+return 100;
+  }
+
+  inline int without_body();
+};
+
+
+int bar = Foo().with_body() + Foo().without_body();
+// CHECK-NOT: warning: inline function 'Foo::with_body' is not defined
+// CHECK: warning: inline function 'Foo::without_body' is not defined
+
+template 
+inline int with_body() { return 10; }
+
+template 
+inline int without_body();
+
+int baz = with_body() + without_body();
+// CHECK-NOT: warning: inline function 'with_body' is not defined
+// CHECK: warning: inline function 'without_body' is not defined
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3855,7 +3855,8 @@
   }
 
   // Note, we should never try to instantiate a deleted function template.
-  assert((Pattern || PatternDecl->isDefaulted()) &&
+  assert((Pattern || PatternDecl->isDefaulted() ||
+  PatternDecl->hasSkippedBody()) &&
  "unexpected kind of function template definition");
 
   // C++1y [temp.explicit]p10:
@@ -3940,16 +3941,20 @@
   }
 }
 
-// Instantiate the function body.
-StmtResult Body = SubstStmt(Pattern, TemplateArgs);
+if (PatternDecl->hasSkippedBody()) {
+  

[clang-tools-extra] r321065 - [clangd] Add unit tests for signature help. SigHelp/CodeComplete lit tests are smoke only.

2017-12-19 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Dec 19 02:29:27 2017
New Revision: 321065

URL: http://llvm.org/viewvc/llvm-project?rev=321065&view=rev
Log:
[clangd] Add unit tests for signature help. SigHelp/CodeComplete lit tests are 
smoke only.

Modified:
clang-tools-extra/trunk/test/clangd/completion.test
clang-tools-extra/trunk/test/clangd/signature-help.test
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/test/clangd/completion.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion.test?rev=321065&r1=321064&r2=321065&view=diff
==
--- clang-tools-extra/trunk/test/clangd/completion.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion.test Tue Dec 19 02:29:27 2017
@@ -6,13 +6,13 @@ Content-Length: 125
 
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 246
+Content-Length: 186
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  
fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 S { int a; };\nint main() {\nS().\n}"}}}
 
 Content-Length: 148
 
-{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":2,"character":4}}}
 #  CHECK:  "id": 1
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": {
@@ -27,157 +27,31 @@ Content-Length: 148
 # CHECK-NEXT:  "label": "a",
 # CHECK-NEXT:  "sortText": "{{.*}}a"
 # CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "bb",
-# CHECK-NEXT:  "insertText": "bb",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 5,
-# CHECK-NEXT:  "label": "bb",
-# CHECK-NEXT:  "sortText": "{{.*}}bb"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "ccc",
-# CHECK-NEXT:  "insertText": "ccc",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 5,
-# CHECK-NEXT:  "label": "ccc",
-# CHECK-NEXT:  "sortText": "{{.*}}ccc"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "f",
-# CHECK-NEXT:  "insertText": "f",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 2,
-# CHECK-NEXT:  "label": "f(int i, const float f) const",
-# CHECK-NEXT:  "sortText": "{{.*}}f"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "filterText": "fake",
-# CHECK-NEXT:  "insertText": "fake",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 7,
-# CHECK-NEXT:  "label": "fake::",
-# CHECK-NEXT:  "sortText": "{{.*}}fake"
-# CHECK-NEXT:},
-# FIXME: Why do buildbots show different operator=s here?
-#  CHECK:{
-#  CHECK:  "detail": "void",
-# CHECK-NEXT:  "filterText": "~fake",
-# CHECK-NEXT:  "insertText": "~fake",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 4,
-# CHECK-NEXT:  "label": "~fake()",
-# CHECK-NEXT:  "sortText": "{{.*}}~fake"
-# CHECK-NEXT:}
-# CHECK-NEXT:  ]
-Content-Length: 148
-
-{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
-#  CHECK:  "id": 2
-# CHECK-NEXT:  "jsonrpc": "2.0",
-# CHECK-NEXT:  "result": {
-# CHECK-NEXT:"isIncomplete": false,
-# CHECK-NEXT:"items": [
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "a",
-# CHECK-NEXT:  "insertText": "a",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 5,
-# CHECK-NEXT:  "label": "a",
-# CHECK-NEXT:  "sortText": "{{.*}}"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "bb",
-# CHECK-NEXT:  "insertText": "bb",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 5,
-# CHECK-NEXT:  "label": "bb",
-# CHECK-NEXT:  "sortText": "{{.*}}"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int",
-# CHECK-NEXT:  "filterText": "ccc",
-# CHECK-NEXT:  "insertText": "ccc",
-# CHECK-NEXT:  "insertTextFormat": 1,
-# CHECK-NEXT:  "kind": 5,
-# CHECK-NEXT:  "label": "ccc",
-# CHECK-NEXT:  "sortText": "{{.*}}"
-# CHECK-NEXT:},
-# CHECK-NEXT:{
-# CHECK-NEXT:  "detail": "int

[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

2017-12-19 Thread András Leitereg via Phabricator via cfe-commits
leanil created this revision.
leanil added reviewers: dcoughlin, xazax.hun.
Herald added subscribers: a.sidorin, rnkovacs, szepet.

It is safe to copy a string literal to an array which is compile time known to 
be large enough.
This reduces the number of false positives, while (hopefully) not introducing 
any false negatives.


https://reviews.llvm.org/D41384

Files:
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  test/Analysis/security-syntax-checks-no-emit.c


Index: test/Analysis/security-syntax-checks-no-emit.c
===
--- test/Analysis/security-syntax-checks-no-emit.c
+++ test/Analysis/security-syntax-checks-no-emit.c
@@ -32,3 +32,31 @@
   rand_r(&b);  // no-warning
   random();// no-warning
 }
+
+#ifdef USE_BUILTINS
+#define BUILTIN(f) __builtin_##f
+#else /* USE_BUILTINS */
+#define BUILTIN(f) f
+#endif /* USE_BUILTINS */
+
+//===--===
+// strcpy()
+//===--===
+#ifdef VARIANT
+
+#define __strcpy_chk BUILTIN(__strcpy_chk)
+char *__strcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
+
+#define strcpy(a, b) __strcpy_chk(a, b, (size_t)-1)
+
+#else /* VARIANT */
+
+#define strcpy BUILTIN(strcpy)
+char *strcpy(char *restrict s1, const char *restrict s2);
+
+#endif /* VARIANT */
+
+void test_strcpy() {
+  char x[5];
+  strcpy(x, "abcd");
+}
Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,18 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  int ArraySize = -1, StrLen = -1;
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(
+DeclRef->getDecl()->getType().getTypePtr()))
+  ArraySize = Array->getSize().getLimitedValue();
+  if (const auto *String = dyn_cast(Source))
+StrLen = String->getLength();
+  if (StrLen != -1 && ArraySize >= StrLen + 1)
+return;
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);


Index: test/Analysis/security-syntax-checks-no-emit.c
===
--- test/Analysis/security-syntax-checks-no-emit.c
+++ test/Analysis/security-syntax-checks-no-emit.c
@@ -32,3 +32,31 @@
   rand_r(&b);	// no-warning
   random();	// no-warning
 }
+
+#ifdef USE_BUILTINS
+#define BUILTIN(f) __builtin_##f
+#else /* USE_BUILTINS */
+#define BUILTIN(f) f
+#endif /* USE_BUILTINS */
+
+//===--===
+// strcpy()
+//===--===
+#ifdef VARIANT
+
+#define __strcpy_chk BUILTIN(__strcpy_chk)
+char *__strcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
+
+#define strcpy(a, b) __strcpy_chk(a, b, (size_t)-1)
+
+#else /* VARIANT */
+
+#define strcpy BUILTIN(strcpy)
+char *strcpy(char *restrict s1, const char *restrict s2);
+
+#endif /* VARIANT */
+
+void test_strcpy() {
+  char x[5];
+  strcpy(x, "abcd");
+}
Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,18 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  int ArraySize = -1, StrLen = -1;
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(
+DeclRef->getDecl()->getType().getTypePtr()))
+  ArraySize = Array->getSize().getLimitedValue();
+  if (const auto *String = dyn_cast(Source))
+StrLen = String->getLength();
+  if (StrLen != -1 && ArraySize >= StrLen + 1)
+return;
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127478.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367

Files:
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -31,7 +31,10 @@
 using testing::UnorderedElementsAre;
 
 // GMock helpers for matching Symbol.
-MATCHER_P(QName, Name, "") { return arg.second.QualifiedName == Name; }
+MATCHER_P(QName, Name, "") {
+  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
+  arg.second.Name) == Name;
+}
 
 namespace clang {
 namespace clangd {
@@ -111,7 +114,8 @@
   const std::string YAML1 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
-QualifiedName:   'clang::Foo1'
+Name:   'Foo1'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
@@ -124,7 +128,8 @@
   const std::string YAML2 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
-QualifiedName:   'clang::Foo2'
+Name:   'Foo2'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -19,45 +19,64 @@
 
 namespace {
 
-Symbol symbol(llvm::StringRef ID) {
+Symbol symbol(llvm::StringRef QName) {
   Symbol Sym;
-  Sym.ID = SymbolID(ID);
-  Sym.QualifiedName = ID;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos);
+  }
   return Sym;
 }
 
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
 };
 
-// Create a slab of symbols with IDs and names [Begin, End]. The life time of
-// the slab is managed by the returned shared pointer. If \p WeakSymbols is
-// provided, it will be pointed to the managed object in the returned shared
-// pointer.
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
 std::shared_ptr>
-generateNumSymbols(int Begin, int End,
-   std::weak_ptr *WeakSymbols = nullptr) {
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr) {
   auto Slab = std::make_shared();
   if (WeakSymbols)
 *WeakSymbols = Slab;
 
-  for (int i = Begin; i <= End; i++)
-Slab->Slab.insert(symbol(std::to_string(i)));
+  for (llvm::StringRef QName : QualifiedNames)
+Slab->Slab.insert(symbol(QName));
 
   for (const auto &Sym : Slab->Slab)
 Slab->Pointers.push_back(&Sym.second);
 
   auto *Pointers = &Slab->Pointers;
   return {std::move(Slab), Pointers};
 }
 
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
 std::vector match(const SymbolIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
   auto Ctx = Context::empty();
-  I.fuzzyFind(Ctx, Req,
-  [&](const Symbol &Sym) { Matches.push_back(Sym.QualifiedName); });
+  I.fuzzyFind(Ctx, Req, [&](const Symbol &Sym) {
+Matches.push_back(Sym.Scope + (Sym.Scope.empty() ? "" : "::") + Sym.Name);
+  });
   return Matches;
 }
 
@@ -110,6 +129,56 @@
   EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
 }
 
+TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "b::yz", "yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  Req.Scopes.push_back("");
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
+  FuzzyFindReques

[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for the review!




Comment at: clangd/index/Index.h:127
   /// \brief A query string for the fuzzy find. This is matched against 
symbols'
-  /// qualfified names.
+  /// qualified names. If any scope below is provided, \p Query is only matched
+  /// against symbols in the scope (excl. symbols in nested scopes).

sammccall wrote:
> If i'm reading this right, you still support fuzzy-matching the scopes (scope 
> information can be in Query, or Scopes, or both). Why? Semantics would be 
> simpler if query matched the identifier only.
This makes a lot of sense. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367



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


[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 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.

just nits, all this stuff up to you




Comment at: clangd/index/Index.h:131
+  /// un-qualified identifiers and should not contain qualifiers like "::". If
+  /// any scope below is provided, \p Query is only matched against symbols in
+  /// the scope (excl. symbols in nested scopes).

I think the rest of the comment isn't needed now - the first two sentences are 
enough (plus the comment on Scopes)



Comment at: clangd/index/MemIndex.cpp:40
 for (const auto Pair : Index) {
+  if (Matched >= Req.MaxCandidateCount)
+return false;

This is too early - we may not actually have an N+1th match :-(



Comment at: clangd/index/SymbolCollector.cpp:63
+std::pair
+splitQualifiedName(llvm::StringRef QName) {
+  size_t Pos = QName.rfind("::");

If you'll never have leading ::, assert that.
Otherwise strip it (I think an assert is better unless you actually expect it)



Comment at: unittests/clangd/FileIndexTests.cpp:127
+  Req.Query = "";
+  Req.Scopes.push_back("ns");
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));

nit: i usually find `Req.Scopes = {"ns"}` more clear, up to you


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367



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


[PATCH] D41351: [clangd] Expose offset <-> LSP position functions, and fix bugs

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

lgtm


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41351



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


[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127484.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- Address a few more comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367

Files:
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -31,7 +31,10 @@
 using testing::UnorderedElementsAre;
 
 // GMock helpers for matching Symbol.
-MATCHER_P(QName, Name, "") { return arg.second.QualifiedName == Name; }
+MATCHER_P(QName, Name, "") {
+  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
+  arg.second.Name) == Name;
+}
 
 namespace clang {
 namespace clangd {
@@ -111,7 +114,8 @@
   const std::string YAML1 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
-QualifiedName:   'clang::Foo1'
+Name:   'Foo1'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
@@ -124,7 +128,8 @@
   const std::string YAML2 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
-QualifiedName:   'clang::Foo2'
+Name:   'Foo2'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -19,45 +19,64 @@
 
 namespace {
 
-Symbol symbol(llvm::StringRef ID) {
+Symbol symbol(llvm::StringRef QName) {
   Symbol Sym;
-  Sym.ID = SymbolID(ID);
-  Sym.QualifiedName = ID;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos);
+  }
   return Sym;
 }
 
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
 };
 
-// Create a slab of symbols with IDs and names [Begin, End]. The life time of
-// the slab is managed by the returned shared pointer. If \p WeakSymbols is
-// provided, it will be pointed to the managed object in the returned shared
-// pointer.
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
 std::shared_ptr>
-generateNumSymbols(int Begin, int End,
-   std::weak_ptr *WeakSymbols = nullptr) {
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr) {
   auto Slab = std::make_shared();
   if (WeakSymbols)
 *WeakSymbols = Slab;
 
-  for (int i = Begin; i <= End; i++)
-Slab->Slab.insert(symbol(std::to_string(i)));
+  for (llvm::StringRef QName : QualifiedNames)
+Slab->Slab.insert(symbol(QName));
 
   for (const auto &Sym : Slab->Slab)
 Slab->Pointers.push_back(&Sym.second);
 
   auto *Pointers = &Slab->Pointers;
   return {std::move(Slab), Pointers};
 }
 
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
 std::vector match(const SymbolIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
   auto Ctx = Context::empty();
-  I.fuzzyFind(Ctx, Req,
-  [&](const Symbol &Sym) { Matches.push_back(Sym.QualifiedName); });
+  I.fuzzyFind(Ctx, Req, [&](const Symbol &Sym) {
+Matches.push_back(Sym.Scope + (Sym.Scope.empty() ? "" : "::") + Sym.Name);
+  });
   return Matches;
 }
 
@@ -110,6 +129,56 @@
   EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
 }
 
+TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "b::yz", "yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  Req.Scopes.push_back("");
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
+  FuzzyFindRe

[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127486.
ioeric added a comment.

- Minor cleanup


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367

Files:
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -31,7 +31,10 @@
 using testing::UnorderedElementsAre;
 
 // GMock helpers for matching Symbol.
-MATCHER_P(QName, Name, "") { return arg.second.QualifiedName == Name; }
+MATCHER_P(QName, Name, "") {
+  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
+  arg.second.Name) == Name;
+}
 
 namespace clang {
 namespace clangd {
@@ -111,7 +114,8 @@
   const std::string YAML1 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
-QualifiedName:   'clang::Foo1'
+Name:   'Foo1'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
@@ -124,7 +128,8 @@
   const std::string YAML2 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
-QualifiedName:   'clang::Foo2'
+Name:   'Foo2'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -19,45 +19,64 @@
 
 namespace {
 
-Symbol symbol(llvm::StringRef ID) {
+Symbol symbol(llvm::StringRef QName) {
   Symbol Sym;
-  Sym.ID = SymbolID(ID);
-  Sym.QualifiedName = ID;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos);
+  }
   return Sym;
 }
 
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
 };
 
-// Create a slab of symbols with IDs and names [Begin, End]. The life time of
-// the slab is managed by the returned shared pointer. If \p WeakSymbols is
-// provided, it will be pointed to the managed object in the returned shared
-// pointer.
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
 std::shared_ptr>
-generateNumSymbols(int Begin, int End,
-   std::weak_ptr *WeakSymbols = nullptr) {
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr) {
   auto Slab = std::make_shared();
   if (WeakSymbols)
 *WeakSymbols = Slab;
 
-  for (int i = Begin; i <= End; i++)
-Slab->Slab.insert(symbol(std::to_string(i)));
+  for (llvm::StringRef QName : QualifiedNames)
+Slab->Slab.insert(symbol(QName));
 
   for (const auto &Sym : Slab->Slab)
 Slab->Pointers.push_back(&Sym.second);
 
   auto *Pointers = &Slab->Pointers;
   return {std::move(Slab), Pointers};
 }
 
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
 std::vector match(const SymbolIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
   auto Ctx = Context::empty();
-  I.fuzzyFind(Ctx, Req,
-  [&](const Symbol &Sym) { Matches.push_back(Sym.QualifiedName); });
+  I.fuzzyFind(Ctx, Req, [&](const Symbol &Sym) {
+Matches.push_back(Sym.Scope + (Sym.Scope.empty() ? "" : "::") + Sym.Name);
+  });
   return Matches;
 }
 
@@ -110,6 +129,56 @@
   EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
 }
 
+TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "b::yz", "yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  Req.Scopes.push_back("");
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithOneScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  Req.Scopes.push_back("

[PATCH] D41367: [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE321067: [clangd] Support filtering by fixing scopes in 
fuzzyFind. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41367?vs=127486&id=127487#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41367

Files:
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -31,7 +31,10 @@
 using testing::UnorderedElementsAre;
 
 // GMock helpers for matching Symbol.
-MATCHER_P(QName, Name, "") { return arg.second.QualifiedName == Name; }
+MATCHER_P(QName, Name, "") {
+  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
+  arg.second.Name) == Name;
+}
 
 namespace clang {
 namespace clangd {
@@ -111,7 +114,8 @@
   const std::string YAML1 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
-QualifiedName:   'clang::Foo1'
+Name:   'Foo1'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
@@ -124,7 +128,8 @@
   const std::string YAML2 = R"(
 ---
 ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
-QualifiedName:   'clang::Foo2'
+Name:   'Foo2'
+Scope:   'clang'
 SymInfo:
   Kind:Function
   Lang:Cpp
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -19,45 +19,64 @@
 
 namespace {
 
-Symbol symbol(llvm::StringRef ID) {
+Symbol symbol(llvm::StringRef QName) {
   Symbol Sym;
-  Sym.ID = SymbolID(ID);
-  Sym.QualifiedName = ID;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos);
+  }
   return Sym;
 }
 
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
 };
 
-// Create a slab of symbols with IDs and names [Begin, End]. The life time of
-// the slab is managed by the returned shared pointer. If \p WeakSymbols is
-// provided, it will be pointed to the managed object in the returned shared
-// pointer.
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
 std::shared_ptr>
-generateNumSymbols(int Begin, int End,
-   std::weak_ptr *WeakSymbols = nullptr) {
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr) {
   auto Slab = std::make_shared();
   if (WeakSymbols)
 *WeakSymbols = Slab;
 
-  for (int i = Begin; i <= End; i++)
-Slab->Slab.insert(symbol(std::to_string(i)));
+  for (llvm::StringRef QName : QualifiedNames)
+Slab->Slab.insert(symbol(QName));
 
   for (const auto &Sym : Slab->Slab)
 Slab->Pointers.push_back(&Sym.second);
 
   auto *Pointers = &Slab->Pointers;
   return {std::move(Slab), Pointers};
 }
 
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
 std::vector match(const SymbolIndex &I,
const FuzzyFindRequest &Req) {
   std::vector Matches;
   auto Ctx = Context::empty();
-  I.fuzzyFind(Ctx, Req,
-  [&](const Symbol &Sym) { Matches.push_back(Sym.QualifiedName); });
+  I.fuzzyFind(Ctx, Req, [&](const Symbol &Sym) {
+Matches.push_back(Sym.Scope + (Sym.Scope.empty() ? "" : "::") + Sym.Name);
+  });
   return Matches;
 }
 
@@ -110,6 +129,56 @@
   EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
 }
 
+TEST(MemIndexTest, MatchQualifiedNamesWithoutSpecificScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "b::yz", "yz"));
+}
+
+TEST(MemIndexTest, MatchQualifiedNamesWithGlobalScope) {
+  MemIndex I;
+  I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
+  FuzzyFindRequest Req;
+  Req.Query = "y";
+  Req.Scopes.push_back("");
+  auto Matches = match(I, Req);
+  EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
+}
+
+TEST(MemIndexTest

[clang-tools-extra] r321067 - [clangd] Support filtering by fixing scopes in fuzzyFind.

2017-12-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Dec 19 03:37:40 2017
New Revision: 321067

URL: http://llvm.org/viewvc/llvm-project?rev=321067&view=rev
Log:
[clangd] Support filtering by fixing scopes in fuzzyFind.

Summary: When scopes are specified, only match symbols from scopes.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

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=321067&r1=321066&r2=321067&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Tue Dec 19 03:37:40 2017
@@ -76,8 +76,11 @@ void operator>>(llvm::StringRef HexStr,
 struct Symbol {
   // The ID of the symbol.
   SymbolID ID;
-  // The qualified name of the symbol, e.g. Foo::bar.
-  std::string QualifiedName;
+  // The unqualified name of the symbol, e.g. "bar" (for "n1::n2::bar").
+  std::string Name;
+  // The scope (e.g. namespace) of the symbol, e.g. "n1::n2" (for
+  // "n1::n2::bar").
+  std::string Scope;
   // The symbol information, like symbol kind.
   index::SymbolInfo SymInfo;
   // The location of the canonical declaration of the symbol.
@@ -124,8 +127,16 @@ private:
 
 struct FuzzyFindRequest {
   /// \brief A query string for the fuzzy find. This is matched against 
symbols'
-  /// qualfified names.
+  /// un-qualified identifiers and should not contain qualifiers like "::".
   std::string Query;
+  /// \brief If this is non-empty, symbols must be in at least one of the 
scopes
+  /// (e.g. namespaces) excluding nested scopes. For example, if a scope "xyz"
+  /// is provided, the matched symbols must be defined in scope "xyz" but not
+  /// "xyz::abc".
+  ///
+  /// A scope must be fully qualified without leading or trailing "::" e.g.
+  /// "n1::n2". "" is interpreted as the global namespace, and "::" is invalid.
+  std::vector Scopes;
   /// \brief The maxinum number of candidates to return.
   size_t MaxCandidateCount = UINT_MAX;
 };

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=321067&r1=321066&r2=321067&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Tue Dec 19 03:37:40 2017
@@ -8,6 +8,7 @@
 //===---===//
 
 #include "MemIndex.h"
+#include "Logger.h"
 
 namespace clang {
 namespace clangd {
@@ -25,20 +26,30 @@ void MemIndex::build(std::shared_ptr Callback) const {
-  std::string LoweredQuery = llvm::StringRef(Req.Query).lower();
+  assert(!StringRef(Req.Query).contains("::") &&
+ "There must be no :: in query.");
+
   unsigned Matched = 0;
   {
 std::lock_guard Lock(Mutex);
 for (const auto Pair : Index) {
   const Symbol *Sym = Pair.second;
-  // Find all symbols that contain the query, igoring cases.
-  // FIXME: consider matching chunks in qualified names instead the whole
-  // string.
-  // FIXME: use better matching algorithm, e.g. fuzzy matcher.
-  if (StringRef(StringRef(Sym->QualifiedName).lower())
-  .contains(LoweredQuery)) {
+
+  // Exact match against all possible scopes.
+  bool ScopeMatched = Req.Scopes.empty();
+  for (StringRef Scope : Req.Scopes) {
+if (Scope == Sym->Scope) {
+  ScopeMatched = true;
+  break;
+}
+  }
+  if (!ScopeMatched)
+continue;
+
+  // FIXME(ioeric): use fuzzy matcher.
+  if (StringRef(StringRef(Sym->Name).lower()).contains(Req.Query)) {
 if (++Matched > Req.MaxCandidateCount)
   return false;
 Callback(*Sym);

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=321067&r1=321066&r2=321067&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Dec 19 
03:37:40 2017
@@ -56,6 +56,18 @@ std::string makeAbsolutePath(const Sourc
   }
   return AbsolutePath.str();
 }
+
+// Split a qualified symbo

[PATCH] D41386: [libunwind][PPC64] Port to ppc64le - initial version

2017-12-19 Thread Leandro Lupori via Phabricator via cfe-commits
luporl created this revision.
luporl added a reviewer: mstorsjo.

Initial working version of libunwind for PowerPC 64. Tested on little end ppc64 
host only.
Based on the existing PowerPC 32 code.

It supports:

- context save/restore (unw_getcontext, unw_init_local, unw_resume)
- read/write from/to saved registers
- backtrace (unw_step)

The main changes were:

- implement ppc64 registers
- add save/restore ppc64 registers code, except for vector ones (this is the 
next planned step)
- change register names from rXX to %rXX. The built-in assembler of clang, on 
powerpc64le on Linux, doesn't seem to recognize the former format. Checked that 
gcc/as also understand this format

This is the continuation of the work started here:
https://github.com/rgdoliveira/libunwind

Note: The commits were squashed to remove test and changed code and present

  a clean history.


https://reviews.llvm.org/D41386

Files:
  include/__libunwind_config.h
  include/libunwind.h
  src/AddressSpace.hpp
  src/Registers.hpp
  src/UnwindCursor.hpp
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/assembly.h
  src/config.h
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -51,6 +51,8 @@
 # define REGISTER_KIND Registers_x86
 #elif defined(__x86_64__)
 # define REGISTER_KIND Registers_x86_64
+#elif defined(__powerpc64__)
+# define REGISTER_KIND Registers_ppc64
 #elif defined(__ppc__)
 # define REGISTER_KIND Registers_ppc
 #elif defined(__aarch64__)
@@ -79,6 +81,7 @@
 }
 
 #ifdef UNW_REMOTE
+//TODO: add powerpc64 support
 /// Create a cursor into a thread in another process.
 _LIBUNWIND_EXPORT int unw_init_remote_thread(unw_cursor_t *cursor,
  unw_addr_space_t as,
Index: src/config.h
===
--- src/config.h
+++ src/config.h
@@ -63,12 +63,12 @@
 #define _LIBUNWIND_BUILD_SJLJ_APIS
 #endif
 
-#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)
 #define _LIBUNWIND_SUPPORT_FRAME_APIS
 #endif
 
 #if defined(__i386__) || defined(__x86_64__) ||\
-defined(__ppc__) || defined(__ppc64__) ||  \
+defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) ||\
 (!defined(__APPLE__) && defined(__arm__)) ||   \
 (defined(__arm64__) || defined(__aarch64__)) ||\
 defined(__mips__)
Index: src/assembly.h
===
--- src/assembly.h
+++ src/assembly.h
@@ -16,7 +16,9 @@
 #ifndef UNWIND_ASSEMBLY_H
 #define UNWIND_ASSEMBLY_H
 
-#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
+#if defined(__powerpc64__)
+#define SEPARATOR ;
+#elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
 #define SEPARATOR @
 #elif defined(__arm64__)
 #define SEPARATOR %%
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -237,6 +237,109 @@
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
   teq $0, $0
 
+#elif defined(__powerpc64__)
+
+//
+// extern int unw_getcontext(unw_context_t* thread_state)
+//
+// On entry:
+//  thread_state pointer is in r3
+//
+DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+  std   %r0,   16(%r3)
+  mflr  %r0
+  std   %r0,0(%r3)  // store lr as ssr0
+  std   %r1,   24(%r3)
+  std   %r2,   32(%r3)
+  std   %r3,   40(%r3)
+  std   %r4,   48(%r3)
+  std   %r5,   56(%r3)
+  std   %r6,   64(%r3)
+  std   %r7,   72(%r3)
+  std   %r8,   80(%r3)
+  std   %r9,   88(%r3)
+  std   %r10,  96(%r3)
+  std   %r11, 104(%r3)
+  std   %r12, 112(%r3)
+  std   %r13, 120(%r3)
+  std   %r14, 128(%r3)
+  std   %r15, 136(%r3)
+  std   %r16, 144(%r3)
+  std   %r17, 152(%r3)
+  std   %r18, 160(%r3)
+  std   %r19, 168(%r3)
+  std   %r20, 176(%r3)
+  std   %r21, 184(%r3)
+  std   %r22, 192(%r3)
+  std   %r23, 200(%r3)
+  std   %r24, 208(%r3)
+  std   %r25, 216(%r3)
+  std   %r26, 224(%r3)
+  std   %r27, 232(%r3)
+  std   %r28, 240(%r3)
+  std   %r29, 248(%r3)
+  std   %r30, 256(%r3)
+  std   %r31, 264(%r3)
+
+  mfcr  %r0
+  std   %r0,  272(%r3)
+
+  mfxer %r0
+  std   %r0,  280(%r3)
+
+  mflr  %r0
+  std   %r0,  288(%r3)
+
+  mfctr %r0
+  std   %r0,  296(%r3)
+
+  mfvrsave%r0
+  std   %r0,  304(%r3)
+
+  // save float registers
+  stfd  %f0,  312(%r3)
+  stfd  %f1,  320(%r3)
+  stfd  %f2,  328(%r3)
+  stfd  %f3,  336(%r3)
+  stfd  %f4,  344(%r3)
+  stfd  %f5,  352(%r3)
+  stfd  %f6,  360(%r3)
+  stfd  %f7,  368(%r3)
+  stfd  %f8,  376(%r3)
+  stfd  %f9,  384(%r3)
+  stfd  %f10, 392(%r3)
+  stfd  %f11, 400(%r3)
+  stfd  %f12, 408(%r3)
+  stfd  %f13, 416(%r3)
+  s

[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127488.
ioeric added a comment.

- Merged with origin/master
- Merged with https://reviews.llvm.org/D41351


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -143,7 +143,7 @@
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("");
+  Req.Scopes = {""};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
@@ -153,7 +153,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
@@ -163,8 +163,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
-  Req.Scopes.push_back("b");
+  Req.Scopes = {"a", "b"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
@@ -174,7 +173,7 @@
   I.build(generateSymbols({"a::xyz", "a::b::yy"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -6,13 +6,15 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+
 #include "ClangdServer.h"
 #include "Compiler.h"
 #include "Context.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
+#include "index/MemIndex.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -83,6 +85,7 @@
 MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
 MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
 MATCHER_P(Kind, K, "") { return arg.kind == K; }
+MATCHER_P(Filter, F, "") { return arg.filterText == F; }
 MATCHER_P(PlainText, Text, "") {
   return arg.insertTextFormat == clangd::InsertTextFormat::PlainText &&
  arg.insertText == Text;
@@ -457,6 +460,92 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+std::unique_ptr simpleIndexFromSymbols(
+std::vector> Symbols) {
+  auto I = llvm::make_unique();
+  struct Snapshot {
+SymbolSlab Slab;
+std::vector Pointers;
+  };
+  auto Snap = std::make_shared();
+  for (const auto &Pair : Symbols) {
+Symbol Sym;
+Sym.ID = SymbolID(Pair.first);
+llvm::StringRef QName = Pair.first;
+size_t Pos = QName.rfind("::");
+if (Pos == llvm::StringRef::npos) {
+  Sym.Name = QName;
+  Sym.Scope = "";
+} else {
+  Sym.Name = QName.substr(Pos + 2);
+  Sym.Scope = QName.substr(0, Pos);
+}
+Sym.SymInfo.Kind = Pair.second;
+Snap->Slab.insert(std::move(Sym));
+  }
+  for (auto &Iter : Snap->Slab)
+Snap->Pointers.push_back(&Iter.second);
+  auto S = std::shared_ptr>(std::move(Snap),
+&Snap->Pointers);
+  I->build(std::move(S));
+  return I;
+}
+
+TEST(CompletionTest, NoIndex) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = nullptr;
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("No"));
+}
+
+TEST(CompletionTest, SimpleIndexBased) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"nx::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = I.get();
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Not(Has("No")));
+}
+
+TEST(CompletionTest, IndexBasedWithFilter) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Functi

[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127493.
ioeric added a comment.

- Merge with updated https://reviews.llvm.org/D41281
- Fix broken merge


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -546,6 +546,58 @@
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, ASTIndexOneFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  auto File = getVirtualTestFilePath("foo.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  void f() { ns::^ }
+  )cpp");
+  // Wait to make sure AST is parsed.
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+}
+
+TEST(CompletionTest, ASTIndexMultiFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  Server
+  .addDocument(Context::empty(), getVirtualTestFilePath("foo.cpp"), R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  )cpp")
+  .wait();
+
+  auto File = getVirtualTestFilePath("bar.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XXX {}; void fo() {} }
+  void f() { ns::^ }
+  )cpp");
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Has("XXX", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("fo", CompletionItemKind::Function));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -90,6 +90,13 @@
 "Trace internal events and timestamps in chrome://tracing JSON format"),
 llvm::cl::init(""), llvm::cl::Hidden);
 
+static llvm::cl::opt EnableIndexBasedCompletion(
+"enable-index-based-completion",
+llvm::cl::desc(
+"Enable index-based global code completion (experimental). Clangd will "
+"use index built from symbols in opened files"),
+llvm::cl::init(false));
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
@@ -180,7 +187,8 @@
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(Out, WorkerThreadsCount, StorePreamblesInMemory,
-CCOpts, ResourceDirRef, CompileCommandsDirPath);
+CCOpts, ResourceDirRef, CompileCommandsDirPath,
+EnableIndexBasedCompletion);
   constexpr int NoShutdownRequestErrorCode = 1;
   llvm::set_thread_name("clangd.main");
   return LSPServer.run(std::cin) ? 0 : NoShutdownRequestErrorCode;
Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -25,6 +25,10 @@
 /// Thread-safe mapping from FileNames to CppFile.
 class CppFileCollection {
 public:
+  /// \p ASTCallback is called when a file is parsed.
+  explicit CppFileCollection(ASTParsedCallback ASTCallback)
+  : ASTCallback(std::move(ASTCallback)) {}
+
   std::shared_ptr
   getOrCreateFile(PathRef File, PathRef ResourceDir,
   GlobalCompilationDatabase &CDB, bool StorePreamblesInMemory,
@@ -38,7 +42,7 @@
   It = OpenedFiles
.try_emplace(File, CppFile::Create(File, std::move(Command),
   StorePreamblesInMemory,
-   

[clang-tools-extra] r321073 - [clangd] Expose offset <-> LSP position functions, and fix bugs

2017-12-19 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Dec 19 04:23:48 2017
New Revision: 321073

URL: http://llvm.org/viewvc/llvm-project?rev=321073&view=rev
Log:
[clangd] Expose offset <-> LSP position functions, and fix bugs

Summary:
- Moved these functions to SourceCode.h
- added unit tests
- fix off by one in positionToOffset: Offset - 1 in final calculation was wrong
- fixed formatOnType which had an equal and opposite off-by-one
- positionToOffset and offsetToPosition both consistently clamp to beginning/end
  of file when input is out of range
- gave variables more descriptive names
- removed windows line ending fixmes where there is nothing to fix
- elaborated on UTF-8 fixmes

This will conflict with Eric's D41281, but in a pretty easy-to-resolve way.

Reviewers: ioeric

Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=321073&r1=321072&r2=321073&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Tue Dec 19 04:23:48 2017
@@ -18,6 +18,7 @@ add_clang_library(clangDaemon
   Logger.cpp
   Protocol.cpp
   ProtocolHandlers.cpp
+  SourceCode.cpp
   Trace.cpp
   index/FileIndex.cpp
   index/Index.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=321073&r1=321072&r2=321073&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Dec 19 04:23:48 2017
@@ -9,6 +9,7 @@
 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
+#include "SourceCode.h"
 #include "llvm/Support/FormatVariadic.h"
 
 using namespace clang::clangd;

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=321073&r1=321072&r2=321073&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Dec 19 04:23:48 2017
@@ -8,6 +8,7 @@
 //===---===//
 
 #include "ClangdServer.h"
+#include "SourceCode.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -57,29 +58,6 @@ public:
 
 } // namespace
 
-size_t clangd::positionToOffset(StringRef Code, Position P) {
-  size_t Offset = 0;
-  for (int I = 0; I != P.line; ++I) {
-// FIXME: \r\n
-// FIXME: UTF-8
-size_t F = Code.find('\n', Offset);
-if (F == StringRef::npos)
-  return 0; // FIXME: Is this reasonable?
-Offset = F + 1;
-  }
-  return (Offset == 0 ? 0 : (Offset - 1)) + P.character;
-}
-
-/// Turn an offset in Code into a [line, column] pair.
-Position clangd::offsetToPosition(StringRef Code, size_t Offset) {
-  StringRef JustBefore = Code.substr(0, Offset);
-  // FIXME: \r\n
-  // FIXME: UTF-8
-  int Lines = JustBefore.count('\n');
-  int Cols = JustBefore.size() - JustBefore.rfind('\n') - 1;
-  return {Lines, Cols};
-}
-
 Tagged>
 RealFileSystemProvider::getTaggedFileSystem(PathRef File) {
   return make_tagged(vfs::getRealFileSystem(), VFSTag());
@@ -337,7 +315,7 @@ ClangdServer::formatOnType(StringRef Cod
   size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos);
   if (PreviousLBracePos == StringRef::npos)
 PreviousLBracePos = CursorPos;
-  size_t Len = 1 + CursorPos - PreviousLBracePos;
+  size_t Len = CursorPos - PreviousLBracePos;
 
   return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)});
 }

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=321073&r1=321072&r2=321073&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Dec 19 04:23:48 2017
@@ -35,12 +35,6 @@ class PCHContainerOperations;
 
 na

[PATCH] D41351: [clangd] Expose offset <-> LSP position functions, and fix bugs

2017-12-19 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE321073: [clangd] Expose offset <-> LSP position 
functions, and fix bugs (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41351?vs=127345&id=127495#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41351

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/SourceCodeTests.cpp

Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -8,6 +8,7 @@
 //===---===//
 
 #include "ClangdServer.h"
+#include "SourceCode.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -57,29 +58,6 @@
 
 } // namespace
 
-size_t clangd::positionToOffset(StringRef Code, Position P) {
-  size_t Offset = 0;
-  for (int I = 0; I != P.line; ++I) {
-// FIXME: \r\n
-// FIXME: UTF-8
-size_t F = Code.find('\n', Offset);
-if (F == StringRef::npos)
-  return 0; // FIXME: Is this reasonable?
-Offset = F + 1;
-  }
-  return (Offset == 0 ? 0 : (Offset - 1)) + P.character;
-}
-
-/// Turn an offset in Code into a [line, column] pair.
-Position clangd::offsetToPosition(StringRef Code, size_t Offset) {
-  StringRef JustBefore = Code.substr(0, Offset);
-  // FIXME: \r\n
-  // FIXME: UTF-8
-  int Lines = JustBefore.count('\n');
-  int Cols = JustBefore.size() - JustBefore.rfind('\n') - 1;
-  return {Lines, Cols};
-}
-
 Tagged>
 RealFileSystemProvider::getTaggedFileSystem(PathRef File) {
   return make_tagged(vfs::getRealFileSystem(), VFSTag());
@@ -337,7 +315,7 @@
   size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos);
   if (PreviousLBracePos == StringRef::npos)
 PreviousLBracePos = CursorPos;
-  size_t Len = 1 + CursorPos - PreviousLBracePos;
+  size_t Len = CursorPos - PreviousLBracePos;
 
   return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)});
 }
Index: clangd/SourceCode.h
===
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -0,0 +1,29 @@
+//===--- SourceCode.h - Manipulating source code as strings -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Various code that examines C++ source code without using heavy AST machinery
+// (and often not even the lexer). To be used sparingly!
+//
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
+#include "Protocol.h"
+
+namespace clang {
+namespace clangd {
+
+/// Turn a [line, column] pair into an offset in Code.
+size_t positionToOffset(llvm::StringRef Code, Position P);
+
+/// Turn an offset in Code into a [line, column] pair.
+Position offsetToPosition(llvm::StringRef Code, size_t Offset);
+
+} // namespace clangd
+} // namespace clang
+#endif
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -35,12 +35,6 @@
 
 namespace clangd {
 
-/// Turn a [line, column] pair into an offset in Code.
-size_t positionToOffset(StringRef Code, Position P);
-
-/// Turn an offset in Code into a [line, column] pair.
-Position offsetToPosition(StringRef Code, size_t Offset);
-
 /// A tag supplied by the FileSytemProvider.
 typedef std::string VFSTag;
 
Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -9,6 +9,7 @@
 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
+#include "SourceCode.h"
 #include "llvm/Support/FormatVariadic.h"
 
 using namespace clang::clangd;
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -18,6 +18,7 @@
   Logger.cpp
   Protocol.cpp
   ProtocolHandlers.cpp
+  SourceCode.cpp
   Trace.cpp
   index/FileIndex.cpp
   index/Index.cpp
Index: clangd/SourceCode.cpp
===
--- clangd/SourceCode.cpp
+++ clangd/SourceCode.cpp
@@ -0,0 +1,41 @@
+//===--- SourceCode.h - Manipulating source code as strings -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the Un

[PATCH] D41365: [clang] Add BeforeExecute method to PrecompiledPreamble

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added inline comments.
This revision now requires changes to proceed.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:249
+  /// from a CompilerInstance.
+  virtual void BeforeExecute(CompilerInstance &CI);
   /// Called after FrontendAction::Execute(), but before

The comment seems a bit too specific.
Maybe change it to something like "can be used to store references to various 
CompilerInstance fields (e.g. SourceManager) that may be interesting to the 
consumers of other callbacks"



Comment at: lib/Frontend/PrecompiledPreamble.cpp:355
 
   Act->Execute();
 

We should probably call it here, right before `Execute`.
Or maybe right before `BeginSourceFile` if we can receive the callbacks while 
executing `BeginSourceFile`. We should make sure to update the comment if you 
decide to call it before `BeginSourceFile`.


Repository:
  rC Clang

https://reviews.llvm.org/D41365



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


[PATCH] D40903: [Sanitizers] Basic Solaris sanitizer support (PR 33274)

2017-12-19 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: lib/Driver/ToolChains/CommonArgs.cpp:528
 StringRef Sanitizer) {
+  // Solaris ld doesn't need this.  Inhibit use of non-existant
+  // --export-dynamic.

alekseyshl wrote:
> ro wrote:
> > alekseyshl wrote:
> > > Can you elaborate why Solaris ld does not need dynamic lists? How does it 
> > > export sanitizer symbols then?
> > Solaris ld simply defaults to --export-dynamic.
> Can we say then that ld "defaults to --export-dynamic behavior" (as 
> --export-dynamic does not exists there) instead of "doesn't need this"?
Sure, that's certainly clearer.  As in the revised patch?


Repository:
  rC Clang

https://reviews.llvm.org/D40903



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


[PATCH] D41387: Remove llvm::MemoryBuffer const_casts

2017-12-19 Thread Pavel Labath via Phabricator via cfe-commits
labath created this revision.
labath added reviewers: dblaikie, rsmith.

llvm has grown a WritableMemoryBuffer class, which is convertible
(inherits from) a MemoryBuffer. We can use it to avoid conts_casting the
buffer contents when we want to write to it.


Repository:
  rC Clang

https://reviews.llvm.org/D41387

Files:
  lib/Basic/SourceManager.cpp
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -420,10 +420,9 @@
   CodeCompletionFile = File;
   CodeCompletionOffset = Position - Buffer->getBufferStart();
 
-  std::unique_ptr NewBuffer =
-  MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
-  Buffer->getBufferIdentifier());
-  char *NewBuf = const_cast(NewBuffer->getBufferStart());
+  auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+  Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
+  char *NewBuf = NewBuffer->getBufferStart();
   char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
   *NewPos = '\0';
   std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -125,11 +125,12 @@
   // possible.
   if (!BufferOrError) {
 StringRef FillStr("<<>>\n");
-Buffer.setPointer(MemoryBuffer::getNewUninitMemBuffer(
-  ContentsEntry->getSize(), "").release());
-char *Ptr = const_cast(Buffer.getPointer()->getBufferStart());
+auto BackupBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+ContentsEntry->getSize(), "");
+char *Ptr = BackupBuffer->getBufferStart();
 for (unsigned i = 0, e = ContentsEntry->getSize(); i != e; ++i)
   Ptr[i] = FillStr[i % FillStr.size()];
+Buffer.setPointer(BackupBuffer.release());
 
 if (Diag.isDiagnosticInFlight())
   Diag.SetDelayedDiagnostic(diag::err_cannot_open_file,


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -420,10 +420,9 @@
   CodeCompletionFile = File;
   CodeCompletionOffset = Position - Buffer->getBufferStart();
 
-  std::unique_ptr NewBuffer =
-  MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
-  Buffer->getBufferIdentifier());
-  char *NewBuf = const_cast(NewBuffer->getBufferStart());
+  auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+  Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
+  char *NewBuf = NewBuffer->getBufferStart();
   char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
   *NewPos = '\0';
   std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -125,11 +125,12 @@
   // possible.
   if (!BufferOrError) {
 StringRef FillStr("<<>>\n");
-Buffer.setPointer(MemoryBuffer::getNewUninitMemBuffer(
-  ContentsEntry->getSize(), "").release());
-char *Ptr = const_cast(Buffer.getPointer()->getBufferStart());
+auto BackupBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
+ContentsEntry->getSize(), "");
+char *Ptr = BackupBuffer->getBufferStart();
 for (unsigned i = 0, e = ContentsEntry->getSize(); i != e; ++i)
   Ptr[i] = FillStr[i % FillStr.size()];
+Buffer.setPointer(BackupBuffer.release());
 
 if (Diag.isDiagnosticInFlight())
   Diag.SetDelayedDiagnostic(diag::err_cannot_open_file,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40903: [Sanitizers] Basic Solaris sanitizer support (PR 33274)

2017-12-19 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 127499.
ro marked an inline comment as done.
ro added a comment.

Reworded comment.


Repository:
  rC Clang

https://reviews.llvm.org/D40903

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Solaris.cpp
  lib/Driver/ToolChains/Solaris.h

Index: lib/Driver/ToolChains/Solaris.h
===
--- lib/Driver/ToolChains/Solaris.h
+++ lib/Driver/ToolChains/Solaris.h
@@ -65,6 +65,7 @@
   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
 
+  SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
 protected:
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -92,24 +92,48 @@
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
+  // Provide __start___sancov_guards.  Solaris ld doesn't automatically create
+  // __start_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_begin", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_e, options::OPT_r});
 
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (getToolChain().ShouldLinkCXXStdlib(Args))
   getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+if (Args.hasArg(options::OPT_fstack_protector) ||
+Args.hasArg(options::OPT_fstack_protector_strong) ||
+Args.hasArg(options::OPT_fstack_protector_all)) {
+  // Explicitly link ssp libraries, not folded into Solaris libc.
+  CmdArgs.push_back("-lssp_nonshared");
+  CmdArgs.push_back("-lssp");
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+if (NeedsSanitizerDeps)
+  linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
   }
 
+  // Provide __stop___sancov_guards.  Solaris ld doesn't automatically create
+  // __stop_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_end", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
@@ -165,6 +189,17 @@
   addPathIfExists(D, D.SysRoot + "/usr/lib" + LibSuffix, Paths);
 }
 
+SanitizerMask Solaris::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  // FIXME: Omit X86_64 until 64-bit support is figured out.
+  if (IsX86) {
+Res |= SanitizerKind::Address;
+  }
+  Res |= SanitizerKind::Vptr;
+  return Res;
+}
+
 Tool *Solaris::buildAssembler() const {
   return new tools::solaris::Assembler(*this);
 }
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -511,9 +511,9 @@
 bool IsShared, bool IsWhole) {
   // Wrap any static runtimes that must be forced into executable in
   // whole-archive.
-  if (IsWhole) CmdArgs.push_back("-whole-archive");
+  if (IsWhole) CmdArgs.push_back("--whole-archive");
   CmdArgs.push_back(TC.getCompilerRTArgString(Args, Sanitizer, IsShared));
-  if (IsWhole) CmdArgs.push_back("-no-whole-archive");
+  if (IsWhole) CmdArgs.push_back("--no-whole-archive");
 
   if (IsShared) {
 addArchSpecificRPath(TC, Args, CmdArgs);
@@ -525,6 +525,10 @@
 static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args,
 ArgStringList &CmdArgs,
 StringRef Sanitizer) {
+  // Solaris ld defaults to --export-dynamic behaviour but doesn't support
+  // the option, so don't try to pass it.
+  if (TC.getTriple().getOS() == llvm::Triple::Solaris)
+return true;
   SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
   if (llvm::sys::fs::exists(SanRT + ".syms")) {
 CmdArgs.push_back(Args.MakeArgString("--dynamic-list=" + SanRT + ".syms"));
@@ -685,7 +689,7 @@
   // If there is a static runtime with no dynamic list, force all the symbols
   // to be dynamic

[PATCH] D40903: [Sanitizers] Basic Solaris sanitizer support (PR 33274)

2017-12-19 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

There are two issues before the patch can be commited:

- It depends on https://reviews.llvm.org/D35755 which needs minor changes.

- I'm currently working with an experimental version of Solaris ld that *does* 
support generation of __start___sancov_guards etc. labels. This will most 
likely go into Solaris 11.4, but somehow older linkers without that support 
(from Solaris 11.3 or OpenSolaris derivatives) will have to be supported, 
probably by a cmake test.  Not sure yet how best to do this.


Repository:
  rC Clang

https://reviews.llvm.org/D40903



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


Re: r320982 - Revert r320978 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"

2017-12-19 Thread Richard Smith via cfe-commits
On 18 Dec 2017 15:23, "Stephan Bergmann via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

On 12/18/2017 03:05 PM, Richard Smith wrote:

> Can we just strip the noexcept from the function type before emitting the
> fsan type info?
>

As is apparently already done when emitting the (not noexcept-annotated)
__cxxabiv1::__function_type_info referenced from a noexcept-annotated
__cxxabiv1::__pointer_type_info?

That would indeed look like a better way to address this, then.  But
wouldn't that also prevent -fsanitize=function from finding mismatches
where a non-noexcept function is called through a noexcept pointer, as in

  void f() {}
  void g(void (*p)() noexcept) { p(); }
  int main() { g(reinterpret_cast(f)); }


That call seems OK to me; if the function does throw, std::terminate() will
be called.

On 18 Dec 2017 13:52, "Stephan Bergmann via cfe-commits" <
> cfe-commits@lists.llvm.org > wrote:
>
> Author: sberg
> Date: Mon Dec 18 05:51:48 2017
> New Revision: 320982
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320982&view=rev
> 
> Log:
> Revert r320978 "No -fsanitize=function warning when calling noexcept
> function through non-noexcept pointer in C++17"
>
> At least
>  builds/6013/steps/annotate/logs/stdio
>  builds/6013/steps/annotate/logs/stdio>> complains about
> __ubsan::__ubsan_handle_function_type_mismatch_abort (compiler-rt
> lib/ubsan/ubsan_handlers.cc) returning now despite being declared
> 'noreturn', so
> looks like a different approach is needed for the
> function_type_mismatch check
> to be called also in cases that may ultimately succeed.
>
> Modified:
>  cfe/trunk/lib/CodeGen/CGExpr.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CG
> Expr.cpp?rev=320982&r1=320981&r2=320982&view=diff
>  GExpr.cpp?rev=320982&r1=320981&r2=320982&view=diff>
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 18 05:51:48 2017
> @@ -4504,14 +4504,10 @@ RValue CodeGenFunction::EmitCall(QualTyp
> Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
> llvm::Constant *StaticData[] = {
>   EmitCheckSourceLocation(E->getLocStart()),
> -EmitCheckTypeDescriptor(CalleeType),
> -cast(FnType)->isNothrow(getContext())
> -  ? llvm::Constant::getNullValue(FTRTTIConst->getType())
> -  : FTRTTIConst
> +EmitCheckTypeDescriptor(CalleeType)
> };
> EmitCheck(std::make_pair(CalleeRTTIMatch,
> SanitizerKind::Function),
> -SanitizerHandler::FunctionTypeMismatch, StaticData,
> -{CalleePtr, CalleeRTTI});
> +SanitizerHandler::FunctionTypeMismatch, StaticData,
> CalleePtr);
>
> Builder.CreateBr(Cont);
> EmitBlock(Cont);
>
___
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] D33826: [clang-tidy] avoid pointer cast to more strict alignment check

2017-12-19 Thread Eniko Donatella Toth via Phabricator via cfe-commits
NorenaLeonetti added a comment.

In https://reviews.llvm.org/D33826#935394, @lebedev.ri wrote:

> Ping?


Hi, I'm sorry I got a bit busy, I'll get back to it next year.


Repository:
  rL LLVM

https://reviews.llvm.org/D33826



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


Re: r320982 - Revert r320978 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"

2017-12-19 Thread Stephan Bergmann via cfe-commits

On 12/19/2017 01:58 PM, Richard Smith wrote:
On 18 Dec 2017 15:23, "Stephan Bergmann via cfe-commits" 
mailto:cfe-commits@lists.llvm.org>> wrote:


On 12/18/2017 03:05 PM, Richard Smith wrote:

Can we just strip the noexcept from the function type before
emitting the fsan type info?


As is apparently already done when emitting the (not
noexcept-annotated) __cxxabiv1::__function_type_info referenced from
a noexcept-annotated __cxxabiv1::__pointer_type_info?

That would indeed look like a better way to address this, then.  But
wouldn't that also prevent -fsanitize=function from finding
mismatches where a non-noexcept function is called through a
noexcept pointer, as in

   void f() {}
   void g(void (*p)() noexcept) { p(); }
   int main() { g(reinterpret_cast(f)); }


That call seems OK to me; if the function does throw, std::terminate() 
will be called.


I would have assumed that should be UB.  But that arguably could depend 
on whether and how that DR about calling noexpect functions through 
non-noexcept pointers that both you and I reported will be resolved. 
(It's a bit unfortunate that no information about those DR filings is 
yet available at 
.)


One more argument in favour of resolving this issue as per 
 for now.  So I'll look into that.

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


[PATCH] D40720: No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17

2017-12-19 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

In https://reviews.llvm.org/D40720#958743, @vsk wrote:

> > Would it be possible to fix this by stripping the noexcept specifiers from 
> > both the function type used in the check and the one that is embedded in 
> > the prefix data? The downside is that we won't catch the case where the 
> > caller has a noexcept specifier and the callee doesn't, but that seems like 
> > an edge case to me, and we can think about fixing it in other ways later.
>
> This sounds fine to me, and it avoids breaking the trapping mode.


...and would be in line with what has been discussed in the mail sub-thread 
starting at 
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20171218/213093.html 
"Re: r320982 - Revert r320978 'No -fsanitize=function warning when calling 
noexcept function through non-noexcept pointer in C++17'"


Repository:
  rC Clang

https://reviews.llvm.org/D40720



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


[PATCH] D41386: [libunwind][PPC64] Port to ppc64le - initial version

2017-12-19 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: include/__libunwind_config.h:46
+#  define _LIBUNWIND_CURSOR_SIZE 148
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 110
 # elif defined(__ppc__)

Don't hardcode a number here; add a define 
`_LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64` further above like the other 
architectures



Comment at: src/Registers.hpp:1128
+  voidjumpto();
+  static int  lastDwarfRegNum() { return 108; }
+

... and use `_LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64` here instead of a 
hardcoded number



Comment at: src/libunwind.cpp:84
 #ifdef UNW_REMOTE
+//TODO: add powerpc64 support
 /// Create a cursor into a thread in another process.

Why this comment here? Remote unwinding is unimplemented in libunwind, and I 
don't see how a ppc64 specific comment is needed here?


https://reviews.llvm.org/D41386



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127509.
ioeric added a comment.

- Fixed a bug when completing scope that starts with '::'.
- Diff base on origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -143,7 +143,7 @@
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("");
+  Req.Scopes = {""};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
@@ -153,7 +153,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
@@ -163,8 +163,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
-  Req.Scopes.push_back("b");
+  Req.Scopes = {"a", "b"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
@@ -174,7 +173,7 @@
   I.build(generateSymbols({"a::xyz", "a::b::yy"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -6,13 +6,15 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+
 #include "ClangdServer.h"
 #include "Compiler.h"
 #include "Context.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
+#include "index/MemIndex.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -83,6 +85,7 @@
 MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
 MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
 MATCHER_P(Kind, K, "") { return arg.kind == K; }
+MATCHER_P(Filter, F, "") { return arg.filterText == F; }
 MATCHER_P(PlainText, Text, "") {
   return arg.insertTextFormat == clangd::InsertTextFormat::PlainText &&
  arg.insertText == Text;
@@ -457,6 +460,104 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+std::unique_ptr simpleIndexFromSymbols(
+std::vector> Symbols) {
+  auto I = llvm::make_unique();
+  struct Snapshot {
+SymbolSlab Slab;
+std::vector Pointers;
+  };
+  auto Snap = std::make_shared();
+  for (const auto &Pair : Symbols) {
+Symbol Sym;
+Sym.ID = SymbolID(Pair.first);
+llvm::StringRef QName = Pair.first;
+size_t Pos = QName.rfind("::");
+if (Pos == llvm::StringRef::npos) {
+  Sym.Name = QName;
+  Sym.Scope = "";
+} else {
+  Sym.Name = QName.substr(Pos + 2);
+  Sym.Scope = QName.substr(0, Pos);
+}
+Sym.SymInfo.Kind = Pair.second;
+Snap->Slab.insert(std::move(Sym));
+  }
+  for (auto &Iter : Snap->Slab)
+Snap->Pointers.push_back(&Iter.second);
+  auto S = std::shared_ptr>(std::move(Snap),
+&Snap->Pointers);
+  I->build(std::move(S));
+  return I;
+}
+
+TEST(CompletionTest, NoIndex) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = nullptr;
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("No"));
+}
+
+TEST(CompletionTest, SimpleIndexBased) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"nx::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = I.get();
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Not(Has("No")));
+}
+
+TEST(CompletionTest, IndexBasedWithFilter) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::Sym

[PATCH] D41391: [clangd] Use the clang-tools-extra as the official repo for `vscode-clangd` extension.

2017-12-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, krasimir.
Herald added subscribers: ilya-biryukov, klimek.

Previously, we use a separate GitHub repository 
(https://github.com/llvm-vs-code-extensions/vscode-clangd)
for publishing `vscode-clangd` extension to marketplace.

To reduce the maintain burden, we will use the vscode extension in the
clang-tools-extra, and deprecate the one on GitHub.

Test in 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.clangd-vscode-test


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41391

Files:
  clangd/clients/clangd-vscode/README.md
  clangd/clients/clangd-vscode/README.txt
  clangd/clients/clangd-vscode/package.json

Index: clangd/clients/clangd-vscode/package.json
===
--- clangd/clients/clangd-vscode/package.json
+++ clangd/clients/clangd-vscode/package.json
@@ -1,17 +1,25 @@
 {
-"name": "clangd-vscode",
-"displayName": "clangd-vscode",
+"name": "vscode-clangd",
+"displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.1",
-"publisher": "Unpublished",
+"version": "0.0.2",
+"publisher": "llvm-vs-code-extensions",
 "engines": {
 "vscode": "^1.15.0"
 },
 "categories": [
 "Languages",
 "Linters",
 "Snippets"
 ],
+"keywords": [
+"C",
+"C++",
+"LSP",
+"Clang",
+"LLVM",
+"Clangd"
+],
 "activationEvents": [
 "onLanguage:cpp",
 "onLanguage:c"
@@ -34,6 +42,10 @@
 "@types/node": "^6.0.40",
 "@types/mocha": "^2.2.32"
 },
+"repository": {
+  "type": "git",
+  "url": "https://github.com/llvm-mirror/clang-tools-extra/tree/master/clangd/clients/clangd-vscode";
+},
 "contributes": {
 "configuration": {
 "type": "object",
Index: clangd/clients/clangd-vscode/README.txt
===
--- clangd/clients/clangd-vscode/README.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-A *toy* VS Code integration for development purposes.
-
-Steps:
-1. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
-point to the binary.
-2. Make sure you have nodejs and npm installed.
-3. Make sure you have VS Code installed.
-4. In order to start a development instance of VS code extended with this, run:
-   $ npm install
-   $ code .
-   When VS Code starts, press .
Index: clangd/clients/clangd-vscode/README.md
===
--- /dev/null
+++ clangd/clients/clangd-vscode/README.md
@@ -0,0 +1,53 @@
+# vscode-clangd
+
+Provides C/C++ language IDE features for VS Code using [clangd](https://clang.llvm.org/extra/clangd.html).
+
+## Usage
+
+`vscode-clangd` provides the features designated by the [Language Server
+Protocol](https://github.com/Microsoft/language-server-protocol), such as
+code completion, code formatting and goto definition.
+
+**Note**: `clangd` is under heavy development, not all LSP features are
+implemented. See [Current Status](https://clang.llvm.org/extra/clangd.html#current-status)
+for details.
+
+To use `vscode-clangd` extension in VS Code, you need to install `vscode-clangd`
+from VS Code extension marketplace.
+
+## Configuration
+
+`vscode-clangd` will attempt to find the `clangd` binary on your `PATH`.
+Alternatively, the `clangd` executable can be specified in your VS Code
+`settings.json` file:
+
+```json
+{
+"clangd.path": "/absolute/path/to/clangd"
+}
+```
+
+To obtain `clangd` binary, please see the [installing Clangd](https://clang.llvm.org/extra/clangd.html#installing-clangd).
+
+## Development
+
+A guide of developing `vscode-clangd` extension.
+
+### Requirements
+
+* VS Code
+* nodejs and npm
+
+### Steps
+
+1. Make sure you disable the installed `vscode-clangd` extension in VS Code.
+2. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
+point to the binary.
+3. In order to start a development instance of VS code extended with this, run:
+
+```bash
+   $ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
+   $ npm install
+   $ code .
+   # When VS Code starts, press .
+```
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20689: [clang-tidy] Suspicious Call Argument checker

2017-12-19 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Sorry, I lost this patch. I've looked at the results and it still seems that 
the signal-to-noise ratio is quite low. There's definitely potential in using 
parameter name and argument spelling to detect possibly swapped arguments, and 
there's a recent research on this topic, where authors claim to have reached 
the true positive rate of 85% with decent recall. See 
https://research.google.com/pubs/pub46317.html. If you're interested in working 
on this check, I would suggest at least looking at the techniques described in 
that paper.


https://reviews.llvm.org/D20689



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/CodeComplete.cpp:334
+  Item.insertTextFormat = InsertTextFormat::PlainText;
+  // FIXME: sort symbols appropriately.
+  Item.sortText = "";

ioeric wrote:
> ilya-biryukov wrote:
> > NIT: FIXME(ioeric)?
> > Also, why not provide some `sortText` here? Like a qualified name. Because 
> > we're currently missing scores?
> Does `sortText` have to be non-empty? I thought the empty string would make 
> all candidates equally scored? 
> 
> I think we want either sensible score or (for now) no score at all.
LS says that if `sortText` is empty, `label` should be used. We're probably 
fine here, you're right.




Comment at: clangd/CodeComplete.h:64
+
+  // Populated internally by clangd, do not set.
+  /// If `Index` is set, it is used to augment the code completion

ioeric wrote:
> ilya-biryukov wrote:
> > Given the comment, maybe we want to pass it as a separate parameter instead?
> @sammccall suggested this approach in the previous prototype patch. I also 
> ended up preferring this approach because:
>  1) it doesn't require changing ClangdServer interfaces, and the dynamic 
> index should be built by ClangdServer and thus doesn't make sense to be a 
> parameter.
>  2) it enables unit tests to use customized dummy indexes.
>  3) we might take another (static) index in the future, and it seems easier 
> to pass it in via the options than adding another parameter.
> 1. it doesn't require changing ClangdServer interfaces, and the dynamic index 
> should be built by ClangdServer and thus doesn't make sense to be a parameter.
We do have it as a parameter to `codeComplete` method, the fact that it's 
wrapped in a struct does not make much difference.
`ClangdServer` should probably accept it in a constructor instead if we want to 
override some stuff via the dynamic index instead.

> 2. it enables unit tests to use customized dummy indexes.
unit-testing code can easily wrap any interface, this shouldn't be a problem.

> 3. we might take another (static) index in the future, and it seems easier to 
> pass it in via the options than adding another parameter.
I'm looking at CodeCompleteOptions as a configurable user preference rather 
than a struct, containing all required inputs of codeComplete. I don't think 
SymbolIndex is in line with other fields that this struct contains.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281



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


[PATCH] D41386: [libunwind][PPC64] Port to ppc64le - initial version

2017-12-19 Thread Leandro Lupori via Phabricator via cfe-commits
luporl updated this revision to Diff 127516.
luporl added a comment.

Addressed review comments.


https://reviews.llvm.org/D41386

Files:
  include/__libunwind_config.h
  include/libunwind.h
  src/AddressSpace.hpp
  src/Registers.hpp
  src/UnwindCursor.hpp
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/assembly.h
  src/config.h
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -51,6 +51,8 @@
 # define REGISTER_KIND Registers_x86
 #elif defined(__x86_64__)
 # define REGISTER_KIND Registers_x86_64
+#elif defined(__powerpc64__)
+# define REGISTER_KIND Registers_ppc64
 #elif defined(__ppc__)
 # define REGISTER_KIND Registers_ppc
 #elif defined(__aarch64__)
Index: src/config.h
===
--- src/config.h
+++ src/config.h
@@ -63,12 +63,12 @@
 #define _LIBUNWIND_BUILD_SJLJ_APIS
 #endif
 
-#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)
 #define _LIBUNWIND_SUPPORT_FRAME_APIS
 #endif
 
 #if defined(__i386__) || defined(__x86_64__) ||\
-defined(__ppc__) || defined(__ppc64__) ||  \
+defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) ||\
 (!defined(__APPLE__) && defined(__arm__)) ||   \
 (defined(__arm64__) || defined(__aarch64__)) ||\
 defined(__mips__)
Index: src/assembly.h
===
--- src/assembly.h
+++ src/assembly.h
@@ -16,7 +16,9 @@
 #ifndef UNWIND_ASSEMBLY_H
 #define UNWIND_ASSEMBLY_H
 
-#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
+#if defined(__powerpc64__)
+#define SEPARATOR ;
+#elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
 #define SEPARATOR @
 #elif defined(__arm64__)
 #define SEPARATOR %%
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -237,6 +237,109 @@
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
   teq $0, $0
 
+#elif defined(__powerpc64__)
+
+//
+// extern int unw_getcontext(unw_context_t* thread_state)
+//
+// On entry:
+//  thread_state pointer is in r3
+//
+DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+  std   %r0,   16(%r3)
+  mflr  %r0
+  std   %r0,0(%r3)  // store lr as ssr0
+  std   %r1,   24(%r3)
+  std   %r2,   32(%r3)
+  std   %r3,   40(%r3)
+  std   %r4,   48(%r3)
+  std   %r5,   56(%r3)
+  std   %r6,   64(%r3)
+  std   %r7,   72(%r3)
+  std   %r8,   80(%r3)
+  std   %r9,   88(%r3)
+  std   %r10,  96(%r3)
+  std   %r11, 104(%r3)
+  std   %r12, 112(%r3)
+  std   %r13, 120(%r3)
+  std   %r14, 128(%r3)
+  std   %r15, 136(%r3)
+  std   %r16, 144(%r3)
+  std   %r17, 152(%r3)
+  std   %r18, 160(%r3)
+  std   %r19, 168(%r3)
+  std   %r20, 176(%r3)
+  std   %r21, 184(%r3)
+  std   %r22, 192(%r3)
+  std   %r23, 200(%r3)
+  std   %r24, 208(%r3)
+  std   %r25, 216(%r3)
+  std   %r26, 224(%r3)
+  std   %r27, 232(%r3)
+  std   %r28, 240(%r3)
+  std   %r29, 248(%r3)
+  std   %r30, 256(%r3)
+  std   %r31, 264(%r3)
+
+  mfcr  %r0
+  std   %r0,  272(%r3)
+
+  mfxer %r0
+  std   %r0,  280(%r3)
+
+  mflr  %r0
+  std   %r0,  288(%r3)
+
+  mfctr %r0
+  std   %r0,  296(%r3)
+
+  mfvrsave%r0
+  std   %r0,  304(%r3)
+
+  // save float registers
+  stfd  %f0,  312(%r3)
+  stfd  %f1,  320(%r3)
+  stfd  %f2,  328(%r3)
+  stfd  %f3,  336(%r3)
+  stfd  %f4,  344(%r3)
+  stfd  %f5,  352(%r3)
+  stfd  %f6,  360(%r3)
+  stfd  %f7,  368(%r3)
+  stfd  %f8,  376(%r3)
+  stfd  %f9,  384(%r3)
+  stfd  %f10, 392(%r3)
+  stfd  %f11, 400(%r3)
+  stfd  %f12, 408(%r3)
+  stfd  %f13, 416(%r3)
+  stfd  %f14, 424(%r3)
+  stfd  %f15, 432(%r3)
+  stfd  %f16, 440(%r3)
+  stfd  %f17, 448(%r3)
+  stfd  %f18, 456(%r3)
+  stfd  %f19, 464(%r3)
+  stfd  %f20, 472(%r3)
+  stfd  %f21, 480(%r3)
+  stfd  %f22, 488(%r3)
+  stfd  %f23, 496(%r3)
+  stfd  %f24, 504(%r3)
+  stfd  %f25, 512(%r3)
+  stfd  %f26, 520(%r3)
+  stfd  %f27, 528(%r3)
+  stfd  %f28, 536(%r3)
+  stfd  %f29, 544(%r3)
+  stfd  %f30, 552(%r3)
+  stfd  %f31, 560(%r3)
+
+  mffs  %f0
+  stfd  %f0,  568(%r3)
+
+  //TODO: save vector registers
+
+
+  li%r3,  0   // return UNW_ESUCCESS
+  blr
+
+
 #elif defined(__ppc__)
 
 ;
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -128,6 +128,101 @@
   ret# rip was saved here
 
 
+#elif defined(__powerpc64__)
+
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind15Registers_ppc646jumptoEv)
+//
+// void libunwind::Registers_ppc64::jumpto()
+//
+// On entry:
+//  thread_state pointer is in r3
+//
+
+

[PATCH] D41386: [libunwind][PPC64] Port to ppc64le - initial version

2017-12-19 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

No further comments from my side, but it'd be good if @compnerd could have a 
look as well.


https://reviews.llvm.org/D41386



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


[PATCH] D41386: [libunwind][PPC64] Port to ppc64le - initial version

2017-12-19 Thread Leandro Lupori via Phabricator via cfe-commits
luporl marked 3 inline comments as done.
luporl added inline comments.



Comment at: src/libunwind.cpp:84
 #ifdef UNW_REMOTE
+//TODO: add powerpc64 support
 /// Create a cursor into a thread in another process.

mstorsjo wrote:
> Why this comment here? Remote unwinding is unimplemented in libunwind, and I 
> don't see how a ppc64 specific comment is needed here?
Right, I thought that maybe only ppc64 had to be added here, but as remote 
unwinding is unimplemented there is really no need for a ppc64 specific comment 
here.


https://reviews.llvm.org/D41386



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/CodeComplete.cpp:111
+  case SK::Using:
+return CompletionItemKind::Reference;
+  case SK::Function:

ioeric wrote:
> sammccall wrote:
> > this seems wrong? I would have thought references are similar to c++ 
> > references?
> > can't find anything in LSP either way.
> > 
> > TypeAlias seems like it could default to class, for Using is complicated 
> > (would need to look at the subtype) - maybe just unknown?
> TypeAlias could be more than class I think? And they are references (to 
> types) to some extend. Anyhow, this is copied from the conversion function 
> above. I'll leave a `FIXME` for now.
Yeah, this is the problem I was alluding to before - LSP encourages us to be 
very specific in completion kinds - but we can't always be. Class seems like 
the best guess to me, but FIXME is also fine for now.



Comment at: clangd/CodeComplete.cpp:283
+struct ScopeSpecifierInfo {
+  static ScopeSpecifierInfo create(Sema &S, const CXXScopeSpec &SS) {
+ScopeSpecifierInfo Info;

ioeric wrote:
> sammccall wrote:
> > sammccall wrote:
> > > There's a lot of sema/ast details here, wedged in the middle of the code 
> > > that deals with candidates and scoring. Can you forward declare this, and 
> > > move this implementation and the other details somewhere lower?
> > "create" doesn't give any more semantics than a constructor would.
> > 
> > Maybe `extractCompletionScope`? (This could also be a free function)
> This is moved to a standalone function `extractCompletionScope`.
Thanks for extracting the function. These index-related details are still out 
of place - they split the two chunks of code that mostly do sema-based 
completion.
Can you move `indexCompletionItem`, `completeWithIndex`, and the implementation 
of `extractCompletionScope` below? I'd suggest immediately above 
`codeComplete()`.



Comment at: clangd/CodeComplete.h:64
+
+  // Populated internally by clangd, do not set.
+  /// If `Index` is set, it is used to augment the code completion

ilya-biryukov wrote:
> ioeric wrote:
> > ilya-biryukov wrote:
> > > Given the comment, maybe we want to pass it as a separate parameter 
> > > instead?
> > @sammccall suggested this approach in the previous prototype patch. I also 
> > ended up preferring this approach because:
> >  1) it doesn't require changing ClangdServer interfaces, and the dynamic 
> > index should be built by ClangdServer and thus doesn't make sense to be a 
> > parameter.
> >  2) it enables unit tests to use customized dummy indexes.
> >  3) we might take another (static) index in the future, and it seems easier 
> > to pass it in via the options than adding another parameter.
> > 1. it doesn't require changing ClangdServer interfaces, and the dynamic 
> > index should be built by ClangdServer and thus doesn't make sense to be a 
> > parameter.
> We do have it as a parameter to `codeComplete` method, the fact that it's 
> wrapped in a struct does not make much difference.
> `ClangdServer` should probably accept it in a constructor instead if we want 
> to override some stuff via the dynamic index instead.
> 
> > 2. it enables unit tests to use customized dummy indexes.
> unit-testing code can easily wrap any interface, this shouldn't be a problem.
> 
> > 3. we might take another (static) index in the future, and it seems easier 
> > to pass it in via the options than adding another parameter.
> I'm looking at CodeCompleteOptions as a configurable user preference rather 
> than a struct, containing all required inputs of codeComplete. I don't think 
> SymbolIndex is in line with other fields that this struct contains.
So yeah, this is my fault...
I do agree it's unfortunate to have a non-user-specified param in the 
CodeComplete options. It's tricky - from the perspective of this module the 
index really is such an option, and we want to propagate it around like one. We 
just don't (currently) want to encourage its use as an API to clangdserver.

`codeComplete` currently has 9(!) arguments. Different people will have 
different reactions to this, mine is to do almost anything to avoid a 10th :-)

> unit-testing code can easily wrap any interface, this shouldn't be a problem.
This doesn't match my experience at all. Can you suggest how to test this logic 
without adding parameters to at least ClangdServer::codeComplete and the 
codeComplete test helpers?

> ClangdServer should probably accept it in a constructor instead if we want to 
> override some stuff via the dynamic index instead.
As of today, the dynamic index is the only index clangd supports. There's 
nothing to accept in the constructor, it's entirely owned by ClangdServer.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281



___
cfe-c

[PATCH] D41394: [CodeGen] Support generation of TBAA info in the new format

2017-12-19 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added reviewers: rjmccall, hfinkel.
kosarev added a project: clang.

Now that the MDBuilder helpers generating TBAA type and access descriptors in 
the new format are in place, we can teach clang to use them when requested.


Repository:
  rL LLVM

https://reviews.llvm.org/D41394

Files:
  lib/CodeGen/CodeGenTBAA.cpp


Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -59,7 +59,10 @@
 llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
 llvm::MDNode *Parent,
 uint64_t Size) {
-  (void)Size; // TODO: Support generation of size-aware type nodes.
+  if (CodeGenOpts.NewStructPathTBAA) {
+llvm::Metadata *Id = MDHelper.createString(Name);
+return MDHelper.createTBAATypeNode(Parent, Size, Id);
+  }
   return MDHelper.createTBAAScalarTypeNode(Name, Parent);
 }
 
@@ -300,8 +303,12 @@
   OutName = RD->getName();
 }
 
-// TODO: Support size-aware type nodes and create one here for the
-// given aggregate type.
+if (CodeGenOpts.NewStructPathTBAA) {
+  llvm::MDNode *Parent = getChar();
+  uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
+  llvm::Metadata *Id = MDHelper.createString(OutName);
+  return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
+}
 
 // Create the struct type node with a vector of pairs (offset, type).
 SmallVector, 4> OffsetsAndTypes;
@@ -348,6 +355,10 @@
 Info.BaseType = Info.AccessType;
 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
   }
+  if (CodeGenOpts.NewStructPathTBAA) {
+return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
+Info.Offset, Info.Size);
+  }
   return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
   Info.Offset);
 }


Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -59,7 +59,10 @@
 llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
 llvm::MDNode *Parent,
 uint64_t Size) {
-  (void)Size; // TODO: Support generation of size-aware type nodes.
+  if (CodeGenOpts.NewStructPathTBAA) {
+llvm::Metadata *Id = MDHelper.createString(Name);
+return MDHelper.createTBAATypeNode(Parent, Size, Id);
+  }
   return MDHelper.createTBAAScalarTypeNode(Name, Parent);
 }
 
@@ -300,8 +303,12 @@
   OutName = RD->getName();
 }
 
-// TODO: Support size-aware type nodes and create one here for the
-// given aggregate type.
+if (CodeGenOpts.NewStructPathTBAA) {
+  llvm::MDNode *Parent = getChar();
+  uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
+  llvm::Metadata *Id = MDHelper.createString(OutName);
+  return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
+}
 
 // Create the struct type node with a vector of pairs (offset, type).
 SmallVector, 4> OffsetsAndTypes;
@@ -348,6 +355,10 @@
 Info.BaseType = Info.AccessType;
 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
   }
+  if (CodeGenOpts.NewStructPathTBAA) {
+return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
+Info.Offset, Info.Size);
+  }
   return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
   Info.Offset);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39834: [clang] -foptimization-record-file= should imply -fsave-optimization-record

2017-12-19 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Thanks Dmitry, this LGTM!

PS: Let me know if you don't have commit access and want me to commit it for 
you.


https://reviews.llvm.org/D39834



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


[PATCH] D41391: [clangd] Use the clang-tools-extra as the official repo for `vscode-clangd` extension.

2017-12-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/clients/clangd-vscode/README.md:16
+To use `vscode-clangd` extension in VS Code, you need to install 
`vscode-clangd`
+from VS Code extension marketplace.
+

The fact that you need to install `clangd` seems to belong here, not as 
"configuration".



Comment at: clangd/clients/clangd-vscode/README.md:39
+* VS Code
+* nodejs and npm
+

node.js



Comment at: clangd/clients/clangd-vscode/package.json:46
+"repository": {
+  "type": "git",
+  "url": 
"https://github.com/llvm-mirror/clang-tools-extra/tree/master/clangd/clients/clangd-vscode";

use the SVN path?
npm says this should be a machine readable SCM url, which these github web urls 
aren't.

consider adding homepage/bugtracker, which are also shown on the marketplace 
page: https://marketplace.visualstudio.com/items?itemName=tht13.python


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41391



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


[PATCH] D41077: [analyser] different.CallArgsOrder checker implementation

2017-12-19 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D41077#958819, @szepet wrote:

> 4. FYI: There is a similar check under review which uses only the AST 
> provided information and implemented as a tidy-checker: 
> https://reviews.llvm.org/D20689 (As I see your checker does not uses symbolic 
> execution provided features. So, it would probably worth thinking about if 
> the analyzer is the project where the checker should be implemented. However, 
> @dcoughlin and @alexfh have more insight on the answer to this question. What 
> do you think? )


The main problem with the check proposed in https://reviews.llvm.org/D20689 
(which uses, IIUC, very similar algorithm to this one) is that the false 
positive rate on real projects is too high. The comment I made on the other 
review thread applies here as well:

| There's definitely potential in using parameter name and argument spelling to 
detect possibly swapped arguments, and there's a recent research on this topic, 
where authors claim to have reached the true positive rate of 85% with decent 
recall. See https://research.google.com/pubs/pub46317.html. If you're 
interested in working on this check, I would suggest at least looking at the 
techniques described in that paper. |
|

As for whether this analysis should be implemented in the static analyzer or as 
a clang-tidy check: I think, clang-tidy would be more suitable, since

1. this analysis doesn't need the path analysis machinery provided by the 
static analyzer
2. this analysis may benefit from suggesting automated fixes
3. the false positive rate of the state-of-the-art algorithm implementing 
similar analysis have a false positive rate of at least 15-30%, and a large 
fraction of false positives could  potentially be treated as "code smells" 
which can be fixed by giving function parameters or local variables proper 
names. I don't know whether this kind of analysis meets the bar the static 
analyzer sets for its checkers. Anna or Devin can tell more here.

> 5. In overall, please add comments to the function which describes its 
> purpose. Mainly on heuristic functions, it can help to understand it more 
> easily. Also, could you provide some results of the current heuristics, what 
> are the false positive rates on real projects like LLVM, FFmpeg, etc? I am 
> quite interested in that.

You can take the list of projects from https://reviews.llvm.org/D20689#878803, 
run the analysis on them, and see whether the results are any better.


Repository:
  rC Clang

https://reviews.llvm.org/D41077



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


[PATCH] D41280: [clangd] Don't use the optional "severity" when comparing Diagnostic.

2017-12-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

ping, in case you miss this patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41280



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


[PATCH] D40299: [Complex] Don't use __div?c3 when building with fast-math.

2017-12-19 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm updated this revision to Diff 127528.
paulwalker-arm added a comment.

Query LangOpts for FastMast rather than IRBuilder and fleshed out the tests.


https://reviews.llvm.org/D40299

Files:
  lib/CodeGen/CGExprComplex.cpp
  test/CodeGen/complex-math.c

Index: test/CodeGen/complex-math.c
===
--- test/CodeGen/complex-math.c
+++ test/CodeGen/complex-math.c
@@ -5,6 +5,7 @@
 // RUN %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s --check-prefix=ARM7K
+// RUN: %clang_cc1 %s -O1 -emit-llvm -triple aarch64-unknown-unknown -ffast-math -o - | FileCheck %s --check-prefix=AARCH64-FASTMATH
 
 float _Complex add_float_rr(float a, float b) {
   // X86-LABEL: @add_float_rr(
@@ -128,13 +129,59 @@
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divsc3(
   // X86: ret
+
+  // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
+  // AARCH64-FASTMATH-LABEL: @div_float_rc(float %a, [2 x float] %b.coerce)
+  // A = a
+  // B = 0
+  // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x float] %b.coerce, 0
+  // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x float] %b.coerce, 1
+  //
+  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float [[C]], %a
+  // BD = 0
+  // ACpBD = AC
+  //
+  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float [[C]], [[C]]
+  // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float [[D]], [[D]]
+  // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float [[CC]], [[DD]]
+  //
+  // BC = 0
+  // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float [[D]], %a
+  // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast float -0.00e+00, [[AD]]
+  //
+  // AARCH64-FASTMATH: fdiv fast float [[AC]], [[CCpDD]]
+  // AARCH64-FASTMATH: fdiv fast float [[BCmAD]], [[CCpDD]]
+  // AARCH64-FASTMATH: ret
   return a / b;
 }
 float _Complex div_float_cc(float _Complex a, float _Complex b) {
   // X86-LABEL: @div_float_cc(
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divsc3(
   // X86: ret
+
+  // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
+  // AARCH64-FASTMATH-LABEL: @div_float_cc([2 x float] %a.coerce, [2 x float] %b.coerce)
+  // AARCH64-FASTMATH: [[A:%.*]] = extractvalue [2 x float] %a.coerce, 0
+  // AARCH64-FASTMATH: [[B:%.*]] = extractvalue [2 x float] %a.coerce, 1
+  // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x float] %b.coerce, 0
+  // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x float] %b.coerce, 1
+  //
+  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float [[C]], [[A]]
+  // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast float [[D]], [[B]]
+  // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast float [[AC]], [[BD]]
+  //
+  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float [[C]], [[C]]
+  // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float [[D]], [[D]]
+  // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float [[CC]], [[DD]]
+  //
+  // AARCH64-FASTMATH: [[BC:%.*]] = fmul fast float [[C]], [[B]]
+  // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float [[D]], [[A]]
+  // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast float [[BC]], [[AD]]
+  //
+  // AARCH64-FASTMATH: fdiv fast float [[ACpBD]], [[CCpDD]]
+  // AARCH64-FASTMATH: fdiv fast float [[BCmAD]], [[CCpDD]]
+  // AARCH64-FASTMATH: ret
   return a / b;
 }
 
@@ -260,13 +307,59 @@
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divdc3(
   // X86: ret
+
+  // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
+  // AARCH64-FASTMATH-LABEL: @div_double_rc(double %a, [2 x double] %b.coerce)
+  // A = a
+  // B = 0
+  // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x double] %b.coerce, 0
+  // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x double] %b.coerce, 1
+  //
+  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast double [[C]], %a
+  // BD = 0
+  // ACpBD = AC
+  //
+  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast double [[C]], [[C]]
+  // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast double [[D]], [[D]]
+  // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast double [[CC]], [[DD]]
+  //
+  // BC = 0
+  // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast double [[D]], %a
+  // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast double -0.00e+00, [[AD]]
+  //
+  // AARCH64-FASTMATH: fdiv fast double [[AC]], [[CCpDD]]
+  // AARCH64-FASTMATH: fdiv fast double [[BCmAD]], [[CCpDD]]
+  // AARCH64-FASTMATH: ret
   return a / b;
 }
 double _Complex div_double_cc(double _Complex a, double _Complex b) {
   // X86-LABEL: @div_double_cc(
   // X86-NOT: fdiv
   // X86: call {{.*}} @__divdc3(
   // X86: ret
+
+  // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
+  // AARCH64-FASTMATH-LABEL: @div_double_cc([2 x double] %a.coerce, [2 x double] %b.coerce)
+  // AARCH64-FASTMATH: [[A:%.*]] = extractvalue [2 x double] %a.coerce, 0
+  // AA

[PATCH] D41280: [clangd] Don't use the optional "severity" when comparing Diagnostic.

2017-12-19 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.

Sorry, I did miss it!




Comment at: clangd/Protocol.h:326
+};
+/// A LSP-specific comparator used to find Disgnostic in a container like
+/// std:map.

nit: diagnostic



Comment at: clangd/Protocol.h:326
+};
+/// A LSP-specific comparator used to find Disgnostic in a container like
+/// std:map.

sammccall wrote:
> nit: diagnostic
it seems like this could move from Protocol to ClangdLSPServer, but up to you


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41280



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


[PATCH] D40299: [Complex] Don't use __div?c3 when building with fast-math.

2017-12-19 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm marked 3 inline comments as done.
paulwalker-arm added inline comments.



Comment at: lib/CodeGen/CGExprComplex.cpp:773
 // supported imaginary types in addition to complex types.
-if (RHSi) {
+if (RHSi && !FMF.isFast()) {
   BinOpInfo LibCallOp = Op;

hfinkel wrote:
> fhahn wrote:
> > Would the following structure be slightly easier to read?
> > 
> > if (RHSi) {
> >   if (FMF.isFast()) { simplify } else {libcall}
> > }
> I'd use CGF.getLangOpts().FastMath (instead of interrogating the implicit 
> state stored in the IR builder).
Probably subjective but in this instance I preferred the look with fewer nested 
conditionals.


https://reviews.llvm.org/D40299



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

LGTM. I still think that we should move the `SymbolIndex` out of the struct, 
but don't want to block this patch.




Comment at: clangd/CodeComplete.h:64
+
+  // Populated internally by clangd, do not set.
+  /// If `Index` is set, it is used to augment the code completion

sammccall wrote:
> ilya-biryukov wrote:
> > ioeric wrote:
> > > ilya-biryukov wrote:
> > > > Given the comment, maybe we want to pass it as a separate parameter 
> > > > instead?
> > > @sammccall suggested this approach in the previous prototype patch. I 
> > > also ended up preferring this approach because:
> > >  1) it doesn't require changing ClangdServer interfaces, and the dynamic 
> > > index should be built by ClangdServer and thus doesn't make sense to be a 
> > > parameter.
> > >  2) it enables unit tests to use customized dummy indexes.
> > >  3) we might take another (static) index in the future, and it seems 
> > > easier to pass it in via the options than adding another parameter.
> > > 1. it doesn't require changing ClangdServer interfaces, and the dynamic 
> > > index should be built by ClangdServer and thus doesn't make sense to be a 
> > > parameter.
> > We do have it as a parameter to `codeComplete` method, the fact that it's 
> > wrapped in a struct does not make much difference.
> > `ClangdServer` should probably accept it in a constructor instead if we 
> > want to override some stuff via the dynamic index instead.
> > 
> > > 2. it enables unit tests to use customized dummy indexes.
> > unit-testing code can easily wrap any interface, this shouldn't be a 
> > problem.
> > 
> > > 3. we might take another (static) index in the future, and it seems 
> > > easier to pass it in via the options than adding another parameter.
> > I'm looking at CodeCompleteOptions as a configurable user preference rather 
> > than a struct, containing all required inputs of codeComplete. I don't 
> > think SymbolIndex is in line with other fields that this struct contains.
> So yeah, this is my fault...
> I do agree it's unfortunate to have a non-user-specified param in the 
> CodeComplete options. It's tricky - from the perspective of this module the 
> index really is such an option, and we want to propagate it around like one. 
> We just don't (currently) want to encourage its use as an API to clangdserver.
> 
> `codeComplete` currently has 9(!) arguments. Different people will have 
> different reactions to this, mine is to do almost anything to avoid a 10th :-)
> 
> > unit-testing code can easily wrap any interface, this shouldn't be a 
> > problem.
> This doesn't match my experience at all. Can you suggest how to test this 
> logic without adding parameters to at least ClangdServer::codeComplete and 
> the codeComplete test helpers?
> 
> > ClangdServer should probably accept it in a constructor instead if we want 
> > to override some stuff via the dynamic index instead.
> As of today, the dynamic index is the only index clangd supports. There's 
> nothing to accept in the constructor, it's entirely owned by ClangdServer.
> codeComplete currently has 9(!) arguments. Different people will have 
> different reactions to this, mine is to do almost anything to avoid a 10th :-)
I do agree this is unfortunate and I'm not at all opposed to cleaning that up. 
By removing parameters that we don't need or grouping them into a struct that 
has saner default parameters or in a different way. Both 9 and 10 seem equally 
bad to me.

My point is that `SymbolIndex` should not be part of `CodeCompleteOptions` only 
because it makes it easier to pass it around.

> This doesn't match my experience at all. Can you suggest how to test this 
> logic without adding parameters to at least ClangdServer::codeComplete and 
> the codeComplete test helpers?
Exactly, I would go with the test helper.

> As of today, the dynamic index is the only index clangd supports. There's 
> nothing to accept in the constructor, it's entirely owned by ClangdServer.
We do have implementations of the index in the tests that we pass around.


That being said, I don't want this change to be blocked by my opinion on this 
matter. This is a minor thing, compared to all the other changes in the patch. 
Just wanted to make a point that this field totally feels out of place.



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281



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


[PATCH] D41391: [clangd] Use the clang-tools-extra as the official repo for `vscode-clangd` extension.

2017-12-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 127529.
hokein marked 3 inline comments as done.
hokein added a comment.

Address review comments and add license.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41391

Files:
  clangd/clients/clangd-vscode/LICENSE
  clangd/clients/clangd-vscode/README.md
  clangd/clients/clangd-vscode/README.txt
  clangd/clients/clangd-vscode/package.json

Index: clangd/clients/clangd-vscode/package.json
===
--- clangd/clients/clangd-vscode/package.json
+++ clangd/clients/clangd-vscode/package.json
@@ -1,17 +1,25 @@
 {
-"name": "clangd-vscode",
-"displayName": "clangd-vscode",
+"name": "vscode-clangd",
+"displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.1",
-"publisher": "Unpublished",
+"version": "0.0.2",
+"publisher": "llvm-vs-code-extensions",
+"homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {
 "vscode": "^1.15.0"
 },
 "categories": [
 "Languages",
 "Linters",
 "Snippets"
 ],
+"keywords": [
+"C",
+"C++",
+"LSP",
+"Clangd",
+"LLVM"
+],
 "activationEvents": [
 "onLanguage:cpp",
 "onLanguage:c"
@@ -34,6 +42,10 @@
 "@types/node": "^6.0.40",
 "@types/mocha": "^2.2.32"
 },
+"repository": {
+  "type": "svn",
+  "url": "http://llvm.org/svn/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/";
+},
 "contributes": {
 "configuration": {
 "type": "object",
Index: clangd/clients/clangd-vscode/README.txt
===
--- clangd/clients/clangd-vscode/README.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-A *toy* VS Code integration for development purposes.
-
-Steps:
-1. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
-point to the binary.
-2. Make sure you have nodejs and npm installed.
-3. Make sure you have VS Code installed.
-4. In order to start a development instance of VS code extended with this, run:
-   $ npm install
-   $ code .
-   When VS Code starts, press .
Index: clangd/clients/clangd-vscode/README.md
===
--- /dev/null
+++ clangd/clients/clangd-vscode/README.md
@@ -0,0 +1,51 @@
+# vscode-clangd
+
+Provides C/C++ language IDE features for VS Code using [clangd](https://clang.llvm.org/extra/clangd.html).
+
+## Usage
+
+`vscode-clangd` provides the features designated by the [Language Server
+Protocol](https://github.com/Microsoft/language-server-protocol), such as
+code completion, code formatting and goto definition.
+
+**Note**: `clangd` is under heavy development, not all LSP features are
+implemented. See [Current Status](https://clang.llvm.org/extra/clangd.html#current-status)
+for details.
+
+To use `vscode-clangd` extension in VS Code, you need to install `vscode-clangd`
+from VS Code extension marketplace.
+
+`vscode-clangd` will attempt to find the `clangd` binary on your `PATH`.
+Alternatively, the `clangd` executable can be specified in your VS Code
+`settings.json` file:
+
+```json
+{
+"clangd.path": "/absolute/path/to/clangd"
+}
+```
+
+To obtain `clangd` binary, please see the [installing Clangd](https://clang.llvm.org/extra/clangd.html#installing-clangd).
+
+## Development
+
+A guide of developing `vscode-clangd` extension.
+
+### Requirements
+
+* VS Code
+* node.js and npm
+
+### Steps
+
+1. Make sure you disable the installed `vscode-clangd` extension in VS Code.
+2. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
+point to the binary.
+3. In order to start a development instance of VS code extended with this, run:
+
+```bash
+   $ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
+   $ npm install
+   $ code .
+   # When VS Code starts, press .
+```
Index: clangd/clients/clangd-vscode/LICENSE
===
--- /dev/null
+++ clangd/clients/clangd-vscode/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 The LLVM Developers
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PU

[PATCH] D41394: [CodeGen] Support generation of TBAA info in the new format

2017-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Tests?


Repository:
  rL LLVM

https://reviews.llvm.org/D41394



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


r321080 - Rename sparc-myriad-elf triplet to sparc-myriad-rtems

2017-12-19 Thread Walter Lee via cfe-commits
Author: waltl
Date: Tue Dec 19 08:19:11 2017
New Revision: 321080

URL: http://llvm.org/viewvc/llvm-project?rev=321080&view=rev
Log:
Rename sparc-myriad-elf triplet to sparc-myriad-rtems

Summary: This is to be consistent with latest Movidius MDK releases.
Also, don't inherit any gcc paths for shave triple.

Reviewers: jyknight

Subscribers: emaste, fedor.sergeev

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

Added:
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/c++/

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/c++/6.3.0/

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/c++/6.3.0/.keep
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/lib/
Removed:
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-elf/
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-elf/
Modified:
cfe/trunk/lib/Driver/ToolChains/Myriad.cpp
cfe/trunk/test/Driver/myriad-toolchain.c

Modified: cfe/trunk/lib/Driver/ToolChains/Myriad.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Myriad.cpp?rev=321080&r1=321079&r2=321080&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Myriad.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Myriad.cpp Tue Dec 19 08:19:11 2017
@@ -199,7 +199,7 @@ void tools::Myriad::Linker::ConstructJob
   }
 
   std::string Exec =
-  Args.MakeArgString(TC.GetProgramPath("sparc-myriad-elf-ld"));
+  Args.MakeArgString(TC.GetProgramPath("sparc-myriad-rtems-ld"));
   C.addCommand(llvm::make_unique(JA, *this, Args.MakeArgString(Exec),
   CmdArgs, Inputs));
 }
@@ -218,10 +218,11 @@ MyriadToolChain::MyriadToolChain(const D
 D.Diag(clang::diag::err_target_unsupported_arch)
 << Triple.getArchName() << "myriad";
 LLVM_FALLTHROUGH;
+  case llvm::Triple::shave:
+return;
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel:
-  case llvm::Triple::shave:
-GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"});
+GCCInstallation.init(Triple, Args, {"sparc-myriad-rtems"});
   }
 
   if (GCCInstallation.isValid()) {
@@ -231,7 +232,7 @@ MyriadToolChain::MyriadToolChain(const D
 addPathIfExists(D, CompilerSupportDir, getFilePaths());
   }
   // libstd++ and libc++ must both be found in this one place.
-  addPathIfExists(D, D.Dir + "/../sparc-myriad-elf/lib", getFilePaths());
+  addPathIfExists(D, D.Dir + "/../sparc-myriad-rtems/lib", getFilePaths());
 }
 
 MyriadToolChain::~MyriadToolChain() {}

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/c++/6.3.0/.keep
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/include/c%2B%2B/6.3.0/.keep?rev=321080&view=auto
==
(empty)

Modified: cfe/trunk/test/Driver/myriad-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/myriad-toolchain.c?rev=321080&r1=321079&r2=321080&view=diff
==
--- cfe/trunk/test/Driver/myriad-toolchain.c (original)
+++ cfe/trunk/test/Driver/myriad-toolchain.c Tue Dec 19 08:19:11 2017
@@ -1,19 +1,19 @@
-// RUN: %clang -no-canonical-prefixes -### -target sparc-myriad-rtems-elf %s \
+// RUN: %clang -no-canonical-prefixes -### -target sparc-myriad-rtems %s \
 // RUN: -ccc-install-dir %S/Inputs/basic_myriad_tree/bin \
 // RUN: --gcc-toolchain=%S/Inputs/basic_myriad_tree 2>&1 | FileCheck %s 
-check-prefix=LINK_WITH_RTEMS
 // LINK_WITH_RTEMS: Inputs{{.*}}crti.o
 // LINK_WITH_RTEMS: Inputs{{.*}}crtbegin.o
-// LINK_WITH_RTEMS: 
"-L{{.*}}Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-elf/4.8.2"
-// LINK_WITH_RTEMS: 
"-L{{.*}}Inputs/basic_myriad_tree/bin/../sparc-myriad-elf/lib"
+// LINK_WITH_RTEMS: 
"-L{{.*}}Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0"
+// LINK_WITH_RTEMS: 
"-L{{.*}}Inputs/basic_myriad_tree/bin/../sparc-myriad-rtems/lib"
 // LINK_WITH_RTEMS: "--start-group" "-lc" "-lgcc" "-lrtemscpu" "-lrtemsbsp" 
"--end-group"
 // LINK_WITH_RTEMS: Inputs{{.*}}crtend.o
 // LINK_WITH_RTEMS: Inputs{{.*}}crtn.o
 
-// RUN: %clang -c -no-canonical-prefixes -### -target sparc-myriad-rtems-elf 
-x c++ %s \
+// RUN: %clang -c -no-canonical-prefixes -### -target sparc-myriad-rtems -x 
c++ %s \
 // RUN: -stdlib=libstdc++ --gcc-toolchain=%S/Inputs/basic_myriad_tree 2>&1 | 
FileCheck %s -check-prefix=COMPILE_CXX
-// COMPILE_CXX: "-internal-isystem" 
"{{.*}}/Inpu

[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127536.
ioeric marked an inline comment as done.
ioeric added a comment.

- Move implementations around to make code easier to read.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -143,7 +143,7 @@
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("");
+  Req.Scopes = {""};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
@@ -153,7 +153,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
@@ -163,8 +163,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
-  Req.Scopes.push_back("b");
+  Req.Scopes = {"a", "b"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
@@ -174,7 +173,7 @@
   I.build(generateSymbols({"a::xyz", "a::b::yy"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -6,13 +6,15 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+
 #include "ClangdServer.h"
 #include "Compiler.h"
 #include "Context.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
+#include "index/MemIndex.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -83,6 +85,7 @@
 MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
 MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
 MATCHER_P(Kind, K, "") { return arg.kind == K; }
+MATCHER_P(Filter, F, "") { return arg.filterText == F; }
 MATCHER_P(PlainText, Text, "") {
   return arg.insertTextFormat == clangd::InsertTextFormat::PlainText &&
  arg.insertText == Text;
@@ -457,6 +460,104 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+std::unique_ptr simpleIndexFromSymbols(
+std::vector> Symbols) {
+  auto I = llvm::make_unique();
+  struct Snapshot {
+SymbolSlab Slab;
+std::vector Pointers;
+  };
+  auto Snap = std::make_shared();
+  for (const auto &Pair : Symbols) {
+Symbol Sym;
+Sym.ID = SymbolID(Pair.first);
+llvm::StringRef QName = Pair.first;
+size_t Pos = QName.rfind("::");
+if (Pos == llvm::StringRef::npos) {
+  Sym.Name = QName;
+  Sym.Scope = "";
+} else {
+  Sym.Name = QName.substr(Pos + 2);
+  Sym.Scope = QName.substr(0, Pos);
+}
+Sym.SymInfo.Kind = Pair.second;
+Snap->Slab.insert(std::move(Sym));
+  }
+  for (auto &Iter : Snap->Slab)
+Snap->Pointers.push_back(&Iter.second);
+  auto S = std::shared_ptr>(std::move(Snap),
+&Snap->Pointers);
+  I->build(std::move(S));
+  return I;
+}
+
+TEST(CompletionTest, NoIndex) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = nullptr;
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("No"));
+}
+
+TEST(CompletionTest, SimpleIndexBased) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"nx::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = I.get();
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Not(Has("No")));
+}
+
+TEST(CompletionTest, IndexBasedWithFilter) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"ns::foo"

[PATCH] D41368: [libc++] Ignore bogus tautologic comparison warnings

2017-12-19 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

In https://reviews.llvm.org/D41368#958865, @zturner wrote:

> It would be better if we could just fix the code.


I disagree (See discussion of https://reviews.llvm.org/D39149). Even if it was 
"just this one place" (which it isn't), this affects users of clang, not just 
libc++.
This is a (small, but significant) barrier to people trying to write correct, 
portable generic code, and clang is just wrong to warn here.

As an aside, I definitely object to "just fix the code". The code is correct as 
written.
I think what you mean is "it would be better if we could just tell the compiler 
to shut up"  (which is what you've proposed - but incompletely)


Repository:
  rCXX libc++

https://reviews.llvm.org/D41368



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127538.
ioeric added a comment.

- Add a FIXME for Index in code completion options.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/IndexTests.cpp

Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -143,7 +143,7 @@
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("");
+  Req.Scopes = {""};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
@@ -153,7 +153,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
@@ -163,8 +163,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
-  Req.Scopes.push_back("b");
+  Req.Scopes = {"a", "b"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
@@ -174,7 +173,7 @@
   I.build(generateSymbols({"a::xyz", "a::b::yy"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -6,13 +6,15 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+
 #include "ClangdServer.h"
 #include "Compiler.h"
 #include "Context.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
+#include "index/MemIndex.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -83,6 +85,7 @@
 MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
 MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
 MATCHER_P(Kind, K, "") { return arg.kind == K; }
+MATCHER_P(Filter, F, "") { return arg.filterText == F; }
 MATCHER_P(PlainText, Text, "") {
   return arg.insertTextFormat == clangd::InsertTextFormat::PlainText &&
  arg.insertText == Text;
@@ -457,6 +460,104 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+std::unique_ptr simpleIndexFromSymbols(
+std::vector> Symbols) {
+  auto I = llvm::make_unique();
+  struct Snapshot {
+SymbolSlab Slab;
+std::vector Pointers;
+  };
+  auto Snap = std::make_shared();
+  for (const auto &Pair : Symbols) {
+Symbol Sym;
+Sym.ID = SymbolID(Pair.first);
+llvm::StringRef QName = Pair.first;
+size_t Pos = QName.rfind("::");
+if (Pos == llvm::StringRef::npos) {
+  Sym.Name = QName;
+  Sym.Scope = "";
+} else {
+  Sym.Name = QName.substr(Pos + 2);
+  Sym.Scope = QName.substr(0, Pos);
+}
+Sym.SymInfo.Kind = Pair.second;
+Snap->Slab.insert(std::move(Sym));
+  }
+  for (auto &Iter : Snap->Slab)
+Snap->Pointers.push_back(&Iter.second);
+  auto S = std::shared_ptr>(std::move(Snap),
+&Snap->Pointers);
+  I->build(std::move(S));
+  return I;
+}
+
+TEST(CompletionTest, NoIndex) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = nullptr;
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("No"));
+}
+
+TEST(CompletionTest, SimpleIndexBased) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"nx::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = I.get();
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Not(Has("No")));
+}
+
+TEST(CompletionTest, IndexBasedWithFilter) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index 

[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/CodeComplete.h:64
+
+  // Populated internally by clangd, do not set.
+  /// If `Index` is set, it is used to augment the code completion

ilya-biryukov wrote:
> sammccall wrote:
> > ilya-biryukov wrote:
> > > ioeric wrote:
> > > > ilya-biryukov wrote:
> > > > > Given the comment, maybe we want to pass it as a separate parameter 
> > > > > instead?
> > > > @sammccall suggested this approach in the previous prototype patch. I 
> > > > also ended up preferring this approach because:
> > > >  1) it doesn't require changing ClangdServer interfaces, and the 
> > > > dynamic index should be built by ClangdServer and thus doesn't make 
> > > > sense to be a parameter.
> > > >  2) it enables unit tests to use customized dummy indexes.
> > > >  3) we might take another (static) index in the future, and it seems 
> > > > easier to pass it in via the options than adding another parameter.
> > > > 1. it doesn't require changing ClangdServer interfaces, and the dynamic 
> > > > index should be built by ClangdServer and thus doesn't make sense to be 
> > > > a parameter.
> > > We do have it as a parameter to `codeComplete` method, the fact that it's 
> > > wrapped in a struct does not make much difference.
> > > `ClangdServer` should probably accept it in a constructor instead if we 
> > > want to override some stuff via the dynamic index instead.
> > > 
> > > > 2. it enables unit tests to use customized dummy indexes.
> > > unit-testing code can easily wrap any interface, this shouldn't be a 
> > > problem.
> > > 
> > > > 3. we might take another (static) index in the future, and it seems 
> > > > easier to pass it in via the options than adding another parameter.
> > > I'm looking at CodeCompleteOptions as a configurable user preference 
> > > rather than a struct, containing all required inputs of codeComplete. I 
> > > don't think SymbolIndex is in line with other fields that this struct 
> > > contains.
> > So yeah, this is my fault...
> > I do agree it's unfortunate to have a non-user-specified param in the 
> > CodeComplete options. It's tricky - from the perspective of this module the 
> > index really is such an option, and we want to propagate it around like 
> > one. We just don't (currently) want to encourage its use as an API to 
> > clangdserver.
> > 
> > `codeComplete` currently has 9(!) arguments. Different people will have 
> > different reactions to this, mine is to do almost anything to avoid a 10th 
> > :-)
> > 
> > > unit-testing code can easily wrap any interface, this shouldn't be a 
> > > problem.
> > This doesn't match my experience at all. Can you suggest how to test this 
> > logic without adding parameters to at least ClangdServer::codeComplete and 
> > the codeComplete test helpers?
> > 
> > > ClangdServer should probably accept it in a constructor instead if we 
> > > want to override some stuff via the dynamic index instead.
> > As of today, the dynamic index is the only index clangd supports. There's 
> > nothing to accept in the constructor, it's entirely owned by ClangdServer.
> > codeComplete currently has 9(!) arguments. Different people will have 
> > different reactions to this, mine is to do almost anything to avoid a 10th 
> > :-)
> I do agree this is unfortunate and I'm not at all opposed to cleaning that 
> up. By removing parameters that we don't need or grouping them into a struct 
> that has saner default parameters or in a different way. Both 9 and 10 seem 
> equally bad to me.
> 
> My point is that `SymbolIndex` should not be part of `CodeCompleteOptions` 
> only because it makes it easier to pass it around.
> 
> > This doesn't match my experience at all. Can you suggest how to test this 
> > logic without adding parameters to at least ClangdServer::codeComplete and 
> > the codeComplete test helpers?
> Exactly, I would go with the test helper.
> 
> > As of today, the dynamic index is the only index clangd supports. There's 
> > nothing to accept in the constructor, it's entirely owned by ClangdServer.
> We do have implementations of the index in the tests that we pass around.
> 
> 
> That being said, I don't want this change to be blocked by my opinion on this 
> matter. This is a minor thing, compared to all the other changes in the 
> patch. Just wanted to make a point that this field totally feels out of place.
> 
Thanks for the feedback! I added a FIXME for this. I am happy to clean this up 
when we have a saner way to config code completion in clangd :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41281



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


[PATCH] D39834: [clang] -foptimization-record-file= should imply -fsave-optimization-record

2017-12-19 Thread Dmitry Venikov via Phabricator via cfe-commits
Quolyk added a comment.

In https://reviews.llvm.org/D39834#959500, @JDevlieghere wrote:

> Thanks Dmitry, this LGTM!
>
> PS: Let me know if you don't have commit access and want me to commit it for 
> you.


I don't have commit access, please commit. Thanks for code review.


https://reviews.llvm.org/D39834



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


r321082 - Add renamed .o files that were omitted by "git llvm push" command

2017-12-19 Thread Walter Lee via cfe-commits
Author: waltl
Date: Tue Dec 19 08:34:13 2017
New Revision: 321082

URL: http://llvm.org/viewvc/llvm-project?rev=321082&view=rev
Log:
Add renamed .o files that were omitted by "git llvm push" command

Original commit is at: https://reviews.llvm.org/D41295.


Added:

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtbegin.o

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtend.o

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crti.o

cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtn.o
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/lib/crt0.o

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtbegin.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtbegin.o?rev=321082&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtend.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtend.o?rev=321082&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crti.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crti.o?rev=321082&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtn.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/lib/gcc/sparc-myriad-rtems/6.3.0/crtn.o?rev=321082&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/lib/crt0.o
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_myriad_tree/sparc-myriad-rtems/lib/crt0.o?rev=321082&view=auto
==
(empty)


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


[PATCH] D41368: [libc++] Ignore bogus tautologic comparison warnings

2017-12-19 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

@mclow.lists are you okay with this approach? I'm also fine using a cast to 
silence the warning, as @zturner suggested, but we should suppress the warning 
in some way, otherwise libc++ 6 is gonna have compile warnings with clang 6 out 
of the box, which isn't great.

A third alternative, which is the least invasive, though not complete in some 
sense: we just add `-Wno-tautological-constant-compare` to the compile flags 
for libc++ (in CMake), to suppress the warning during libc++'s compilation. 
There's still an instance of the warning in a header, but all other clients of 
the header should treat it as a system header (in which case warnings will be 
suppressed anyway). It's not targeted at all and could suppress legitimate 
instances of the warning though.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41368



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


[PATCH] D41368: [libc++] Ignore bogus tautologic comparison warnings

2017-12-19 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Also FWIW I agree with you that the warning is completely bogus here, but it 
looks like the fix to that warning isn't gonna make it into clang 6, at least, 
so we have to adjust accordingly.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41368



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


[PATCH] D41281: [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321083: [clangd] Index-based code completion. (authored by 
ioeric, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41281

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/CodeComplete.h
  clang-tools-extra/trunk/clangd/index/FileIndex.cpp
  clang-tools-extra/trunk/clangd/index/FileIndex.h
  clang-tools-extra/trunk/clangd/index/Index.h
  clang-tools-extra/trunk/clangd/index/MemIndex.cpp
  clang-tools-extra/trunk/clangd/index/MemIndex.h
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/trunk/unittests/clangd/IndexTests.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
@@ -143,7 +143,7 @@
   I.build(generateSymbols({"a::xyz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("");
+  Req.Scopes = {""};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("yz"));
 }
@@ -153,7 +153,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy"));
 }
@@ -163,8 +163,7 @@
   I.build(generateSymbols({"a::xyz", "a::yy", "a::xz", "b::yz", "yz"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
-  Req.Scopes.push_back("b");
+  Req.Scopes = {"a", "b"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz", "a::yy", "b::yz"));
 }
@@ -174,7 +173,7 @@
   I.build(generateSymbols({"a::xyz", "a::b::yy"}));
   FuzzyFindRequest Req;
   Req.Query = "y";
-  Req.Scopes.push_back("a");
+  Req.Scopes = {"a"};
   auto Matches = match(I, Req);
   EXPECT_THAT(match(I, Req), UnorderedElementsAre("a::xyz"));
 }
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -6,13 +6,15 @@
 // License. See LICENSE.TXT for details.
 //
 //===--===//
+
 #include "ClangdServer.h"
 #include "Compiler.h"
 #include "Context.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
+#include "index/MemIndex.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -83,6 +85,7 @@
 MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
 MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
 MATCHER_P(Kind, K, "") { return arg.kind == K; }
+MATCHER_P(Filter, F, "") { return arg.filterText == F; }
 MATCHER_P(PlainText, Text, "") {
   return arg.insertTextFormat == clangd::InsertTextFormat::PlainText &&
  arg.insertText == Text;
@@ -457,6 +460,104 @@
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+std::unique_ptr simpleIndexFromSymbols(
+std::vector> Symbols) {
+  auto I = llvm::make_unique();
+  struct Snapshot {
+SymbolSlab Slab;
+std::vector Pointers;
+  };
+  auto Snap = std::make_shared();
+  for (const auto &Pair : Symbols) {
+Symbol Sym;
+Sym.ID = SymbolID(Pair.first);
+llvm::StringRef QName = Pair.first;
+size_t Pos = QName.rfind("::");
+if (Pos == llvm::StringRef::npos) {
+  Sym.Name = QName;
+  Sym.Scope = "";
+} else {
+  Sym.Name = QName.substr(Pos + 2);
+  Sym.Scope = QName.substr(0, Pos);
+}
+Sym.SymInfo.Kind = Pair.second;
+Snap->Slab.insert(std::move(Sym));
+  }
+  for (auto &Iter : Snap->Slab)
+Snap->Pointers.push_back(&Iter.second);
+  auto S = std::shared_ptr>(std::move(Snap),
+&Snap->Pointers);
+  I->build(std::move(S));
+  return I;
+}
+
+TEST(CompletionTest, NoIndex) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = nullptr;
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("No"));
+}
+
+TEST(CompletionTest, SimpleIndexBased) {
+  clangd::CodeCompleteOptions Opts;
+  auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
+   {"nx::XYZ", index::SymbolKind::Class},
+   {"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = I.get();
+
+  auto Results = completions(R"cpp(
+  namespace ns { class No {}; }
+  void f() { ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Has("XYZ", Complet

[clang-tools-extra] r321083 - [clangd] Index-based code completion.

2017-12-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Dec 19 08:50:37 2017
New Revision: 321083

URL: http://llvm.org/viewvc/llvm-project?rev=321083&view=rev
Log:
[clangd] Index-based code completion.

Summary: Use symbol index to populate completion results for qualfified IDs 
e.g. "nx::A^".

Reviewers: ilya-biryukov, sammccall

Reviewed By: ilya-biryukov, sammccall

Subscribers: rwols, klimek, mgorny, cfe-commits, sammccall

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=321083&r1=321082&r2=321083&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Dec 19 08:50:37 2017
@@ -16,6 +16,8 @@
 
 #include "CodeComplete.h"
 #include "Compiler.h"
+#include "Logger.h"
+#include "index/Index.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -26,26 +28,28 @@ namespace clang {
 namespace clangd {
 namespace {
 
-CompletionItemKind getKindOfDecl(CXCursorKind CursorKind) {
+CompletionItemKind toCompletionItemKind(CXCursorKind CursorKind) {
   switch (CursorKind) {
   case CXCursor_MacroInstantiation:
   case CXCursor_MacroDefinition:
 return CompletionItemKind::Text;
   case CXCursor_CXXMethod:
+  case CXCursor_Destructor:
 return CompletionItemKind::Method;
   case CXCursor_FunctionDecl:
   case CXCursor_FunctionTemplate:
 return CompletionItemKind::Function;
   case CXCursor_Constructor:
-  case CXCursor_Destructor:
 return CompletionItemKind::Constructor;
   case CXCursor_FieldDecl:
 return CompletionItemKind::Field;
   case CXCursor_VarDecl:
   case CXCursor_ParmDecl:
 return CompletionItemKind::Variable;
-  case CXCursor_ClassDecl:
+  // FIXME(ioeric): use LSP struct instead of class when it is suppoted in the
+  // protocol.
   case CXCursor_StructDecl:
+  case CXCursor_ClassDecl:
   case CXCursor_UnionDecl:
   case CXCursor_ClassTemplate:
   case CXCursor_ClassTemplatePartialSpecialization:
@@ -58,6 +62,7 @@ CompletionItemKind getKindOfDecl(CXCurso
 return CompletionItemKind::Value;
   case CXCursor_EnumDecl:
 return CompletionItemKind::Enum;
+  // FIXME(ioeric): figure out whether reference is the right type for aliases.
   case CXCursor_TypeAliasDecl:
   case CXCursor_TypeAliasTemplateDecl:
   case CXCursor_TypedefDecl:
@@ -69,11 +74,12 @@ CompletionItemKind getKindOfDecl(CXCurso
   }
 }
 
-CompletionItemKind getKind(CodeCompletionResult::ResultKind ResKind,
-   CXCursorKind CursorKind) {
+CompletionItemKind
+toCompletionItemKind(CodeCompletionResult::ResultKind ResKind,
+ CXCursorKind CursorKind) {
   switch (ResKind) {
   case CodeCompletionResult::RK_Declaration:
-return getKindOfDecl(CursorKind);
+return toCompletionItemKind(CursorKind);
   case CodeCompletionResult::RK_Keyword:
 return CompletionItemKind::Keyword;
   case CodeCompletionResult::RK_Macro:
@@ -85,6 +91,59 @@ CompletionItemKind getKind(CodeCompletio
   llvm_unreachable("Unhandled CodeCompletionResult::ResultKind.");
 }
 
+CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
+  using SK = index::SymbolKind;
+  switch (Kind) {
+  case SK::Unknown:
+return CompletionItemKind::Missing;
+  case SK::Module:
+  case SK::Namespace:
+  case SK::NamespaceAlias:
+return CompletionItemKind::Module;
+  case SK::Macro:
+return CompletionItemKind::Text;
+  case SK::Enum:
+return CompletionItemKind::Enum;
+  // FIXME(ioeric): use LSP struct instead of class when it is suppoted in the
+  // protocol.
+  case SK::Struct:
+  case SK::Class:
+  case SK::Protocol:
+  case SK::Extension:
+  case SK::Union:
+return CompletionItemKind::Class;
+  // FIXME(ioeric): figure out whether reference is the right type for aliases.
+  case SK::TypeAlias:
+  case SK::Using:
+return CompletionItemKind::Reference;
+  case SK::Function:
+  // FIXME(ioeric): this should probably be an operator. This should be fixed
+  // when `Operator` is support type in the protocol.
+  case SK::ConversionFunction:
+return CompletionItemKind::Function;
+  case SK::Variable:
+  case SK::Parameter:
+return CompletionItemKind::Variable;
+  case SK::Field:
+return CompletionItemKind::Field;
+  // F

[PATCH] D41399: [CodeGen] Represent array members in new-format TBAA type descriptors

2017-12-19 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added reviewers: rjmccall, hfinkel.
kosarev added a project: clang.

Now that in the new TBAA format we allow access types to be of any object 
types, including aggregate ones, it becomes critical to specify types of all 
sub-objects such aggregates comprise as their members. In order to meet this 
requirement, this patch enables generation of field descriptors for members of 
array types.

This patch requires https://reviews.llvm.org/D41394 to be landed first.


Repository:
  rL LLVM

https://reviews.llvm.org/D41399

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-array.cpp


Index: test/CodeGen/tbaa-array.cpp
===
--- test/CodeGen/tbaa-array.cpp
+++ test/CodeGen/tbaa-array.cpp
@@ -1,18 +1,28 @@
 // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
-// RUN: -emit-llvm -o - | FileCheck %s
-//
-// Check that we generate correct TBAA information for accesses to array
-// elements.
+// RUN: -new-struct-path-tbaa -emit-llvm -o - | FileCheck %s
 
 struct A { int i; };
 struct B { A a[1]; };
+struct C { int i; int x[3]; };
 
+// Check that we generate correct TBAA information for accesses to array
+// elements.
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
   return b->a->i;
 }
 
-// CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
-// CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
-// CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
+// Check that members of array types are represented correctly.
+int bar(C *c) {
+// CHECK-LABEL: _Z3barP1C
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
+  return c->i;
+}
+
+// CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0, i64 4}
+// CHECK-DAG: [[TAG_C_i]] = !{[[TYPE_C:!.*]], [[TYPE_int:!.*]], i64 0, i64 16}
+// CHECK-DAG: [[TYPE_A]] = !{[[TYPE_char:!.*]], i64 4, !"_ZTS1A", 
[[TYPE_int]], i64 0, i64 4}
+// CHECK-DAG: [[TYPE_C]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", [[TYPE_int]], 
i64 0, i64 4, [[TYPE_int]], i64 4, i64 12}
+// CHECK-DAG: [[TYPE_int]] = !{[[TYPE_char]], i64 4, !"int"}
+// CHECK-DAG: [[TYPE_char]] = !{{{!.*}}, i64 1, !"omnipotent char"}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -161,6 +161,10 @@
   if (Ty->isPointerType() || Ty->isReferenceType())
 return createScalarTypeNode("any pointer", getChar(), Size);
 
+  // Accesses to arrays are accesses to objects of their element types.
+  if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
+return getTypeInfo(cast(Ty)->getElementType());
+
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {


Index: test/CodeGen/tbaa-array.cpp
===
--- test/CodeGen/tbaa-array.cpp
+++ test/CodeGen/tbaa-array.cpp
@@ -1,18 +1,28 @@
 // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
-// RUN: -emit-llvm -o - | FileCheck %s
-//
-// Check that we generate correct TBAA information for accesses to array
-// elements.
+// RUN: -new-struct-path-tbaa -emit-llvm -o - | FileCheck %s
 
 struct A { int i; };
 struct B { A a[1]; };
+struct C { int i; int x[3]; };
 
+// Check that we generate correct TBAA information for accesses to array
+// elements.
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
   return b->a->i;
 }
 
-// CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
-// CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
-// CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
+// Check that members of array types are represented correctly.
+int bar(C *c) {
+// CHECK-LABEL: _Z3barP1C
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
+  return c->i;
+}
+
+// CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0, i64 4}
+// CHECK-DAG: [[TAG_C_i]] = !{[[TYPE_C:!.*]], [[TYPE_int:!.*]], i64 0, i64 16}
+// CHECK-DAG: [[TYPE_A]] = !{[[TYPE_char:!.*]], i64 4, !"_ZTS1A", [[TYPE_int]], i64 0, i64 4}
+// CHECK-DAG: [[TYPE_C]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", [[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 4, i64 12}
+// CHECK-DAG: [[TYPE_int]] = !{[[TYPE_char]], i64 4, !"int"}
+// CHECK-DAG: [[TYPE_char]] = !{{{!.*}}, i64 1, !"omnipotent char"}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -161,6 +161,10 @@
   if (Ty->isPointerType() || Ty->isReferenceType())
 return createScalarTypeNode("any pointer", getChar(), Size);
 
+  // Accesses to arrays are accesses to objects of their element types.
+  if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
+return getTypeInfo(cas

[PATCH] D41077: [analyser] different.CallArgsOrder checker implementation

2017-12-19 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hi Alexey,

This commit strongly needs testing on some real code. I cannot predict the TP 
rate of this checker now.
Regarding implementation, you can find some remarks inline.




Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:31
+
+class ParamsGroup {
+public:

We have a class without any private parts. This means that we should declare it 
as 'struct' or do some redesign - the way it is constructed (with expressions 
like `PGL.back().ParamsVec.push_back(std::move(p));` clearly indicates some 
design issues. I suggest at least adding a wrapper above ParamsGroupVec with 
methods:
 `ParamGroup &addParam(const ParmVarDecl *ParamVD)`; // adds a variable into 
existing group or creates new one
`void reclaimLastGroupIfSingle(); // deletes last added group if it has only a 
single element`
and moving some logic here.




Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:33
+public:
+  ParamsGroup() : StartIndex(0) { ParamsVec.reserve(4); }
+

You don't need to reserve  the amount of items same or less then SmallVector 
default size - they are already stack-allocated.



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:112
+  checkCallExpr(CE);
+if (const CXXConstructExpr *CE =
+Result.Nodes.getNodeAs("cxxConstructExpr"))

else if?



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:119
+
+StringRefVec ParamsGroup::trimSame(StringRefVec StrVec) {
+  return rtrimSame(ltrimSame(StrVec));

trim* functions should be moved out of ParamsGroup because they are not 
related. 



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:139
+
+if (SamePrefixSize > StrSize) {
+  SamePrefix = SamePrefix.drop_back(SamePrefixSize - StrSize);

We can the code:
```
SamePrefix = SamePrefix.take_front(StrSize);
SamePrefixSize = SamePrefix.size();
```
instead. The behaviour of `StringRef::take_front(size_t N)` is well-defined if 
N >= size().

Same below: drop_front() can be replaced with take_back().



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:144
+
+for (size_t i = 0; i < SamePrefixSize; i++) {
+  if (Str[i] != SamePrefix[i]) {

What you are trying to do here (find common prefix of two strings) can be done 
easier using std::mismatch().



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:157
+  const size_t SamePrefixSize = SamePrefix.size();
+  std::transform(StrVec.begin(), StrVec.end(), StrVec.begin(),
+ [SamePrefixSize](const StringRef &Str) {

llvm::transform(StrVec, StrVec.begin(), ...)



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:164
+
+StringRefVec ParamsGroup::rtrimSame(StringRefVec StrVec) {
+  if (StrVec.empty())

szepet wrote:
> Please add a comment to this function which describes its input, output, 
> purpose.
With names like removeCommon[Pre/Suf]fix, the intention of these functions will 
be much cleaner. Also, please do not pass vectors by value.



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:185
+
+for (size_t i = StrSize, j = SameSuffixSize; i > 0 && j > 0; i--, j--) {
+  if (Str[i - 1] != SameSuffix[j - 1]) {

We can use std::mismatch with std::reverse_iterator (std::rbegin(), 
std::rend()).



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:208
+CallArgsOrderChecker::getOrBuildParamsGroups(const FunctionDecl *FD) const {
+  const auto It = PGLCache.find(FD);
+  if (It != PGLCache.end())

We can use `try_emplace()` to construct the new item in-place.



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:215
+  const unsigned NumParams = FD->getNumParams();
+  if (NumParams > 0) {
+const ParmVarDecl *prevParam = FD->getParamDecl(0);

This is already check in the caller. I think, this can be replaced with an 
assertion.



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:257
+
+static StringRef getExprName(const Expr *E) {
+  const Expr *OrigE = E->IgnoreParenCasts();

Could you please explain what kind of ExprName are you trying to get?



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:259
+  const Expr *OrigE = E->IgnoreParenCasts();
+  if (!OrigE)
+return StringRef();

As I remember, IgnoreParenCasts() can not return nullptr. So, we can turn this 
into assertion.



Comment at: lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp:262
+
+  if (const DeclRefExpr *DRE = dyn_cast_or_null(OrigE))
+return DRE->getFoundDecl()->getName();

OrigE is not nullptr s

[PATCH] D41368: [libc++] Ignore bogus tautologic comparison warnings

2017-12-19 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

In https://reviews.llvm.org/D41368#959579, @smeenai wrote:

> @mclow.lists are you okay with this approach? I'm also fine using a cast to 
> silence the warning, as @zturner suggested, but we should suppress the 
> warning in some way, otherwise libc++ 6 is gonna have compile warnings with 
> clang 6 out of the box, which isn't great.
>
> A third alternative, which is the least invasive, though not complete in some 
> sense: we just add `-Wno-tautological-constant-compare` to the compile flags 
> for libc++ (in CMake), to suppress the warning during libc++'s compilation. 
> There's still an instance of the warning in a header, but all other clients 
> of the header should treat it as a system header (in which case warnings will 
> be suppressed anyway). It's not targeted at all and could suppress legitimate 
> instances of the warning though.


I agree, if we're willing to disable the warning in libc++ builds we should be 
willing to disable it via pragma.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41368



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


[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127544.
ioeric added a comment.

- Merge with https://reviews.llvm.org/D41289.
- Merge with origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -558,6 +558,58 @@
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, ASTIndexOneFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  auto File = getVirtualTestFilePath("foo.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  void f() { ns::^ }
+  )cpp");
+  // Wait to make sure AST is parsed.
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+}
+
+TEST(CompletionTest, ASTIndexMultiFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  Server
+  .addDocument(Context::empty(), getVirtualTestFilePath("foo.cpp"), R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  )cpp")
+  .wait();
+
+  auto File = getVirtualTestFilePath("bar.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XXX {}; void fo() {} }
+  void f() { ns::^ }
+  )cpp");
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Has("XXX", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("fo", CompletionItemKind::Function));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -90,6 +90,13 @@
 "Trace internal events and timestamps in chrome://tracing JSON format"),
 llvm::cl::init(""), llvm::cl::Hidden);
 
+static llvm::cl::opt EnableIndexBasedCompletion(
+"enable-index-based-completion",
+llvm::cl::desc(
+"Enable index-based global code completion (experimental). Clangd will "
+"use index built from symbols in opened files"),
+llvm::cl::init(false));
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
@@ -180,7 +187,8 @@
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(Out, WorkerThreadsCount, StorePreamblesInMemory,
-CCOpts, ResourceDirRef, CompileCommandsDirPath);
+CCOpts, ResourceDirRef, CompileCommandsDirPath,
+EnableIndexBasedCompletion);
   constexpr int NoShutdownRequestErrorCode = 1;
   llvm::set_thread_name("clangd.main");
   return LSPServer.run(std::cin) ? 0 : NoShutdownRequestErrorCode;
Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -25,6 +25,10 @@
 /// Thread-safe mapping from FileNames to CppFile.
 class CppFileCollection {
 public:
+  /// \p ASTCallback is called when a file is parsed.
+  explicit CppFileCollection(ASTParsedCallback ASTCallback)
+  : ASTCallback(std::move(ASTCallback)) {}
+
   std::shared_ptr
   getOrCreateFile(PathRef File, PathRef ResourceDir,
   GlobalCompilationDatabase &CDB, bool StorePreamblesInMemory,
@@ -38,7 +42,7 @@
   It = OpenedFiles
.try_emplace(File, CppFile::Create(File, std::move(Command),
   StorePreamblesInMemory,
-  

[clang-tools-extra] r321086 - [clangd] Fix warnings/compiler pickiness after r321083

2017-12-19 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Dec 19 09:05:00 2017
New Revision: 321086

URL: http://llvm.org/viewvc/llvm-project?rev=321086&view=rev
Log:
[clangd] Fix warnings/compiler pickiness after r321083

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=321086&r1=321085&r2=321086&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Dec 19 09:05:00 2017
@@ -784,7 +784,7 @@ SpecifiedScope extraCompletionScope(Sema
 DeclContext *DC = S.computeDeclContext(SS);
 if (auto *NS = llvm::dyn_cast(DC)) {
   Info.Resolved = NS->getQualifiedNameAsString();
-} else if (auto *TU = llvm::dyn_cast(DC)) {
+} else if (llvm::dyn_cast(DC) != nullptr) {
   Info.Resolved = "::";
   // Sema does not include the suffix "::" in the range of SS, so we add
   // it back here.

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=321086&r1=321085&r2=321086&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Dec 19 
09:05:00 2017
@@ -488,7 +488,7 @@ std::unique_ptr simpleIndex
   auto S = std::shared_ptr>(std::move(Snap),
 &Snap->Pointers);
   I->build(std::move(S));
-  return I;
+  return std::move(I);
 }
 
 TEST(CompletionTest, NoIndex) {


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


[clang-tools-extra] r321087 - [clangd] Split findDefs/highlights into XRefs, from ClangdUnit. NFC

2017-12-19 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Dec 19 09:06:07 2017
New Revision: 321087

URL: http://llvm.org/viewvc/llvm-project?rev=321087&view=rev
Log:
[clangd] Split findDefs/highlights into XRefs, from ClangdUnit. NFC

Going to add unit tests in the next patch. (Haha!) But seriously there's
some work to do first - need to extract the markers-in-source-code
parser from CodeComplete test and make it more flexible, to allow
annotated ranges etc.

Added:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/XRefs.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=321087&r1=321086&r2=321087&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Tue Dec 19 09:06:07 2017
@@ -20,6 +20,7 @@ add_clang_library(clangDaemon
   ProtocolHandlers.cpp
   SourceCode.cpp
   Trace.cpp
+  XRefs.cpp
   index/FileIndex.cpp
   index/Index.cpp
   index/MemIndex.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=321087&r1=321086&r2=321087&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Dec 19 09:06:07 2017
@@ -8,7 +8,9 @@
 //===---===//
 
 #include "ClangdServer.h"
+#include "CodeComplete.h"
 #include "SourceCode.h"
+#include "XRefs.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=321087&r1=321086&r2=321087&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Dec 19 09:06:07 2017
@@ -267,268 +267,15 @@ ParsedAST::Build(const Context &Ctx,
 namespace {
 
 SourceLocation getMacroArgExpandedLocation(const SourceManager &Mgr,
-   const FileEntry *FE,
-   unsigned Offset) {
-  SourceLocation FileLoc = Mgr.translateFileLineCol(FE, 1, 1);
-  return Mgr.getMacroArgExpandedLocation(FileLoc.getLocWithOffset(Offset));
-}
-
-SourceLocation getMacroArgExpandedLocation(const SourceManager &Mgr,
const FileEntry *FE, Position Pos) {
   SourceLocation InputLoc =
   Mgr.translateFileLineCol(FE, Pos.line + 1, Pos.character + 1);
   return Mgr.getMacroArgExpandedLocation(InputLoc);
 }
 
-/// Finds declarations locations that a given source location refers to.
-class DeclarationAndMacrosFinder : public index::IndexDataConsumer {
-  std::vector Decls;
-  std::vector MacroInfos;
-  const SourceLocation &SearchedLocation;
-  const ASTContext &AST;
-  Preprocessor &PP;
-
-public:
-  DeclarationAndMacrosFinder(raw_ostream &OS,
- const SourceLocation &SearchedLocation,
- ASTContext &AST, Preprocessor &PP)
-  : SearchedLocation(SearchedLocation), AST(AST), PP(PP) {}
-
-  std::vector takeDecls() {
-// Don't keep the same declaration multiple times.
-// This can happen when nodes in the AST are visited twice.
-std::sort(Decls.begin(), Decls.end());
-auto Last = std::unique(Decls.begin(), Decls.end());
-Decls.erase(Last, Decls.end());
-return std::move(Decls);
-  }
-
-  std::vector takeMacroInfos() {
-// Don't keep the same Macro info multiple times.
-std::sort(MacroInfos.begin(), MacroInfos.end());
-auto Last = std::unique(MacroInfos.begin(), MacroInfos.end());
-MacroInfos.erase(Last, MacroInfos.end());
-return std::move(MacroInfos);
-  }
-
-  bool
-  handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
-  ArrayRef Relations, FileID FID,
-  unsigned Offset,
-  index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
-if (isSearchedLocation(FID, Offset))
-  Decls.push_back(D);
-return true;
-  }
-
-private:
-  bool isSearchedLocation(FileID FID, unsigned Offset) const {
-const SourceManager &SourceMgr = AST.getSourceManager();
-return SourceMgr.getFileOffset(SearchedLocation) == Offset &&
-   SourceMgr.getFileID(SearchedLocation) == FID;
-  }
-
-  void finish() override {
-// 

r321090 - [clang] -foptimization-record-file= should imply -fsave-optimization-record

2017-12-19 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Tue Dec 19 09:16:45 2017
New Revision: 321090

URL: http://llvm.org/viewvc/llvm-project?rev=321090&view=rev
Log:
[clang] -foptimization-record-file= should imply -fsave-optimization-record

The Clang option -foptimization-record-file= controls which file an
optimization record is output to. Optimization records are output if you
use the Clang option -fsave-optimization-record. If you specify the
first option without the second, you get a warning that the command line
argument was unused. Passing -foptimization-record-file= should imply
-fsave-optimization-record.

This fixes PR33670

Patch by: Dmitry Venikov 

Differential revision: https://reviews.llvm.org/D39834

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/opt-record.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=321090&r1=321089&r2=321090&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Dec 19 09:16:45 2017
@@ -4389,6 +4389,7 @@ void Clang::ConstructJob(Compilation &C,
 CmdArgs.push_back("-fapple-pragma-pack");
 
   if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_foptimization_record_file_EQ,
options::OPT_fno_save_optimization_record, false)) {
 CmdArgs.push_back("-opt-record-file");
 

Modified: cfe/trunk/test/Driver/opt-record.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opt-record.c?rev=321090&r1=321089&r2=321090&view=diff
==
--- cfe/trunk/test/Driver/opt-record.c (original)
+++ cfe/trunk/test/Driver/opt-record.c Tue Dec 19 09:16:45 2017
@@ -9,6 +9,8 @@
 // RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc 
-nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O 
-check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib 
%s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -S -o FOO -fsave-optimization-record 
-foptimization-record-file=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt %s 2>&1 | 
FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt 
-fno-save-optimization-record %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-FOPT-DISABLE
 
 // CHECK: "-cc1"
 // CHECK: "-opt-record-file" "FOO.opt.yaml"
@@ -20,3 +22,4 @@
 // CHECK-EQ: "-cc1"
 // CHECK-EQ: "-opt-record-file" "BAR.txt"
 
+// CHECK-FOPT-DISABLE-NOT: "-fno-save-optimization-record"


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


[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 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.

OK, this is pretty clean now! :-)




Comment at: clangd/ClangdServer.cpp:139
+  FileIdx(BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
+  Units(FileIdx
+? [this](const Context &Ctx, PathRef Path,

A comment explaining when this runs and what it does might be nice.

Also this doesn't seem like an ideal long-term solution: rebuilding an index 
can be slow (less the symbol extraction, and more the rebuilding of index data 
structures) and we may be able to index on less critical paths.
Probably also worth a comment.



Comment at: clangd/ClangdUnit.cpp:617
+  new CppFile(FileName, std::move(Command), StorePreamblesInMemory,
+  std::move(PCHs), std::move(ASTCallback)));
 }

CppFile doesn't need to pass the path, do you want `[FileName, 
ASTCallback](const Context &C, ParsedAST *AST) { ASTCallback(C, FileName, AST); 
}`



Comment at: clangd/ClangdUnitStore.h:28
 public:
+  /// \p ASTCallback is called when a file is parsed.
+  explicit CppFileCollection(ASTParsedCallback ASTCallback)

synchronously... maybe mention this will block diagnostics and doing expensive 
things would be bad



Comment at: clangd/tool/ClangdMain.cpp:98
+"use index built from symbols in opened files"),
+llvm::cl::init(false));
+

llvm::cl::Hidden,  if it's experimental?



Comment at: unittests/clangd/CodeCompleteTests.cpp:561
 
+TEST(CompletionTest, ASTIndexOneFile) {
+  MockFSProvider FS;

for this test, I don't see a clear sign that the results come from the index.
Is there a way we know this that you can point out?

For the second test we can tell because there's no #include, but it could use a 
comment



Comment at: unittests/clangd/CodeCompleteTests.cpp:584
+TEST(CompletionTest, ASTIndexMultiFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;

This repeated setup is a bit ugly but I'm planning to pull out a helper for 
this anyway.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289



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


[PATCH] D39834: [clang] -foptimization-record-file= should imply -fsave-optimization-record

2017-12-19 Thread Jonas Devlieghere via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC321090: [clang] -foptimization-record-file= should imply 
-fsave-optimization-record (authored by JDevlieghere, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D39834

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/opt-record.c


Index: test/Driver/opt-record.c
===
--- test/Driver/opt-record.c
+++ test/Driver/opt-record.c
@@ -9,6 +9,8 @@
 // RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc 
-nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O 
-check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib 
%s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -S -o FOO -fsave-optimization-record 
-foptimization-record-file=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt %s 2>&1 | 
FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt 
-fno-save-optimization-record %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-FOPT-DISABLE
 
 // CHECK: "-cc1"
 // CHECK: "-opt-record-file" "FOO.opt.yaml"
@@ -20,3 +22,4 @@
 // CHECK-EQ: "-cc1"
 // CHECK-EQ: "-opt-record-file" "BAR.txt"
 
+// CHECK-FOPT-DISABLE-NOT: "-fno-save-optimization-record"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4389,6 +4389,7 @@
 CmdArgs.push_back("-fapple-pragma-pack");
 
   if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_foptimization_record_file_EQ,
options::OPT_fno_save_optimization_record, false)) {
 CmdArgs.push_back("-opt-record-file");
 


Index: test/Driver/opt-record.c
===
--- test/Driver/opt-record.c
+++ test/Driver/opt-record.c
@@ -9,6 +9,8 @@
 // RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
 // RUN: %clang -### -S -o FOO -fsave-optimization-record -foptimization-record-file=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+// RUN: %clang -### -S -o FOO -foptimization-record-file=BAR.txt -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE
 
 // CHECK: "-cc1"
 // CHECK: "-opt-record-file" "FOO.opt.yaml"
@@ -20,3 +22,4 @@
 // CHECK-EQ: "-cc1"
 // CHECK-EQ: "-opt-record-file" "BAR.txt"
 
+// CHECK-FOPT-DISABLE-NOT: "-fno-save-optimization-record"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4389,6 +4389,7 @@
 CmdArgs.push_back("-fapple-pragma-pack");
 
   if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_foptimization_record_file_EQ,
options::OPT_fno_save_optimization_record, false)) {
 CmdArgs.push_back("-opt-record-file");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40939: [analyzer] Avoid element regions of void type.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 127548.
NoQ added a comment.

- Fix comments as suggested by Devin.
- Point out that arithmetic on void pointers is a GNU extension.


https://reviews.llvm.org/D40939

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer. Note that arithmetic on void pointers is a GCC 
extension.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2178,9 +2178,17 @@
 ProgramStateRef state = Node->getState();
 
 if (IsGLValueLike) {
-  SVal V = state->getLValue(A->getType(),
-  state->getSVal(Idx, LCtx),
-  state->getSVal(Base, LCtx));
+  QualType T = A->getType();
+
+  // One of the forbidden LValue types! We still need to have sensible
+  // symbolic locations to represent this stuff. Note that arithmetic on
+  // void pointers is a GCC extension.
+  if (T->isVoidType())
+T = getContext().CharTy;
+
+  SVal V = state->getLValue(T,
+state->getSVal(Idx, LCtx),
+state->getSVal(Base, LCtx));
   Bldr.generateNode(A, Node, state->BindExpr(A, LCtx, V), nullptr,
   ProgramPoint::PostLValueKind);
 } else if (IsVectorType) {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -961,7 +961,10 @@
   CXXThisRegion(const PointerType *thisPointerTy,
 const StackArgumentsSpaceRegion *sReg)
   : TypedValueRegion(sReg, CXXThisRegionKind),
-ThisPointerTy(thisPointerTy) {}
+ThisPointerTy(thisPointerTy) {
+assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
+   "Invalid region type!");
+  }
 
   static void ProfileRegion(llvm::FoldingSetNodeID &ID,
 const PointerType *PT,
@@ -1075,6 +1078,8 @@
 assert((!Idx.getAs() ||
 Idx.castAs().getValue().isSigned()) &&
"The index must be signed");
+assert(!elementType.isNull() && !elementType->isVoidType() &&
+   "Invalid region type!");
   }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer. Note that arithmetic on void pointers is a GCC extension.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2178,9 +2178,17 @@
 ProgramStateRef state = Node->getState();
 
 if (IsGLValueLike) {
-  SVal V = state->getLValue(A->getType(),
-  state->getSVal(Idx, LCtx),
-  state->getSVal(Base, LCtx));
+  QualType T = A->getType();
+
+  // One of the forbidden LValue types! We still need to have sensible
+  // symbolic locations to represent this stuff. Note that arithmetic on
+  // void pointers is a GCC extension.
+  if (T->isVoidType())
+T = getContext().CharTy;
+
+  SVal V = state->getLValue(T,
+state->getSVal(Idx, LCtx),
+state->getSVal(Base, LCtx));
   Bldr.gene

Re: [PATCH] D40939: [analyzer] Avoid element regions of void type.

2017-12-19 Thread Roman Lebedev via cfe-commits
On Tue, Dec 19, 2017 at 8:26 PM, Artem Dergachev via Phabricator via
cfe-commits  wrote:
> NoQ updated this revision to Diff 127548.
> NoQ added a comment.
>
> - Fix comments as suggested by Devin.
> - Point out that arithmetic on void pointers is a GNU extension.
>
>
> https://reviews.llvm.org/D40939
>
> Files:
>   include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
>   lib/StaticAnalyzer/Core/ExprEngine.cpp
>   lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
No tests?

> Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
> ===
> --- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
> +++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
> @@ -988,6 +988,12 @@
>  elementType = resultTy->getPointeeType();
>  }
>
> +// Represent arithmetic on void pointers as arithmetic on char pointers.
> +// It is fine when a TypedValueRegion of char value type represents
> +// a void pointer. Note that arithmetic on void pointers is a GCC 
> extension.
> +if (elementType->isVoidType())
> +  elementType = getContext().CharTy;
> +
>  if (Optional indexV = index.getAs()) {
>return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
> superR, 
> getContext()));
> Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
> ===
> --- lib/StaticAnalyzer/Core/ExprEngine.cpp
> +++ lib/StaticAnalyzer/Core/ExprEngine.cpp
> @@ -2178,9 +2178,17 @@
>  ProgramStateRef state = Node->getState();
>
>  if (IsGLValueLike) {
> -  SVal V = state->getLValue(A->getType(),
> -  state->getSVal(Idx, LCtx),
> -  state->getSVal(Base, LCtx));
> +  QualType T = A->getType();
> +
> +  // One of the forbidden LValue types! We still need to have sensible
> +  // symbolic locations to represent this stuff. Note that arithmetic on
> +  // void pointers is a GCC extension.
> +  if (T->isVoidType())
> +T = getContext().CharTy;
> +
> +  SVal V = state->getLValue(T,
> +state->getSVal(Idx, LCtx),
> +state->getSVal(Base, LCtx));
>Bldr.generateNode(A, Node, state->BindExpr(A, LCtx, V), nullptr,
>ProgramPoint::PostLValueKind);
>  } else if (IsVectorType) {
> Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
> ===
> --- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
> +++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
> @@ -961,7 +961,10 @@
>CXXThisRegion(const PointerType *thisPointerTy,
>  const StackArgumentsSpaceRegion *sReg)
>: TypedValueRegion(sReg, CXXThisRegionKind),
> -ThisPointerTy(thisPointerTy) {}
> +ThisPointerTy(thisPointerTy) {
> +assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
> +   "Invalid region type!");
> +  }
>
>static void ProfileRegion(llvm::FoldingSetNodeID &ID,
>  const PointerType *PT,
> @@ -1075,6 +1078,8 @@
>  assert((!Idx.getAs() ||
>  Idx.castAs().getValue().isSigned()) &&
> "The index must be signed");
> +assert(!elementType.isNull() && !elementType->isVoidType() &&
> +   "Invalid region type!");
>}
>
>static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,
>
>
>
> ___
> 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] D41394: [CodeGen] Support generation of TBAA info in the new format

2017-12-19 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

There are more tests that we will need to rewrite during migration to the new 
format than I think we could handle with a single patch. I was going to address 
them with separate patches. Or, I can rewrite some most basic of them as part 
of this patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D41394



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


[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 127554.
ioeric marked 4 inline comments as done.
ioeric added a comment.

- Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -558,6 +558,38 @@
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, ASTIndexMultiFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  Server
+  .addDocument(Context::empty(), getVirtualTestFilePath("foo.cpp"), R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  )cpp")
+  .wait();
+
+  auto File = getVirtualTestFilePath("bar.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XXX {}; void fo() {} }
+  void f() { ns::^ }
+  )cpp");
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  // "XYZ" and "foo" are not included in the file being completed but are still
+  // visible through the index.
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Has("XXX", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("fo", CompletionItemKind::Function));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -90,6 +90,13 @@
 "Trace internal events and timestamps in chrome://tracing JSON format"),
 llvm::cl::init(""), llvm::cl::Hidden);
 
+static llvm::cl::opt EnableIndexBasedCompletion(
+"enable-index-based-completion",
+llvm::cl::desc(
+"Enable index-based global code completion (experimental). Clangd will "
+"use index built from symbols in opened files"),
+llvm::cl::init(false), llvm::cl::Hidden);
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
@@ -180,7 +187,8 @@
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(Out, WorkerThreadsCount, StorePreamblesInMemory,
-CCOpts, ResourceDirRef, CompileCommandsDirPath);
+CCOpts, ResourceDirRef, CompileCommandsDirPath,
+EnableIndexBasedCompletion);
   constexpr int NoShutdownRequestErrorCode = 1;
   llvm::set_thread_name("clangd.main");
   return LSPServer.run(std::cin) ? 0 : NoShutdownRequestErrorCode;
Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -25,6 +25,11 @@
 /// Thread-safe mapping from FileNames to CppFile.
 class CppFileCollection {
 public:
+  /// \p ASTCallback is called when a file is parsed synchronously. This should
+  /// not be expensive since it blocks diagnostics.
+  explicit CppFileCollection(ASTParsedCallback ASTCallback)
+  : ASTCallback(std::move(ASTCallback)) {}
+
   std::shared_ptr
   getOrCreateFile(PathRef File, PathRef ResourceDir,
   GlobalCompilationDatabase &CDB, bool StorePreamblesInMemory,
@@ -38,7 +43,7 @@
   It = OpenedFiles
.try_emplace(File, CppFile::Create(File, std::move(Command),
   StorePreamblesInMemory,
-  std::move(PCHs)))
+  std::move(PCHs), ASTCallback))
.first;
 }
 return It->second;
@@ -85,6 +90,7 @@
 
   std::mutex Mutex;
   llvm::StringMap> OpenedFiles;
+  ASTParsedCallback ASTCallback;
 };
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdUnitStore.cpp
===
--- clangd/ClangdUnitStore.cpp
+++ clangd/ClangdUnitStore.cpp
@@ -41,13 +41,14 @@
 It = OpenedFiles
  .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
 StorePreamble

[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for the quick review!




Comment at: clangd/ClangdUnit.cpp:617
+  new CppFile(FileName, std::move(Command), StorePreamblesInMemory,
+  std::move(PCHs), std::move(ASTCallback)));
 }

sammccall wrote:
> CppFile doesn't need to pass the path, do you want `[FileName, 
> ASTCallback](const Context &C, ParsedAST *AST) { ASTCallback(C, FileName, 
> AST); }`
The downside is 1) we need to worry about the life time of FileName 2) we need 
another type for the new callback, so I am inclined to simply forward the 
callback.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289



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


[PATCH] D41289: [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE321092: [clangd] Build dynamic index and use it for code 
completion. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41289?vs=127554&id=127555#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41289

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -558,6 +558,38 @@
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, ASTIndexMultiFile) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*BuildDynamicSymbolIndex=*/true);
+
+  Server
+  .addDocument(Context::empty(), getVirtualTestFilePath("foo.cpp"), R"cpp(
+  namespace ns { class XYZ {}; void foo() {} }
+  )cpp")
+  .wait();
+
+  auto File = getVirtualTestFilePath("bar.cpp");
+  auto Test = parseTextMarker(R"cpp(
+  namespace ns { class XXX {}; void fo() {} }
+  void f() { ns::^ }
+  )cpp");
+  Server.addDocument(Context::empty(), File, Test.Text).wait();
+
+  auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ .get()
+ .second.Value;
+  // "XYZ" and "foo" are not included in the file being completed but are still
+  // visible through the index.
+  EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
+  EXPECT_THAT(Results.items, Has("XXX", CompletionItemKind::Class));
+  EXPECT_THAT(Results.items, Has("fo", CompletionItemKind::Function));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -134,8 +134,19 @@
FileSystemProvider &FSProvider,
unsigned AsyncThreadsCount,
bool StorePreamblesInMemory,
+   bool BuildDynamicSymbolIndex,
llvm::Optional ResourceDir)
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
+  FileIdx(BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
+  // Pass a callback into `Units` to extract symbols from a newly parsed
+  // file and rebuild the file index synchronously each time an AST is
+  // parsed.
+  // FIXME(ioeric): this can be slow and we may be able to index on less
+  // critical paths.
+  Units(FileIdx
+? [this](const Context &Ctx, PathRef Path,
+ ParsedAST *AST) { FileIdx->update(Ctx, Path, AST); }
+: ASTParsedCallback()),
   ResourceDir(ResourceDir ? ResourceDir->str() : getStandardResourceDir()),
   PCHs(std::make_shared()),
   StorePreamblesInMemory(StorePreamblesInMemory),
@@ -238,6 +249,8 @@
   Resources->getPossiblyStalePreamble();
   // Copy completion options for passing them to async task handler.
   auto CodeCompleteOpts = Opts;
+  if (FileIdx)
+CodeCompleteOpts.Index = FileIdx.get();
   // A task that will be run asynchronously.
   auto Task =
   // 'mutable' to reassign Preamble variable.
Index: clangd/ClangdUnitStore.cpp
===
--- clangd/ClangdUnitStore.cpp
+++ clangd/ClangdUnitStore.cpp
@@ -41,13 +41,14 @@
 It = OpenedFiles
  .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
 StorePreamblesInMemory,
-std::move(PCHs)))
+std::move(PCHs), ASTCallback))
  .first;
   } else if (!compileCommandsAreEqual(It->second->getCompileCommand(),
   NewCommand)) {
 Result.RemovedFile = std::move(It->second);
-It->second = CppFile::Create(File, std::move(NewCommand),
- StorePreamblesInMemory, std::move(PCHs));
+It->second =
+CppFile::Create(File, std::move(NewCommand), StorePreamblesInMemory,
+std::move(PCHs), ASTCallback);
   }
   Result.FileInCollection = It->second;
   return Result;
Index: clangd/ClangdLSPServer.h
===

[clang-tools-extra] r321092 - [clangd] Build dynamic index and use it for code completion.

2017-12-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Dec 19 10:00:37 2017
New Revision: 321092

URL: http://llvm.org/viewvc/llvm-project?rev=321092&view=rev
Log:
[clangd] Build dynamic index and use it for code completion.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=321092&r1=321091&r2=321092&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Dec 19 10:00:37 2017
@@ -282,10 +282,11 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  bool StorePreamblesInMemory,
  const clangd::CodeCompleteOptions &CCOpts,
  llvm::Optional ResourceDir,
- llvm::Optional CompileCommandsDir)
+ llvm::Optional CompileCommandsDir,
+ bool BuildDynamicSymbolIndex)
 : Out(Out), CDB(std::move(CompileCommandsDir)), CCOpts(CCOpts),
   Server(CDB, /*DiagConsumer=*/*this, FSProvider, AsyncThreadsCount,
- StorePreamblesInMemory, ResourceDir) {}
+ StorePreamblesInMemory, BuildDynamicSymbolIndex, ResourceDir) {}
 
 bool ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=321092&r1=321091&r2=321092&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Dec 19 10:00:37 2017
@@ -34,7 +34,8 @@ public:
   bool StorePreamblesInMemory,
   const clangd::CodeCompleteOptions &CCOpts,
   llvm::Optional ResourceDir,
-  llvm::Optional CompileCommandsDir);
+  llvm::Optional CompileCommandsDir,
+  bool BuildDynamicSymbolIndex);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be
   /// opened in binary mode. Output will be written using Out variable passed 
to

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=321092&r1=321091&r2=321092&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Dec 19 10:00:37 2017
@@ -134,8 +134,19 @@ ClangdServer::ClangdServer(GlobalCompila
FileSystemProvider &FSProvider,
unsigned AsyncThreadsCount,
bool StorePreamblesInMemory,
+   bool BuildDynamicSymbolIndex,
llvm::Optional ResourceDir)
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
+  FileIdx(BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
+  // Pass a callback into `Units` to extract symbols from a newly parsed
+  // file and rebuild the file index synchronously each time an AST is
+  // parsed.
+  // FIXME(ioeric): this can be slow and we may be able to index on less
+  // critical paths.
+  Units(FileIdx
+? [this](const Context &Ctx, PathRef Path,
+ ParsedAST *AST) { FileIdx->update(Ctx, Path, AST); }
+: ASTParsedCallback()),
   ResourceDir(ResourceDir ? ResourceDir->str() : getStandardResourceDir()),
   PCHs(std::make_shared()),
   StorePreamblesInMemory(StorePreamblesInMemory),
@@ -238,6 +249,8 @@ void ClangdServer::codeComplete(
   Resources->getPossiblyStalePreamble();
   // Copy completion options for passing them to async task handler.
   auto CodeCompleteOpts = Opts;
+  if (FileIdx)
+CodeCompleteOpts.Index = FileIdx.get();
   // A task that will be run asynchronously.
   auto Task =
   // 'mutable' to reassign Preamble variable.

Modified:

[PATCH] D40939: [analyzer] Avoid element regions of void type.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a subscriber: lebedev.ri.
NoQ added a comment.

@lebedev.ri wrote:

> No tests?


This patch adds an assertion => Multiple existing tests immediately starts 
crashing => This patch fixes the crashes with the new functionality.

So in my understanding the new assertion is all the tests we need. Old tests 
didn't pass when this assertion was enforced, now they do. If somebody breaks 
the newly added functionality, the regression will immediately show up on tests 
by hitting the assertion.

Additionally, i'm adding actual practical tests (of how the analyzer's behavior 
actually change) in a follow-up patch (https://reviews.llvm.org/D41250). So if 
we merge these two patches (if necessary), we'd have new stuff in the tests 
directory.

Or i could try to come up with actual tests for this patch, but i'm not sure 
it's worth it given the above.

Please correct me if my logic is flawed or contradicts existing policies.


https://reviews.llvm.org/D40939



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


[clang-tools-extra] r321094 - [clangd] Supress a log warning by putting it behind a condition.

2017-12-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Dec 19 10:10:32 2017
New Revision: 321094

URL: http://llvm.org/viewvc/llvm-project?rev=321094&view=rev
Log:
[clangd] Supress a log warning by putting it behind a condition.

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=321094&r1=321093&r2=321094&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Dec 19 10:10:32 2017
@@ -830,8 +830,9 @@ CompletionList codeComplete(const Contex
  FileName, Command, Preamble, Contents, Pos, 
std::move(VFS),
  std::move(PCHs));
   if (Opts.Index && CompletedName.SSInfo) {
-log(Ctx, "WARNING: Got completion results from sema for completion on "
- "qualified ID while symbol index is provided.");
+if (!Results.items.empty())
+  log(Ctx, "WARNING: Got completion results from sema for completion on "
+   "qualified ID while symbol index is provided.");
 Results.items.clear();
 completeWithIndex(Ctx, *Opts.Index, Contents, *CompletedName.SSInfo,
   CompletedName.Filter, &Results);


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


[PATCH] D41394: [CodeGen] Support generation of TBAA info in the new format

2017-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Rewriting some of the most basic tests would be fine.  Please either use new 
FileCheck lines or clone the existing tests, since we don't really know how 
long this transition will last.


Repository:
  rL LLVM

https://reviews.llvm.org/D41394



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


[PATCH] D41250: [analyzer] Model implied cast around operator new().

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 127549.
NoQ added a comment.

Rebase.

> I also noticed that `evalCast` from `void *` to `T *` is uncomfortable to use 
> because sometimes it transforms `&SymRegion{$x}` into `&element{T, 0S32b, 
> SymRegion{$x}}` even when `$x` is already of type `T *`. The form 
> `&SymRegion{$x}` seems to be the canonical form of this symbolic pointer 
> value in the rest of the analyzer, so i decided to change `evalCast` to 
> preserve it.

Suddenly it turns out that this is not needed anymore. I'm struggling quite a 
bit to get the casts right, and still failing to identify the actual system 
we're trying to follow when representing pointer casts. I'd love to get to the 
bottom of it eventually.


https://reviews.llvm.org/D41250

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-inlined.cpp

Index: test/Analysis/new-ctor-inlined.cpp
===
--- test/Analysis/new-ctor-inlined.cpp
+++ test/Analysis/new-ctor-inlined.cpp
@@ -27,3 +27,18 @@
   // Check that bindings are correct (and also not dying).
   clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
 }
+
+void checkNewPOD() {
+  int *i = new int;
+  clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}
+  int *j = new int();
+  clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}
+  int *k = new int(5);
+  clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
+}
+
+void checkTrivialCopy() {
+  S s;
+  S *t = new S(s); // no-crash
+  clang_analyzer_eval(t->x == 1); // expected-warning{{TRUE}}
+}
Index: test/Analysis/new-ctor-conservative.cpp
===
--- test/Analysis/new-ctor-conservative.cpp
+++ test/Analysis/new-ctor-conservative.cpp
@@ -12,3 +12,12 @@
   S *s = new S;
   clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
 }
+
+void checkNewPOD() {
+  int *i = new int;
+  clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}
+  int *j = new int();
+  clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}
+  int *k = new int(5);
+  clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -277,11 +277,12 @@
   state = state->BindExpr(CCE, callerCtx, ThisV);
 }
 
-if (isa(CE)) {
+if (const auto *CNE = dyn_cast(CE)) {
   // We are currently evaluating a CXXNewAllocator CFGElement. It takes a
   // while to reach the actual CXXNewExpr element from here, so keep the
   // region for later use.
-  state = pushCXXNewAllocatorValue(state, state->getSVal(CE, callerCtx));
+  state = pushCXXNewAllocatorValue(state, state->getSVal(CE, callerCtx),
+   CNE->getType());
 }
   }
 
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -463,7 +463,8 @@
   for (auto I : DstPostCall) {
 ProgramStateRef State = I->getState();
 ValueBldr.generateNode(
-CNE, I, pushCXXNewAllocatorValue(State, State->getSVal(CNE, LCtx)));
+CNE, I, pushCXXNewAllocatorValue(State, State->getSVal(CNE, LCtx),
+ CNE->getType()));
   }
 
   getCheckerManager().runCheckersForPostCall(Dst, DstPostValue,
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -314,7 +314,12 @@
 }
 
 ProgramStateRef ExprEngine::pushCXXNewAllocatorValue(ProgramStateRef State,
- SVal V) {
+ SVal V, QualType T) {
+  // Because operator new returns void *,  we need to perform the cast here,
+  // which is implied by the semantics of operator new.
+  V = svalBuilder.evalCast(V, T,
+   getContext().getPointerType(getContext().VoidTy));
+
   return State->add(V);
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -659,8 +659,10 @@
   /// Store the region returned by operator new() so that the constructor
   /// that follows it knew what location to initialize. The value should be
   /// cleared once the r

[PATCH] D41266: [analyzer] With c++-allocator-inlining, fix memory space for operator new pointers.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 127560.
NoQ added a comment.

Rebase.

Remove the redundant cast that is done in `c++-allocator-inlining` mode when 
modeling array new. After rebase it started causing two identical element 
regions top appear on top of each other.


https://reviews.llvm.org/D41266

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-null.cpp

Index: test/Analysis/new-ctor-null.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-null.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *operator new(size_t size) throw() {
+  return nullptr;
+}
+void *operator new[](size_t size) throw() {
+  return nullptr;
+}
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void testArrays() {
+  S *s = new S[10]; // no-crash
+  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+}
Index: test/Analysis/new-ctor-conservative.cpp
===
--- test/Analysis/new-ctor-conservative.cpp
+++ test/Analysis/new-ctor-conservative.cpp
@@ -21,3 +21,9 @@
   int *k = new int(5);
   clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
 }
+
+void checkNewArray() {
+  S *s = new S[10];
+  // FIXME: Should be true once we inline array constructors.
+  clang_analyzer_eval(s[0].x == 1); // expected-warning{{UNKNOWN}}
+}
Index: test/Analysis/NewDelete-checker-test.cpp
===
--- test/Analysis/NewDelete-checker-test.cpp
+++ test/Analysis/NewDelete-checker-test.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -fblocks -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -fblocks -analyzer-config c++-allocator-inlining=true -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -fblocks -analyzer-config c++-allocator-inlining=true -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
 typedef __typeof__(sizeof(int)) size_t;
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -562,7 +562,19 @@
   QualType ResultTy = Call.getResultType();
   SValBuilder &SVB = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
-  SVal R = SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+
+  // See if we need to conjure a heap pointer instead of
+  // a regular unknown pointer.
+  bool IsHeapPointer = false;
+  if (const auto *CNE = dyn_cast(E))
+if (isStandardGlobalOperatorNewFunction(CNE)) {
+  // FIXME: Delegate this to evalCall in MallocChecker?
+  IsHeapPointer = true;
+}
+
+  SVal R = IsHeapPointer
+   ? SVB.getConjuredHeapSymbolVal(E, LCtx, Count)
+   : SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
   return State->BindExpr(E, LCtx, R);
 }
 
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -453,8 +453,10 @@
 
   ExplodedNodeSet DstPostCall;
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
-  for (auto I : DstPreCall)
+  for (auto I : DstPreCall) {
+// FIXME: Provide evalCall for checkers?
 defaultEvalCall(CallBldr, I, *Call);
+  }
 
   // Store return value of operator new() for future use, until the actual
   // CXXNewExpr gets processed.
@@ -471,6 +473,22 @@
  *Call, *this);
 }
 
+bool ExprEngine::isStandardGlobalOperatorNewFunction(const CXXNewExpr *CNE) {
+  const FunctionDecl *FD = CNE->getOperatorNew();
+  if (FD && !isa(FD) && !FD->isVariadic()) {
+if (FD->getNumParams() == 2) {
+  QualType T = FD->getParamDecl(1)->getType();
+  if (const IdentifierInfo *II = T.getBaseTypeIdentifier()) {
+// NoThrow placement new behaves as a standard new.
+return II->getName().equals("nothrow_t");
+  }
+} else {
+  // Placement forms are considered non-standard.
+  return FD->getNumParams() == 1;
+}
+  }
+  return false;
+}
 
 void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
Ex

[PATCH] D39050: Add index-while-building support to Clang

2017-12-19 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes updated this revision to Diff 127568.
nathawes added a comment.

Fix out of data header comment in FileIndexData.h


https://reviews.llvm.org/D39050

Files:
  include/clang/Basic/AllDiagnostics.h
  include/clang/Basic/CMakeLists.txt
  include/clang/Basic/Diagnostic.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticIDs.h
  include/clang/Basic/DiagnosticIndexKinds.td
  include/clang/Driver/Job.h
  include/clang/Driver/Options.td
  include/clang/Frontend/CompilerInstance.h
  include/clang/Frontend/FrontendOptions.h
  include/clang/Index/DeclOccurrence.h
  include/clang/Index/IndexDataConsumer.h
  include/clang/Index/IndexDiagnostic.h
  include/clang/Index/IndexUnitDataConsumer.h
  include/clang/Index/IndexingAction.h
  include/clang/module.modulemap
  lib/Basic/DiagnosticIDs.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/FrontendTool/CMakeLists.txt
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  lib/Index/CMakeLists.txt
  lib/Index/FileIndexData.cpp
  lib/Index/FileIndexData.h
  lib/Index/IndexingAction.cpp
  lib/Index/IndexingContext.cpp
  lib/Index/IndexingContext.h
  test/Index/Store/assembly-invocation.c
  tools/c-index-test/core_main.cpp
  tools/diagtool/DiagnosticNames.cpp
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -463,12 +463,12 @@
 private:
   bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef Relations,
-   FileID FID, unsigned Offset,
+   FileID FID, unsigned Offset, bool IsInSystemFile,
ASTNodeInfo ASTNode) override;
 
   bool handleModuleOccurence(const ImportDecl *ImportD,
- index::SymbolRoleSet Roles,
- FileID FID, unsigned Offset) override;
+ index::SymbolRoleSet Roles, FileID FID,
+ unsigned Offset, bool IsInSystemFile) override;
 
   void finish() override;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -150,11 +150,9 @@
 };
 }
 
-bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
-  SymbolRoleSet Roles,
- ArrayRef Relations,
-  FileID FID, unsigned Offset,
-  ASTNodeInfo ASTNode) {
+bool CXIndexDataConsumer::handleDeclOccurence(
+const Decl *D, SymbolRoleSet Roles, ArrayRef Relations,
+FileID FID, unsigned Offset, bool IsInSystemFile, ASTNodeInfo ASTNode) {
   SourceLocation Loc = getASTContext().getSourceManager()
   .getLocForStartOfFile(FID).getLocWithOffset(Offset);
 
@@ -219,9 +217,9 @@
 }
 
 bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
-SymbolRoleSet Roles,
-FileID FID,
-unsigned Offset) {
+SymbolRoleSet Roles, FileID FID,
+unsigned Offset,
+bool IsInSystemFile) {
   IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
   return !shouldAbort();
 }
Index: tools/diagtool/DiagnosticNames.cpp
===
--- tools/diagtool/DiagnosticNames.cpp
+++ tools/diagtool/DiagnosticNames.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
+#include "clang/Basic/DiagnosticIndexKinds.inc"
 #undef DIAG
 };
 
Index: tools/c-index-test/core_main.cpp
===
--- tools/c-index-test/core_main.cpp
+++ tools/c-index-test/core_main.cpp
@@ -87,8 +87,8 @@
   }
 
   bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
-   ArrayRef Relations,
-   FileID FID, unsigned Offset,
+   ArrayRef Relations, FileID FID,
+   unsigned Offset, bool IsInSystemFile,
ASTNodeInfo ASTNode) override {
 ASTContext &Ctx = D->getASTContext();
 SourceManager &SM = Ctx.getSourceManager();
@@ -124,7 +124,8 @@
   }
 
   bool handleMod

[PATCH] D41387: Remove llvm::MemoryBuffer const_casts

2017-12-19 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.

Seems good


Repository:
  rC Clang

https://reviews.llvm.org/D41387



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


[PATCH] D41405: Fix an assertion failure regression in isDesignatorAtObjectEnd for __builtin_object_size with incomplete array type in struct

2017-12-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: vsapsai, rsmith, george.burgess.iv.

The commit r316245 introduced a regression that causes an assertion failure 
when Clang tries to cast an `IncompleteArrayType` to a `PointerType` when 
evaluating __builtin_object_size in this sample:

  typedef struct {
char string[512];
  } NestedArrayStruct;
  
  typedef struct {
  int x;
  NestedArrayStruct session[];
  } IncompleteArrayStruct;
  
  void func(IncompleteArrayStruct* p) {
 __builtin___strlcpy_chk (p->session[0].string, "ab", 2, 
__builtin_object_size(p->session[0].string, 1));
  }

Interestingly enough gcc seems to produce a different output for the above code 
(when `1` is the last parameter to `__builtin_object_size`). It evaluates 
`__builtin_object_size` to 512 instead of -1 like Clang:

https://godbolt.org/g/vD9F9T

I'm still not sure what's the right behavior after reading GCC's description of 
__builtin_object_size 
(https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html). Maybe someone 
who's more familiar with this builtin could point to the cause of this 
discrepancy.

rdar://36094951


Repository:
  rC Clang

https://reviews.llvm.org/D41405

Files:
  lib/AST/ExprConstant.cpp
  test/Sema/builtin-object-size.c


Index: test/Sema/builtin-object-size.c
===
--- test/Sema/builtin-object-size.c
+++ test/Sema/builtin-object-size.c
@@ -91,3 +91,16 @@
 
   return n;
 }
+
+typedef struct  {
+  char string[512];
+} NestedArrayStruct;
+
+typedef struct  {
+int x;
+NestedArrayStruct  session[];
+} IncompleteArrayStruct;
+
+void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct* p) {
+   __builtin___strlcpy_chk (p->session[0].string, "ab", 2, 
__builtin_object_size(p->session[0].string, 1));
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7419,7 +7419,10 @@
 // If we don't know the array bound, conservatively assume we're looking at
 // the final array element.
 ++I;
-BaseType = BaseType->castAs()->getPointeeType();
+if (BaseType->isIncompleteArrayType())
+  BaseType = Ctx.getAsArrayType(BaseType)->getElementType();
+else
+  BaseType = BaseType->castAs()->getPointeeType();
   }
 
   for (unsigned E = LVal.Designator.Entries.size(); I != E; ++I) {


Index: test/Sema/builtin-object-size.c
===
--- test/Sema/builtin-object-size.c
+++ test/Sema/builtin-object-size.c
@@ -91,3 +91,16 @@
 
   return n;
 }
+
+typedef struct 	 {
+  char string[512];
+} NestedArrayStruct;
+
+typedef struct 	 {
+int x;
+NestedArrayStruct	session[];
+} IncompleteArrayStruct;
+
+void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct* p) {
+   __builtin___strlcpy_chk (p->session[0].string, "ab", 2, __builtin_object_size(p->session[0].string, 1));
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7419,7 +7419,10 @@
 // If we don't know the array bound, conservatively assume we're looking at
 // the final array element.
 ++I;
-BaseType = BaseType->castAs()->getPointeeType();
+if (BaseType->isIncompleteArrayType())
+  BaseType = Ctx.getAsArrayType(BaseType)->getElementType();
+else
+  BaseType = BaseType->castAs()->getPointeeType();
   }
 
   for (unsigned E = LVal.Designator.Entries.size(); I != E; ++I) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41405: Fix an assertion failure regression in isDesignatorAtObjectEnd for __builtin_object_size with incomplete array type in struct

2017-12-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Note that even though there is a discrepancy between GCC and Clang, this patch 
does not change Clang's behavior in this instance as it emitted -1 previously 
as well


Repository:
  rC Clang

https://reviews.llvm.org/D41405



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


[PATCH] D39462: [Sema] Implement -Wmaybe-tautological-constant-compare for when the tautologicalness is data model dependent

2017-12-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

FWIW we've already rolled Clang that contains `-Wtautological-constant-compare` 
to our codebase and we had to set `-Wno-tautological-constant-compare` globally 
because we were getting bogus warnings in many places, similarly to 
https://reviews.llvm.org/D41368. If that warning ships as part of Clang 6, it's 
going to be be a major pain for many users so we really need some solution.


Repository:
  rL LLVM

https://reviews.llvm.org/D39462



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


[PATCH] D40998: [driver][darwin] Take the OS version specified in "-target" as the target OS instead of inferring it from SDK / environment

2017-12-19 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC321099: [driver][darwin] Take the OS version specified in 
"-target" as the target (authored by arphaman, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D40998

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c
  test/Driver/objc-weak.m
  test/Driver/pic.c
  test/Driver/unavailable_aligned_allocation.cpp

Index: test/Driver/objc-weak.m
===
--- test/Driver/objc-weak.m
+++ test/Driver/objc-weak.m
@@ -1,27 +1,27 @@
 // Check miscellaneous Objective-C options.
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-arc -fobjc-weak 2>&1 | FileCheck %s --check-prefix ARC-WEAK
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fno-objc-weak -fobjc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-WEAK
+// RUN: %clang -target x86_64-apple-macosx10.7 -S -### %s -fobjc-arc -fobjc-weak 2>&1 | FileCheck %s --check-prefix ARC-WEAK
+// RUN: %clang -target x86_64-apple-macosx10.7 -S -### %s -fno-objc-weak -fobjc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-WEAK
 // ARC-WEAK: -fobjc-arc
 // ARC-WEAK: -fobjc-weak
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-arc -fno-objc-weak 2>&1 | FileCheck %s --check-prefix ARC-NO-WEAK
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-weak -fno-objc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-NO-WEAK
+// RUN: %clang -target x86_64-apple-macos10.7 -S -### %s -fobjc-arc -fno-objc-weak 2>&1 | FileCheck %s --check-prefix ARC-NO-WEAK
+// RUN: %clang -target x86_64-apple-macos10.7 -S -### %s -fobjc-weak -fno-objc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-NO-WEAK
 // ARC-NO-WEAK: -fobjc-arc
 // ARC-NO-WEAK: -fno-objc-weak
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.5 -S -### %s -fobjc-arc -fobjc-weak 2>&1 | FileCheck %s --check-prefix ARC-WEAK-NOTSUPPORTED
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.5 -S -### %s -fno-objc-weak -fobjc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-WEAK-NOTSUPPORTED
+// RUN: %clang -target x86_64-apple-macosx10.5 -S -### %s -fobjc-arc -fobjc-weak 2>&1 | FileCheck %s --check-prefix ARC-WEAK-NOTSUPPORTED
+// RUN: %clang -target x86_64-apple-macosx10.5 -S -### %s -fno-objc-weak -fobjc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-WEAK-NOTSUPPORTED
 // ARC-WEAK-NOTSUPPORTED: error: -fobjc-weak is not supported on the current deployment target
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fno-objc-weak -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK
+// RUN: %clang -target x86_64-apple-macos10.7 -S -### %s -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK
+// RUN: %clang -target x86_64-apple-macos10.7 -S -### %s -fno-objc-weak -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK
 // MRC-WEAK: -fobjc-weak
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fno-objc-weak 2>&1 | FileCheck %s --check-prefix MRC-NO-WEAK
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-weak -fno-objc-weak 2>&1 | FileCheck %s --check-prefix MRC-NO-WEAK
+// RUN: %clang -target x86_64-apple-macosx10.7 -S -### %s -fno-objc-weak 2>&1 | FileCheck %s --check-prefix MRC-NO-WEAK
+// RUN: %clang -target x86_64-apple-macosx10.7 -S -### %s -fobjc-weak -fno-objc-weak 2>&1 | FileCheck %s --check-prefix MRC-NO-WEAK
 // MRC-NO-WEAK: -fno-objc-weak
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.5 -S -### %s -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK-NOTSUPPORTED
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.5 -S -### %s -fno-objc-weak -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK-NOTSUPPORTED
+// RUN: %clang -target x86_64-apple-macosx10.5 -S -### %s -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK-NOTSUPPORTED
+// RUN: %clang -target x86_64-apple-macosx10.5 -S -### %s -fno-objc-weak -fobjc-weak 2>&1 | FileCheck %s --check-prefix MRC-WEAK-NOTSUPPORTED
 // MRC-WEAK-NOTSUPPORTED: error: -fobjc-weak is not supported on the current deployment target
Index: test/Driver/pic.c
===
--- test/Driver/pic.c
+++ test/Driver/pic.c
@@ -221,19 +221,19 @@
 //
 // Checks for ARM+Apple+IOS including -fapple-kext, -mkernel, and iphoneos
 // version boundaries.
-// RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target armv7-apple-

r321099 - [driver][darwin] Take the OS version specified in "-target" as the target

2017-12-19 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Dec 19 11:05:04 2017
New Revision: 321099

URL: http://llvm.org/viewvc/llvm-project?rev=321099&view=rev
Log:
[driver][darwin] Take the OS version specified in "-target" as the target
OS instead of inferring it from SDK / environment

The OS version is specified in -target should be used instead of the one in an
environment variable / SDK name.

rdar://35813850

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/test/Driver/darwin-version.c
cfe/trunk/test/Driver/objc-weak.m
cfe/trunk/test/Driver/pic.c
cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=321099&r1=321098&r2=321099&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Tue Dec 19 11:05:04 2017
@@ -1233,6 +1233,10 @@ struct DarwinPlatform {
 llvm_unreachable("Unsupported Darwin Source Kind");
   }
 
+  static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
+ StringRef OSVersion, Arg *A) {
+return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+  }
   static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
 return DarwinPlatform(OSVersionArg, Platform, A);
@@ -1250,33 +1254,32 @@ struct DarwinPlatform {
   }
   static DarwinPlatform createFromArch(llvm::Triple::OSType OS,
StringRef Value) {
-DarwinPlatformKind Platform;
+return DarwinPlatform(InferredFromArch, getPlatformFromOS(OS), Value);
+  }
+
+private:
+  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, Arg *Argument)
+  : Kind(Kind), Platform(Platform), Argument(Argument) {}
+  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, StringRef Value,
+ Arg *Argument = nullptr)
+  : Kind(Kind), Platform(Platform), OSVersion(Value), Argument(Argument) {}
+
+  static DarwinPlatformKind getPlatformFromOS(llvm::Triple::OSType OS) {
 switch (OS) {
 case llvm::Triple::Darwin:
 case llvm::Triple::MacOSX:
-  Platform = DarwinPlatformKind::MacOS;
-  break;
+  return DarwinPlatformKind::MacOS;
 case llvm::Triple::IOS:
-  Platform = DarwinPlatformKind::IPhoneOS;
-  break;
+  return DarwinPlatformKind::IPhoneOS;
 case llvm::Triple::TvOS:
-  Platform = DarwinPlatformKind::TvOS;
-  break;
+  return DarwinPlatformKind::TvOS;
 case llvm::Triple::WatchOS:
-  Platform = DarwinPlatformKind::WatchOS;
-  break;
+  return DarwinPlatformKind::WatchOS;
 default:
   llvm_unreachable("Unable to infer Darwin variant");
 }
-return DarwinPlatform(InferredFromArch, Platform, Value);
   }
 
-private:
-  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, Arg *Argument)
-  : Kind(Kind), Platform(Platform), Argument(Argument) {}
-  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, StringRef Value)
-  : Kind(Kind), Platform(Platform), OSVersion(Value), Argument(nullptr) {}
-
   SourceKind Kind;
   DarwinPlatformKind Platform;
   std::string OSVersion;
@@ -1449,20 +1452,15 @@ inferDeploymentTargetFromArch(DerivedArg
   const Driver &TheDriver) {
   llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
 
-  // Set the OSTy based on -target if -arch isn't present.
-  if (Args.hasArg(options::OPT_target) && !Args.hasArg(options::OPT_arch)) {
-OSTy = Triple.getOS();
-  } else {
-StringRef MachOArchName = Toolchain.getMachOArchName(Args);
-if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
-MachOArchName == "arm64")
-  OSTy = llvm::Triple::IOS;
-else if (MachOArchName == "armv7k")
-  OSTy = llvm::Triple::WatchOS;
-else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" &&
- MachOArchName != "armv7em")
-  OSTy = llvm::Triple::MacOSX;
-  }
+  StringRef MachOArchName = Toolchain.getMachOArchName(Args);
+  if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
+  MachOArchName == "arm64")
+OSTy = llvm::Triple::IOS;
+  else if (MachOArchName == "armv7k")
+OSTy = llvm::Triple::WatchOS;
+  else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" &&
+   MachOArchName != "armv7em")
+OSTy = llvm::Triple::MacOSX;
 
   if (OSTy == llvm::Triple::UnknownOS)
 return None;
@@ -1470,6 +1468,19 @@ inferDeploymentTargetFromArch(DerivedArg
 getOSVersion(OSTy, Triple, TheDriver));
 }
 
+/// Returns the deployment target that's specified using the -target option.
+Optional getDeploymentTargetFromTargetArg(
+DerivedArgList &Args, const 

[PATCH] D41406: [analyzer] Add a new checker callback, check::NewAllocator.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added a subscriber: rnkovacs.

This patch is roughly based on the discussion we've had in 
http://lists.llvm.org/pipermail/cfe-dev/2017-December/056314.html about how our 
support for C++ operator new() should provide useful callbacks to the checkers. 
As in, this patch tries to do a minimal necessary thing while avoiding all 
decisions that we didn't have a consensus over.

This patch also absorbs https://reviews.llvm.org/D36708.

In the discussion, we've been mentioning PreAllocator/PostAllocator callbacks. 
However, we already sort of have them: they are PreCall/PostCall callbacks for 
the allocator call, which are readily available in the `c++-allocator-inlining` 
mode.

This patch also causes no change in the behavior of the pre/post `CXXNewExpr` 
callbacks. They remain broken in the `c++-allocator-inlining` mode for now.

Missing in the current system of callbacks, however, is a callback that would 
be called before construction while providing the //casted// return value of 
operator new (in the sense of https://reviews.llvm.org/D41250: operator new 
returns `void *`, but we need to have `C *`). The user can subscribe on the 
allocator's `PostCall` and perform the cast manually, but that's an unpleasant 
thing to do. So it sounds like a good idea to provide a callback that would 
contain the relevant information.

A similar "Pre" callback doesn't seem necessary - there's not much additional 
information we can provide compared to PreCall.

In this patch, I add the callback (with a lot of code that is the usual 
boilerplate around the callback, though there's still a questionable TODO in 
`CheckNewAllocatorContext::runChecker()`) and modify MallocChecker to make use 
of it when `c++-allocator-inlining` mode is turned on. Specifically:

- If the allocator (operator new) call is evaluated conservatively, 
`checkNewAllocator()` provides the return value of the allocator that is 
semantically equivalent to the value in `checkPostStmt()` that 
we've been using earlier. Without the cast, the value is different and the 
checker crashes.
- If the allocator call is inlined, the checker does not treat it as an 
allocator, but instead as a simple inlined function. That is, it does not start 
tracking the return value here, and in particular avoids crashes. This policy 
has already been there because previously we could inline the operator when it 
was written without operator syntax - see tests in 
`test/Analysis/NewDelete-custom.cpp`. Whether this policy was correct or not is 
a matter of discussion. For now it means that in `c++-allocator-inlining` mode 
we'd have new negatives (i.e. lost positives) on code that uses custom 
allocators which do not boil down to simple malloc.

The `std::nothrow_t` tests in `NewDelete-custom.cpp` are affected in a 
surprising manner. I'd fix them in a follow-up commit.


https://reviews.llvm.org/D41406

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/NewDelete-custom.cpp
  test/Analysis/new-ctor-malloc.cpp

Index: test/Analysis/new-ctor-malloc.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-malloc.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *malloc(size_t size);
+
+void *operator new(size_t size) throw() {
+  void *x = malloc(size);
+  if (!x)
+return nullptr;
+  return x;
+}
+
+void checkNewAndConstructorInlining() {
+  int *s = new int;
+} // expected-warning {{Potential leak of memory pointed to by 's'}}
Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DALLOCATOR_INLINING=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=

Re: r313729 - Implement C++ [basic.link]p8.

2017-12-19 Thread Alex L via cfe-commits
Hi Richard,

This commit has caused a new regression in Clang which causes an assertion
failure for extern "C" function definitions whose return type is a pointer
to a record. I filed https://bugs.llvm.org/show_bug.cgi?id=35697 which
contains the minimized test case for this issue. Do you mind taking a look
at it?

Cheers,
Alex

On 20 September 2017 at 00:22, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Wed Sep 20 00:22:00 2017
> New Revision: 313729
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313729&view=rev
> Log:
> Implement C++ [basic.link]p8.
>
> If a function or variable has a type with no linkage (and is not extern
> "C"),
> any use of it requires a definition within the same translation unit; the
> idea
> is that it is not possible to define the entity elsewhere, so any such use
> is
> necessarily an error.
>
> There is an exception, though: some types formally have no linkage but
> nonetheless can be referenced from other translation units (for example,
> this
> happens to anonymous structures defined within inline functions). For
> entities
> with those types, we suppress the diagnostic except under -pedantic.
>
> Added:
> cfe/trunk/test/CXX/basic/basic.link/p8.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/include/clang/Sema/SemaInternal.h
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/Sema/Sema.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/Analysis/malloc.mm
> cfe/trunk/test/Analysis/reference.cpp
> cfe/trunk/test/CodeGenCXX/debug-info-method.cpp
> cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
> cfe/trunk/test/CodeGenCXX/mangle.cpp
> cfe/trunk/test/PCH/cxx11-lambdas.mm
> cfe/trunk/test/SemaCXX/warn-unreachable.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=313729&r1=313728&r2=313729&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 20
> 00:22:00 2017
> @@ -4707,6 +4707,14 @@ def note_deleted_assign_field : Note<
>  def warn_undefined_internal : Warning<
>"%select{function|variable}0 %q1 has internal linkage but is not
> defined">,
>InGroup>;
> +def err_undefined_internal_type : Error<
> +  "%select{function|variable}0 %q1 is used but not defined in this "
> +  "translation unit, and cannot be defined in any other translation unit "
> +  "because its type does not have linkage">;
> +def ext_undefined_internal_type : Extension<
> +  "ISO C++ requires a definition in this translation unit for "
> +  "%select{function|variable}0 %q1 because its type does not have
> linkage">,
> +  InGroup>;
>  def warn_undefined_inline : Warning<"inline function %q0 is not defined">,
>InGroup>;
>  def err_undefined_inline_var : Error<"inline variable %q0 is not
> defined">;
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=313729&r1=313728&r2=313729&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Wed Sep 20 00:22:00 2017
> @@ -1086,6 +1086,11 @@ public:
>/// definition in this translation unit.
>llvm::MapVector UndefinedButUsed;
>
> +  /// Determine if VD, which must be a variable or function, is an
> external
> +  /// symbol that nonetheless can't be referenced from outside this
> translation
> +  /// unit because its type has no linkage and it's not extern "C".
> +  bool isExternalWithNoLinkageType(ValueDecl *VD);
> +
>/// Obtain a sorted list of functions that are undefined but ODR-used.
>void getUndefinedButUsed(
>SmallVectorImpl >
> &Undefined);
>
> Modified: cfe/trunk/include/clang/Sema/SemaInternal.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/SemaInternal.h?rev=313729&r1=313728&r2=313729&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/SemaInternal.h (original)
> +++ cfe/trunk/include/clang/Sema/SemaInternal.h Wed Sep 20 00:22:00 2017
> @@ -73,7 +73,8 @@ inline void MarkVarDeclODRUsed(VarDecl *
>// Keep track of used but undefined variables.
>// FIXME: We shouldn't suppress this warning for static data members.
>if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
> -  (!Var->isExternallyVisible() || Var->isInline()) &&
> +  (!Var->isExternallyVisible() || Var->isInline() ||
> +   SemaRef.isExternalWithNoLinkageType(Var)) &&
>!(Var->isStaticDataMember() && Var->hasI

[PATCH] D39462: [Sema] Implement -Wmaybe-tautological-constant-compare for when the tautologicalness is data model dependent

2017-12-19 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

In https://reviews.llvm.org/D39462#959822, @phosek wrote:

> FWIW we've already rolled Clang that contains 
> `-Wtautological-constant-compare` to our codebase and we had to set 
> `-Wno-tautological-constant-compare` globally because we were getting bogus 
> warnings in many places, similarly to https://reviews.llvm.org/D41368. If 
> that warning ships as part of Clang 6, it's going to be be a major pain for 
> many users so we really need some solution.


Let's escalate this discussion to llvm-dev, then?  If we don't do anything 
soon, it will ship w/clang 6.


Repository:
  rL LLVM

https://reviews.llvm.org/D39462



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


[PATCH] D41406: [analyzer] Add a new checker callback, check::NewAllocator.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 127579.
NoQ added a comment.

- Actually call the new callback when the allocator call is inlined.
- Update checker documentation :)


https://reviews.llvm.org/D41406

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/NewDelete-custom.cpp
  test/Analysis/new-ctor-malloc.cpp

Index: test/Analysis/new-ctor-malloc.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-malloc.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *malloc(size_t size);
+
+void *operator new(size_t size) throw() {
+  void *x = malloc(size);
+  if (!x)
+return nullptr;
+  return x;
+}
+
+void checkNewAndConstructorInlining() {
+  int *s = new int;
+} // expected-warning {{Potential leak of memory pointed to by 's'}}
Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DALLOCATOR_INLINING=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#ifndef LEAKS
+#if !LEAKS
 // expected-no-diagnostics
 #endif
 
@@ -26,7 +28,7 @@
 
   C *c3 = ::new C;
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'c3'}}
 #endif
 
@@ -37,7 +39,7 @@
 void testNewExprArray() {
   int *p = new int[0];
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
@@ -50,30 +52,30 @@
 void testNewExpr() {
   int *p = new int;
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
   void *p = operator new(0, std::nothrow);
 }
-#ifdef LEAKS
+#if LEAKS
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#ifdef LEAKS
+#if LEAKS
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
 //- Custom placement operators
 void testOpNewPlacement() {
   void *p = operator new(0, 0.1); // no warn
-} 
+}
 
 void testNewExprPlacement() {
   int *p = new(0.1) int; // no warn
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -339,10 +339,21 @@
 CallEventRef<> UpdatedCall = Call.cloneWithState(CEEState);
 
 ExplodedNodeSet DstPostCall;
-getCheckerManager().runCheckersForPostCall(DstPostCall, CEENode,
-   *UpdatedCall, *this,
-   /*WasInlined=*/true);
-
+if (const CXXNewExpr *CNE = dyn_cast_or_null(CE)) {
+  ExplodedNodeSet DstPostPostCallCallback;
+  getCheckerManager().runCheckersForPostCall(DstPostPostCallCallback,
+ CEENode, *UpdatedCall, *this,
+ /*WasInlined=*/true);
+  for (auto I : DstPostPostCallCallback) {
+getCheckerManager().runCheckersForNewAllocator(
+CNE, peekCXXNewAllocatorValue(I->getState()), DstPostCall, I, *this,
+/*WasInlined=*/true);
+  }
+} else {
+  getCheckerManager().runCheckersForPostCall(DstPostCall, CEENode,
+ *UpdatedCall, *this,
+ /*WasInlined=*/true);
+}
 ExplodedNodeSet Dst;
 

[PATCH] D41408: [analyzer] NFC: Fix nothrow operator new definition in a test.

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

Fun C++ fact: definition

  void *operator new(std::size_t size, std::nothrow_t ¬hrow) throw() { ... }

does not override the global nothrow operator new. The standard nothrow 
operator new would still be called when this definition is present. Because, 
well, the second parameter (`std::nothrow_t ¬hrow`) is missing a `const` 
qualifier, so it's a completely different function. In fact, temporary of type 
`std::nothrow_t` would never be bound to a non-const reference at all. So the 
custom operator defined above is also very hard to call.

This patch fixes the test case. The analyzer behavior is intended (at least for 
now, see also discussion in https://reviews.llvm.org/D41406) regardless of 
whether the operator is overridden correctly or not, but tests now actually 
test it.


Repository:
  rC Clang

https://reviews.llvm.org/D41408

Files:
  test/Analysis/NewDelete-custom.cpp


Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -4,16 +4,16 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 
-DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
 
 void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return 
allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t ¬hrow) throw() { 
return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 


Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -4,16 +4,16 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
 
 void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t ¬hrow) throw() { return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41409: [analyzer] Fix intermediate diagnostics on paths that go through operator new().

2017-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

When operator new() is inlined, diagnostic pieces may appear within it. They'd 
be surrounded by `Calling 'operator new'` and `Returning from 'operator new'` 
pieces. These pieces were already in place, but the analyzer didn't know where 
to put them when the operator was called through operator syntax. This patch 
fixes it.


Repository:
  rC Clang

https://reviews.llvm.org/D41409

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/new-ctor-malloc.cpp


Index: test/Analysis/new-ctor-malloc.cpp
===
--- test/Analysis/new-ctor-malloc.cpp
+++ test/Analysis/new-ctor-malloc.cpp
@@ -1,18 +1,21 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
 
 typedef __typeof__(sizeof(int)) size_t;
 
 void *malloc(size_t size);
 
 void *operator new(size_t size) throw() {
-  void *x = malloc(size);
-  if (!x)
+  void *x = malloc(size); // expected-note {{Memory is allocated}}
+  if (!x) // expected-note{{Assuming 'x' is non-null}}
+  // expected-note@-1 {{Taking false branch}}
 return nullptr;
   return x;
 }
 
 void checkNewAndConstructorInlining() {
-  int *s = new int;
+  int *s = new int; // expected-note   {{Calling 'operator new'}}
+// expected-note@-1{{Returning from 'operator new'}}
 } // expected-warning {{Potential leak of memory pointed to by 's'}}
+  // expected-note@-1 {{Potential leak of memory pointed to by 's'}}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -576,8 +576,11 @@
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::NewAllocator: {
+const CFGNewAllocator &Alloc = Source.castAs();
+return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
-  case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:


Index: test/Analysis/new-ctor-malloc.cpp
===
--- test/Analysis/new-ctor-malloc.cpp
+++ test/Analysis/new-ctor-malloc.cpp
@@ -1,18 +1,21 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
 
 typedef __typeof__(sizeof(int)) size_t;
 
 void *malloc(size_t size);
 
 void *operator new(size_t size) throw() {
-  void *x = malloc(size);
-  if (!x)
+  void *x = malloc(size); // expected-note {{Memory is allocated}}
+  if (!x) // expected-note{{Assuming 'x' is non-null}}
+  // expected-note@-1 {{Taking false branch}}
 return nullptr;
   return x;
 }
 
 void checkNewAndConstructorInlining() {
-  int *s = new int;
+  int *s = new int; // expected-note   {{Calling 'operator new'}}
+// expected-note@-1{{Returning from 'operator new'}}
 } // expected-warning {{Potential leak of memory pointed to by 's'}}
+  // expected-note@-1 {{Potential leak of memory pointed to by 's'}}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -576,8 +576,11 @@
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::NewAllocator: {
+const CFGNewAllocator &Alloc = Source.castAs();
+return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
-  case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321102 - [driver][darwin] Set the 'simulator' environment when it's specified

2017-12-19 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Dec 19 11:56:14 2017
New Revision: 321102

URL: http://llvm.org/viewvc/llvm-project?rev=321102&view=rev
Log:
[driver][darwin] Set the 'simulator' environment when it's specified
in '-target'

rdar://35742458

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/test/Driver/darwin-version.c

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=321102&r1=321101&r2=321102&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Tue Dec 19 11:56:14 2017
@@ -1181,9 +1181,12 @@ struct DarwinPlatform {
   };
 
   using DarwinPlatformKind = Darwin::DarwinPlatformKind;
+  using DarwinEnvironmentKind = Darwin::DarwinEnvironmentKind;
 
   DarwinPlatformKind getPlatform() const { return Platform; }
 
+  DarwinEnvironmentKind getEnvironment() const { return Environment; }
+
   StringRef getOSVersion() const {
 if (Kind == OSVersionArg)
   return Argument->getValue();
@@ -1234,8 +1237,17 @@ struct DarwinPlatform {
   }
 
   static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
- StringRef OSVersion, Arg *A) {
-return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+ StringRef OSVersion, Arg *A,
+ llvm::Triple::EnvironmentType Env) {
+DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+switch (Env) {
+case llvm::Triple::Simulator:
+  Result.Environment = DarwinEnvironmentKind::Simulator;
+  break;
+default:
+  break;
+}
+return Result;
   }
   static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
@@ -1282,6 +1294,7 @@ private:
 
   SourceKind Kind;
   DarwinPlatformKind Platform;
+  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
   std::string OSVersion;
   Arg *Argument;
   StringRef EnvVarName;
@@ -1478,7 +1491,8 @@ Optional getDeploymentTa
 return None;
   std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
   return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
-  
Args.getLastArg(options::OPT_target));
+  Args.getLastArg(options::OPT_target),
+  Triple.getEnvironment());
 }
 
 } // namespace
@@ -1584,10 +1598,11 @@ void Darwin::AddDeploymentTarget(Derived
   } else
 llvm_unreachable("unknown kind of Darwin platform");
 
-  DarwinEnvironmentKind Environment = NativeEnvironment;
+  DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
-  if (Platform != MacOS && (getTriple().getArch() == llvm::Triple::x86 ||
-getTriple().getArch() == llvm::Triple::x86_64))
+  if (Environment == NativeEnvironment && Platform != MacOS &&
+  (getTriple().getArch() == llvm::Triple::x86 ||
+   getTriple().getArch() == llvm::Triple::x86_64))
 Environment = Simulator;
 
   setTarget(Platform, Environment, Major, Minor, Micro);

Modified: cfe/trunk/test/Driver/darwin-version.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-version.c?rev=321102&r1=321101&r2=321102&view=diff
==
--- cfe/trunk/test/Driver/darwin-version.c (original)
+++ cfe/trunk/test/Driver/darwin-version.c Tue Dec 19 11:56:14 2017
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 
| \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"


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


[PATCH] D41076: [driver][darwin] Set the 'simulator' environment when it's specified in '-target'

2017-12-19 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC321102: [driver][darwin] Set the 'simulator' 
environment when it's specified (authored by arphaman, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41076

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 
| \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   using DarwinPlatformKind = Darwin::DarwinPlatformKind;
+  using DarwinEnvironmentKind = Darwin::DarwinEnvironmentKind;
 
   DarwinPlatformKind getPlatform() const { return Platform; }
 
+  DarwinEnvironmentKind getEnvironment() const { return Environment; }
+
   StringRef getOSVersion() const {
 if (Kind == OSVersionArg)
   return Argument->getValue();
@@ -1234,8 +1237,17 @@
   }
 
   static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
- StringRef OSVersion, Arg *A) {
-return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+ StringRef OSVersion, Arg *A,
+ llvm::Triple::EnvironmentType Env) {
+DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+switch (Env) {
+case llvm::Triple::Simulator:
+  Result.Environment = DarwinEnvironmentKind::Simulator;
+  break;
+default:
+  break;
+}
+return Result;
   }
   static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
@@ -1282,6 +1294,7 @@
 
   SourceKind Kind;
   DarwinPlatformKind Platform;
+  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
   std::string OSVersion;
   Arg *Argument;
   StringRef EnvVarName;
@@ -1478,7 +1491,8 @@
 return None;
   std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
   return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
-  
Args.getLastArg(options::OPT_target));
+  Args.getLastArg(options::OPT_target),
+  Triple.getEnvironment());
 }
 
 } // namespace
@@ -1584,10 +1598,11 @@
   } else
 llvm_unreachable("unknown kind of Darwin platform");
 
-  DarwinEnvironmentKind Environment = NativeEnvironment;
+  DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
-  if (Platform != MacOS && (getTriple().getArch() == llvm::Triple::x86 ||
-getTriple().getArch() == llvm::Triple::x86_64))
+  if (Environment == NativeEnvironment && Platform != MacOS &&
+  (getTriple().getArch() == llvm::Triple::x86 ||
+   getTriple().getArch() == llvm::Triple::x86_64))
 Environment = Simulator;
 
   setTarget(Platform, Environment, Major, Minor, Micro);


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.

[PATCH] D40295: -fsanitize=vptr warnings on bad static types in dynamic_cast and typeid

2017-12-19 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

I don't think any checks can be skipped in the newly-introduced calls to 
EmitTypeCheck. Clang uses EmitDynamicCast on arbitrary addresses, not just 
addresses which are known to be checked for alignment/etc. Regarding the test 
update, I think it makes sense to extend the runtime test in vptr.cpp, but that 
we'd also benefit from a small/narrow IR test (e.g in 
test/CodeGenCXX/ubsan-vtable-checks.cpp). With the added test I think this 
patch would be in great shape.


https://reviews.llvm.org/D40295



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


[PATCH] D41280: [clangd] Don't use the optional "severity" when comparing Diagnostic.

2017-12-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 127586.
hokein marked an inline comment as done.
hokein added a comment.

Fix typos.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41280

Files:
  clangd/ClangdLSPServer.h
  clangd/Protocol.h


Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -322,14 +322,15 @@
 
   /// The diagnostic's message.
   std::string message;
-
-  friend bool operator==(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) ==
-   std::tie(RHS.range, RHS.severity, RHS.message);
-  }
-  friend bool operator<(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) <
-   std::tie(RHS.range, RHS.severity, RHS.message);
+};
+/// A LSP-specific comparator used to find diagnostic in a container like
+/// std:map.
+/// We only use the required fields of Diagnostic to do the comparsion to avoid
+/// any regression issues from LSP clients (e.g. VScode), see
+/// https://git.io/vbr29
+struct LSPDiagnosticCompare {
+  bool operator()(const Diagnostic& LHS, const Diagnostic& RHS) const {
+return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
   }
 };
 bool fromJSON(const json::Expr &, Diagnostic &);
Index: clangd/ClangdLSPServer.h
===
--- clangd/ClangdLSPServer.h
+++ clangd/ClangdLSPServer.h
@@ -87,7 +87,8 @@
   bool IsDone = false;
 
   std::mutex FixItsMutex;
-  typedef std::map>
+  typedef std::map,
+   LSPDiagnosticCompare>
   DiagnosticToReplacementMap;
   /// Caches FixIts per file and diagnostics
   llvm::StringMap FixItsMap;


Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -322,14 +322,15 @@
 
   /// The diagnostic's message.
   std::string message;
-
-  friend bool operator==(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) ==
-   std::tie(RHS.range, RHS.severity, RHS.message);
-  }
-  friend bool operator<(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) <
-   std::tie(RHS.range, RHS.severity, RHS.message);
+};
+/// A LSP-specific comparator used to find diagnostic in a container like
+/// std:map.
+/// We only use the required fields of Diagnostic to do the comparsion to avoid
+/// any regression issues from LSP clients (e.g. VScode), see
+/// https://git.io/vbr29
+struct LSPDiagnosticCompare {
+  bool operator()(const Diagnostic& LHS, const Diagnostic& RHS) const {
+return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
   }
 };
 bool fromJSON(const json::Expr &, Diagnostic &);
Index: clangd/ClangdLSPServer.h
===
--- clangd/ClangdLSPServer.h
+++ clangd/ClangdLSPServer.h
@@ -87,7 +87,8 @@
   bool IsDone = false;
 
   std::mutex FixItsMutex;
-  typedef std::map>
+  typedef std::map,
+   LSPDiagnosticCompare>
   DiagnosticToReplacementMap;
   /// Caches FixIts per file and diagnostics
   llvm::StringMap FixItsMap;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40478: Added control flow architecture protection Flag

2017-12-19 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon marked an inline comment as done.
oren_ben_simhon added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:876
   // Apply xray attributes to the function (as a string, for now)
-  if (D && ShouldXRayInstrumentFunction()) {
+  bool InstrumentXray = ShouldXRayInstrumentFunction();
+  if (D && InstrumentXray) {

craig.topper wrote:
> Why this change?
Apparently, some compilers do strange optimizations on bit structures (like 
CodeGenOptions) that cause this code to be compiled wrongly. 
I encountered this issue when i added a new Code Gen Option and compiled clang 
in windows.
In order to overcome this issue, i changed a bit the code and the wrong 
optimization didn't occur.


Repository:
  rL LLVM

https://reviews.llvm.org/D40478



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


[PATCH] D40478: Added control flow architecture protection Flag

2017-12-19 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon updated this revision to Diff 127590.
oren_ben_simhon added a reviewer: pcc.
oren_ben_simhon added a comment.

Implemented comments posted until 12/19 (Thanks Craig)


Repository:
  rL LLVM

https://reviews.llvm.org/D40478

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/cf-arch-protection.c
  test/CodeGen/complex-builtins.c
  test/CodeGen/complex-libcalls.c
  test/CodeGen/math-builtins.c
  test/CodeGen/math-libcalls.c
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -503,3 +503,19 @@
 // CHECK-WINDOWS-ISO10646: "-fwchar-type=int"
 // CHECK-WINDOWS-ISO10646: "-fsigned-wchar"
 
+// RUN: %clang -### -S -fcf-arch-protection %s 2>&1 | FileCheck -check-prefix=CHECK-CF-ARCH-PROTECTION %s
+// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-ARCH-PROTECTION %s
+// CHECK-CF-ARCH-PROTECTION: -fcf-arch-protection
+// CHECK-NO-CF-ARCH-PROTECTION-NOT: -fcf-arch-protection
+// RUN: %clang -### -S -fcf-arch-protection=full %s 2>&1 | FileCheck -check-prefix=CHECK-CF-ARCH-PROTECTION-FULL %s
+// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-ARCH-PROTECTION-FULL %s
+// CHECK-CF-ARCH-PROTECTION-FULL: -fcf-arch-protection=full
+// CHECK-NO-CF-ARCH-PROTECTION-FULL-NOT: -fcf-arch-protection=full
+// RUN: %clang -### -S -fcf-arch-protection=return %s 2>&1 | FileCheck -check-prefix=CHECK-CF-ARCH-PROTECTION-RETURN %s
+// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-ARCH-PROTECTION-RETURN %s
+// CHECK-CF-ARCH-PROTECTION-RETURN: -fcf-arch-protection=return
+// CHECK-NO-CF-ARCH-PROTECTION-RETURN-NOT: -fcf-arch-protection=return
+// RUN: %clang -### -S -fcf-arch-protection=branch %s 2>&1 | FileCheck -check-prefix=CHECK-CF-ARCH-PROTECTION-BRANCH %s
+// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-ARCH-PROTECTION-BRANCH %s
+// CHECK-CF-ARCH-PROTECTION-BRANCH: -fcf-arch-protection=branch
+// CHECK-NO-CF-ARCH-PROTECTION-BRANCH-NOT: -fcf-arch-protection=branch
Index: test/CodeGen/math-libcalls.c
===
--- test/CodeGen/math-libcalls.c
+++ test/CodeGen/math-libcalls.c
@@ -534,11 +534,11 @@
 
 
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
-// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 // NO__ERRNO: attributes [[READONLY]] = { {{.*}}readonly{{.*}} }
 // NO__ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
 
-// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 // HAS_ERRNO: attributes [[READONLY]] = { {{.*}}readonly{{.*}} }
 
Index: test/CodeGen/math-builtins.c
===
--- test/CodeGen/math-builtins.c
+++ test/CodeGen/math-builtins.c
@@ -565,9 +565,9 @@
 
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 // NO__ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
-// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 
-// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE_INTRINSIC]] = { {{.*}}readnone{{.*}} }
 // HAS_ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 
Index: test/CodeGen/complex-libcalls.c
===
--- test/CodeGen/complex-libcalls.c
+++ test/CodeGen/complex-libcalls.c
@@ -201,8 +201,8 @@
 
 
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
-// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 
-// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// HAS_ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correctly{{.*}} }
 // HAS_ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
 
Index: test/CodeGen/complex-builtins.c
===
--- test/CodeGen/complex-builtins.c
+++ test/CodeGen/complex-builtins.c
@@ -199,8 +199,8 @@
 
 
 // NO__ERRNO: attributes [[READNONE]] = { {{.*}}readnone{{.*}} }
-// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind "correctly{{.*}} }
+// NO__ERRNO: attributes [[NOT_READNONE]] = { nounwind {{.*}} "correc

  1   2   >