[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-07-04 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 207977.
Tyker marked 2 inline comments as done.
Tyker set the repository for this revision to rC Clang.
Tyker added a comment.

fixed comment typo.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63640

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/APValue.cpp

Index: clang/test/PCH/APValue.cpp
===
--- /dev/null
+++ clang/test/PCH/APValue.cpp
@@ -0,0 +1,211 @@
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -include-pch %t.pch -ast-dump-all | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -ast-merge %t.pch -ast-dump-all | FileCheck %s
+
+#ifndef EMIT
+#define EMIT
+
+namespace Integer {
+
+constexpr int Unique_Int = int(6789);
+//CHECK:  VarDecl {{.*}} Unique_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'int' 6789
+
+constexpr __uint128_t Unique_Int128 = ((__uint128_t)0x75f17d6b3588f843 << 64) | 0xb13dea7c9c324e51;
+//CHECK:  VarDecl {{.*}} Unique_Int128 
+//CHECK-NEXT: ConstantExpr {{.*}} 'unsigned __int128' 156773562844924187900898496343692168785
+
+}
+
+namespace FloatingPoint {
+
+constexpr double Unique_Double = double(567890.67890);
+//CHECK:  VarDecl {{.*}} Unique_Double
+//CHECK-NEXT: ConstantExpr {{.*}} 'double' 5.678907e+05
+
+}
+
+// FIXME: Add test for FixePoint, ComplexInt, ComplexFloat, AddrLabelDiff.
+
+namespace Struct {
+
+struct B {
+  int i;
+  double d;
+};
+
+constexpr B Basic_Struct = B{1, 0.7};
+//CHECK:  VarDecl {{.*}} Basic_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::B' {1, 7.00e-01}
+
+struct C {
+  int i = 9;
+};
+
+struct A : B {
+  int i;
+  double d;
+  C c;
+};
+
+constexpr A Advanced_Struct = A{Basic_Struct, 1, 79.789, {}};
+//CHECK:  VarDecl {{.*}} Advanced_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::A' {{[{][{]}}1, 7.00e-01}, 1, 7.978900e+01, {9}}
+
+}
+
+namespace Vector {
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Vector_Int = (v4si){8, 2, 3};
+//CHECK:  VarDecl {{.*}} Vector_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'Vector::v4si':'__attribute__((__vector_size__(4 * sizeof(int int' {8, 2, 3, 0}
+
+}
+
+namespace Array {
+
+constexpr int Array_Int[] = {1, 2, 3, 4, 5, 6};
+//CHECK:  VarDecl {{.*}} Array_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'const int [6]' {1, 2, 3, 4, 5, 6}
+
+struct A {
+  int i = 789;
+  double d = 67890.09876;
+};
+
+constexpr A Array2_Struct[][3] = {{{}, {-45678, 9.8}, {9}}, {{}}};
+//CHECK:  VarDecl {{.*}} Array2_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'Array::A const [2][3]' {{[{][{]}}{789, 6.789010e+04}, {-45678, 9.80e+00}, {9, 6.789010e+04}}, {{[{][{]}}789, 6.789010e+04}, {789, 6.789010e+04}, {789, 6.789010e+04}}}
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Array_Vector[] = {{1, 2, 3, 4}, {4, 5, 6, 7}};
+//CHECK:  VarDecl {{.*}} Array_Vector
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Array::v4si [2]' {{[{][{]}}1, 2, 3, 4}, {4, 5, 6, 7}}
+
+}
+
+namespace Union {
+
+struct A {
+  int i = 6789;
+  float f = 987.9876;
+};
+
+union U {
+  int i;
+  A a{567890, 9876.5678f};
+};
+
+constexpr U Unique_Union1 = U{0};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.i = 0}
+
+constexpr U Unique_Union2 = U{};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.a = {567890, 9.876567e+03}}
+
+}
+
+namespace MemberPointer{
+
+struct A {
+  struct B {
+struct C {
+  struct D {
+struct E {
+  struct F {
+struct G {
+  int i;
+};
+  };
+};
+  };
+};
+  };
+};
+
+constexpr auto MemberPointer1 = &A::B::C::D::E::F::G::i;
+//CHECK:  VarDecl {{.*}} MemberPointer1
+//CHECK-NEXT: ConstantExpr {{.*}} 'int MemberPointer::A::B::C::D::E::F::G::*' &G::i
+
+struct A1 {
+  struct B1 {
+int f() const {
+  return 0;
+}
+  };
+
+};
+
+constexpr auto MemberPointer2 = &A1::B1::f;
+//CHECK:  VarDecl {{.*}} MemberPointer2
+//CHECK-NEXT: ConstantExpr {{.*}} 'int (MemberPointer::A1::B1::*)() const' &B1::f
+
+}
+
+namespace std {
+  struct type_info;
+};
+
+namespace LValue {
+
+constexpr int LValueInt = 0;
+constexpr const int& ConstIntRef = LValueInt;
+//CHECK:  VarDecl {{.*}} ConstIntRef

[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-07-04 Thread Tyker via Phabricator via cfe-commits
Tyker added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8503
 
+llvm::Expected ASTImporter::Import(const APValue &FromValue) {
+  APValue Result;

martong wrote:
> Looks okay, but could we have unit tests for this in ASTImporterTest.cpp?
I tested importing using the same test file as serialization 
`clang/test/PCH/APValue.cpp` with `-ast-merge` which uses importing. this 
prevent duplicating the test code for importing and serializing. is the 
unit-test in ASTImporterTest.cpp necessary anyway ?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63640



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


[PATCH] D63919: [clangd] Emit publishSemanticHighlighting in LSP if enabled

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:59
+  void onHighlightingsReady(PathRef File,
+ std::vector Highlightings) 
override;
 

nit: clang-format.



Comment at: clang-tools-extra/clangd/test/semantic-highlighting.test:36
+# CHECK-NEXT:  "renameProvider": true,
+# CHECK-NEXT:  "semanticHighlighting": {
+# CHECK-NEXT:"scopes": [

nit: we could just verify this field like:

```
# CHECK:  "id": 0,
# CHECK:  " "semanticHighlighting": {
# CHECK-NEXT:"scopes": [
# CHECK-NEXT:  [
# CHECK-NEXT:"variable.cpp"
# CHECK-NEXT:  ],
# CHECK-NEXT:  [
# CHECK-NEXT:"entity.name.function.cpp"
# CHECK-NEXT:  ]
# CHECK-NEXT:]
# CHECK-NEXT:  },
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63919



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


[clang-tools-extra] r365111 - [clangd] Emit publishSemanticHighlighting in LSP if enabled

2019-07-04 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Thu Jul  4 00:53:12 2019
New Revision: 365111

URL: http://llvm.org/viewvc/llvm-project?rev=365111&view=rev
Log:
[clangd] Emit publishSemanticHighlighting in LSP if enabled

Summary: Emit publishSemanticHighlighting in LSP if enabled

Reviewers: hokein, kadircet

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

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=365111&r1=365110&r2=365111&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Jul  4 00:53:12 2019
@@ -11,6 +11,7 @@
 #include "FormattedString.h"
 #include "GlobalCompilationDatabase.h"
 #include "Protocol.h"
+#include "SemanticHighlighting.h"
 #include "SourceCode.h"
 #include "Trace.h"
 #include "URI.h"
@@ -328,6 +329,8 @@ void ClangdLSPServer::onInitialize(const
 WithOffsetEncoding.emplace(kCurrentOffsetEncoding,
*NegotiatedOffsetEncoding);
 
+  ClangdServerOpts.SemanticHighlighting =
+  Params.capabilities.SemanticHighlighting;
   if (Params.rootUri && *Params.rootUri)
 ClangdServerOpts.WorkspaceRoot = Params.rootUri->file();
   else if (Params.rootPath && !Params.rootPath->empty())
@@ -407,6 +410,11 @@ void ClangdLSPServer::onInitialize(const
 ;
   if (NegotiatedOffsetEncoding)
 Result["offsetEncoding"] = *NegotiatedOffsetEncoding;
+  if (Params.capabilities.SemanticHighlighting)
+Result.getObject("capabilities")
+->insert(
+{"semanticHighlighting",
+ llvm::json::Object{{"scopes", getTextMateScopeLookupTable()}}});
   Reply(std::move(Result));
 }
 
@@ -927,6 +935,11 @@ void ClangdLSPServer::applyConfiguration
 reparseOpenedFiles();
 }
 
+void ClangdLSPServer::publishSemanticHighlighting(
+SemanticHighlightingParams Params) {
+  notify("textDocument/semanticHighlighting", Params);
+}
+
 void ClangdLSPServer::publishDiagnostics(
 const URIForFile &File, std::vector Diagnostics) {
   // Publish diagnostics.
@@ -1063,6 +1076,13 @@ bool ClangdLSPServer::shouldRunCompletio
   return true;
 }
 
+void ClangdLSPServer::onHighlightingsReady(
+PathRef File, std::vector Highlightings) {
+  publishSemanticHighlighting(
+  {{URIForFile::canonicalize(File, /*TUPath=*/File)},
+   toSemanticHighlightingInformation(Highlightings)});
+}
+
 void ClangdLSPServer::onDiagnosticsReady(PathRef File,
  std::vector Diagnostics) {
   auto URI = URIForFile::canonicalize(File, /*TUPath=*/File);

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=365111&r1=365110&r2=365111&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Jul  4 00:53:12 2019
@@ -55,6 +55,8 @@ private:
   // Implement DiagnosticsConsumer.
   void onDiagnosticsReady(PathRef File, std::vector Diagnostics) 
override;
   void onFileUpdated(PathRef File, const TUStatus &Status) override;
+  void onHighlightingsReady(PathRef File,
+ std::vector Highlightings) 
override;
 
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).
@@ -115,6 +117,9 @@ private:
   void reparseOpenedFiles();
   void applyConfiguration(const ConfigurationSettings &Settings);
 
+  /// Sends a "publishSemanticHighlighting" notification to the LSP client.
+  void publishSemanticHighlighting(SemanticHighlightingParams Params);
+
   /// Sends a "publishDiagnostics" notification to the LSP client.
   void publishDiagnostics(const URIForFile &File,
   std::vector Diagnostics);

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=365111&r1=365110&r2=365111&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Jul  4 00:53:12 2019
@@ 

[PATCH] D63919: [clangd] Emit publishSemanticHighlighting in LSP if enabled

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jvikstrom marked 2 inline comments as done.
Closed by commit rL365111: [clangd] Emit publishSemanticHighlighting in LSP if 
enabled (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63919?vs=207783&id=207978#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63919

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h
@@ -55,6 +55,8 @@
   // Implement DiagnosticsConsumer.
   void onDiagnosticsReady(PathRef File, std::vector Diagnostics) override;
   void onFileUpdated(PathRef File, const TUStatus &Status) override;
+  void onHighlightingsReady(PathRef File,
+ std::vector Highlightings) override;
 
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).
@@ -115,6 +117,9 @@
   void reparseOpenedFiles();
   void applyConfiguration(const ConfigurationSettings &Settings);
 
+  /// Sends a "publishSemanticHighlighting" notification to the LSP client.
+  void publishSemanticHighlighting(SemanticHighlightingParams Params);
+
   /// Sends a "publishDiagnostics" notification to the LSP client.
   void publishDiagnostics(const URIForFile &File,
   std::vector Diagnostics);
Index: clang-tools-extra/trunk/clangd/Protocol.cpp
===
--- clang-tools-extra/trunk/clangd/Protocol.cpp
+++ clang-tools-extra/trunk/clangd/Protocol.cpp
@@ -273,6 +273,12 @@
   if (!O)
 return false;
   if (auto *TextDocument = O->getObject("textDocument")) {
+if (auto *SemanticHighlighting =
+TextDocument->getObject("semanticHighlightingCapabilities")) {
+  if (auto SemanticHighlightingSupport =
+  SemanticHighlighting->getBoolean("semanticHighlighting"))
+R.SemanticHighlighting = *SemanticHighlightingSupport;
+}
 if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
   if (auto CategorySupport = Diagnostics->getBoolean("categorySupport"))
 R.DiagnosticCategory = *CategorySupport;
@@ -1027,5 +1033,22 @@
   return OS << toString(Enc);
 }
 
+bool operator==(const SemanticHighlightingInformation &Lhs,
+const SemanticHighlightingInformation &Rhs) {
+  return Lhs.Line == Rhs.Line && Lhs.Tokens == Rhs.Tokens;
+}
+
+llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting) {
+  return llvm::json::Object{{"line", Highlighting.Line},
+{"tokens", Highlighting.Tokens}};
+}
+
+llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting) {
+  return llvm::json::Object{
+  {"textDocument", Highlighting.TextDocument},
+  {"lines", std::move(Highlighting.Lines)},
+  };
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
@@ -0,0 +1,75 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"semanticHighlightingCapabilities":{"semanticHighlighting":true}}},"trace":"off"}}
+---
+#  CHECK:  "id": 0,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"capabilities": {
+# CHECK-NEXT:  "codeActionProvider": true,
+# CHECK-NEXT:  "completionProvider": {
+# CHECK-NEXT:"resolveProvider": false,
+# CHECK-NEXT:"triggerCharacters": [
+# CHECK-NEXT:  ".",
+# CHECK-NEXT:  ">",
+# CHECK-NEXT:  ":"
+# CHECK-NEXT:]
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "declarationProvider": true,
+# CHECK-NEXT:  "definitionProvider": true,
+# CHECK-NEXT:  "documentFormattingProvider": true,
+# CHECK-NEXT:  "documentHighlightProvider": true,
+# CHECK-NEXT:  "documentOnTypeFormattingProvider": {
+# CHECK-NEXT:"firstTriggerCharacter": "\n",
+# CHECK-NEXT:"moreTrigge

[PATCH] D64137: [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:15
+
+llvm::StringRef highlightingKindToString(HighlightingKind Kind) {
+  switch (Kind) {

it would be nice to use the textmate class name rather than an arbitrary string 
here, it saves a level of indirection when verifying/debugging behavior



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:48
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  auto &SM = Inputs.AST.getSourceManager();

These operations are contextual, it would be nice to root at the selected node.

You should be able to do (approximately) this by walking up to the next decl 
and using it as the traversal scope - don't forget to reset it afterwards!

(This is a bit hacky and invalidates the parent map, but it's a debug tweak so 
it should be OK)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64137



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


[clang-tools-extra] r365112 - [clangd] Add missing changes for 365111

2019-07-04 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Thu Jul  4 01:06:48 2019
New Revision: 365112

URL: http://llvm.org/viewvc/llvm-project?rev=365112&view=rev
Log:
[clangd] Add missing changes for 365111

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=365112&r1=365111&r2=365112&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Jul  4 01:06:48 2019
@@ -55,8 +55,9 @@ private:
   // Implement DiagnosticsConsumer.
   void onDiagnosticsReady(PathRef File, std::vector Diagnostics) 
override;
   void onFileUpdated(PathRef File, const TUStatus &Status) override;
-  void onHighlightingsReady(PathRef File,
- std::vector Highlightings) 
override;
+  void
+  onHighlightingsReady(PathRef File,
+   std::vector Highlightings) override;
 
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=365112&r1=365111&r2=365112&view=diff
==
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Thu Jul  4 
01:06:48 2019
@@ -2,38 +2,7 @@
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"semanticHighlightingCapabilities":{"semanticHighlighting":true}}},"trace":"off"}}
 ---
 #  CHECK:  "id": 0,
-# CHECK-NEXT:  "jsonrpc": "2.0",
-# CHECK-NEXT:  "result": {
-# CHECK-NEXT:"capabilities": {
-# CHECK-NEXT:  "codeActionProvider": true,
-# CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"resolveProvider": false,
-# CHECK-NEXT:"triggerCharacters": [
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":"
-# CHECK-NEXT:]
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "declarationProvider": true,
-# CHECK-NEXT:  "definitionProvider": true,
-# CHECK-NEXT:  "documentFormattingProvider": true,
-# CHECK-NEXT:  "documentHighlightProvider": true,
-# CHECK-NEXT:  "documentOnTypeFormattingProvider": {
-# CHECK-NEXT:"firstTriggerCharacter": "\n",
-# CHECK-NEXT:"moreTriggerCharacter": []
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "documentRangeFormattingProvider": true,
-# CHECK-NEXT:  "documentSymbolProvider": true,
-# CHECK-NEXT:  "executeCommandProvider": {
-# CHECK-NEXT:"commands": [
-# CHECK-NEXT:  "clangd.applyFix",
-# CHECK-NEXT:  "clangd.applyTweak"
-# CHECK-NEXT:]
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "hoverProvider": true,
-# CHECK-NEXT:  "referencesProvider": true,
-# CHECK-NEXT:  "renameProvider": true,
-# CHECK-NEXT:  "semanticHighlighting": {
+# CHECK:  "semanticHighlighting": {
 # CHECK-NEXT:"scopes": [
 # CHECK-NEXT:  [
 # CHECK-NEXT:"variable.cpp"
@@ -43,17 +12,6 @@
 # CHECK-NEXT:  ]
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
-# CHECK-NEXT:  "signatureHelpProvider": {
-# CHECK-NEXT:"triggerCharacters": [
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ","
-# CHECK-NEXT:]
-# CHECK-NEXT:  },
-# CHECK-NEXT:  "textDocumentSync": 2,
-# CHECK-NEXT:  "typeHierarchyProvider": true
-# CHECK-NEXT:  "workspaceSymbolProvider": true
-# CHECK-NEXT:}
-# CHECK-NEXT:  }
 ---
 
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"int
 x = 2;"}}}
 #  CHECK:  "method": "textDocument/semanticHighlighting",


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


[PATCH] D64147: [clangd] Make HadErrors part of background index's internal state

2019-07-04 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.

Logic looks great, just naming/comment nits




Comment at: clang-tools-extra/clangd/index/Background.cpp:276
+const auto DigestIt = IndexedFilesSnapshot.find(AbsPath);
 // File has different contents.
+if (DigestIt == IndexedFilesSnapshot.end() ||

, or we indexed successfully this time.



Comment at: clang-tools-extra/clangd/index/Background.cpp:444
   SymbolCollector::Options IndexOpts;
-  IndexOpts.FileFilter = createFileFilter(DigestsSnapshot);
+  // Creates a filter to not collect index results from files with unchanged
+  // digests.

I'm happy with this inline or out-of-line, but if it's inline here it shouldn't 
have a function-style comment with \p :-)



Comment at: clang-tools-extra/clangd/index/Background.h:98
+  /// Represents the state of a single file when indexing was performed.
+  struct IndexedFile {
+FileDigest Digest{0};

I wonder whether a more "flavorful" name like "ShardVersion" might help explain 
the purpose here?



Comment at: clang-tools-extra/clangd/index/Background.h:125
   FileSymbols IndexedSymbols;
-  llvm::StringMap IndexedFileDigests; // Key is absolute file path.
+  // We do not store the whole IncludeGraph since we only care about Digest and
+  // Errorness of each source file. We might start storing IncludeGraph 
directly

It's not obvious to me why we're apologising for this not being the include 
graph. The data happens to come from there (kind of) but I wouldn't really 
mention it.



Comment at: clang-tools-extra/clangd/index/Background.h:128
+  // once there are use cases for additional information in include graph.
+  llvm::StringMap IndexedFiles; // Key is absolute file path.
   std::mutex DigestsMu;

Again, I think "Versions" would make it more obvious what this is for.



Comment at: clang-tools-extra/clangd/index/Background.h:129
+  llvm::StringMap IndexedFiles; // Key is absolute file path.
   std::mutex DigestsMu;
 

rename mutex to match guarded variable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64147



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


[PATCH] D64196: [clangd] Query driver reads stderr and passes driver as first argument

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

gcc invokes cc1 through a path deduced from argv[0] therefore it must
be correctly set.
Also it prints the search path to stderr not stdout, this also applies to clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64196

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -3,11 +3,12 @@
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here: >&2' >> 
%t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -102,20 +102,19 @@
 return {};
   }
 
-  llvm::SmallString<128> OutputPath;
-  auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
-   OutputPath);
-  if (EC) {
+  llvm::SmallString<128> StdErrPath;
+  if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
+   StdErrPath)) {
 elog("System include extraction: failed to create temporary file with "
  "error {0}",
  EC.message());
 return {};
   }
   auto CleanUp = llvm::make_scope_exit(
-  [&OutputPath]() { llvm::sys::fs::remove(OutputPath); });
+  [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); });
 
   llvm::Optional Redirects[] = {
-  {""}, llvm::StringRef(OutputPath), {""}};
+  {""}, {""}, llvm::StringRef(StdErrPath)};
 
   auto Type = driver::types::lookupTypeForExtension(Ext);
   if (Type == driver::types::TY_INVALID) {
@@ -123,22 +122,21 @@
 return {};
   }
   // Should we also preserve flags like "-sysroot", "-nostdinc" ?
-  const llvm::StringRef Args[] = {"-E", "-x", driver::types::getTypeName(Type),
-  "-", "-v"};
+  const llvm::StringRef Args[] = {
+  Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"};
 
-  int RC =
-  llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, Redirects);
-  if (RC) {
+  if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
+ Redirects)) {
 elog("System include extraction: driver execution failed with return code: 
"
  "{0}",
  llvm::to_string(RC));
 return {};
   }
 
-  auto BufOrError = llvm::MemoryBuffer::getFile(OutputPath);
+  auto BufOrError = llvm::MemoryBuffer::getFile(StdErrPath);
   if (!BufOrError) {
 elog("System include extraction: failed to read {0} with error {1}",
- OutputPath, BufOrError.getError().message());
+ StdErrPath, BufOrError.getError().message());
 return {};
   }
 


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -3,11 +3,12 @@
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' 

[PATCH] D64147: [clangd] Make HadErrors part of background index's internal state

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 207986.
kadircet marked 6 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64147

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -524,18 +524,41 @@
   CDB.setCompileCommand(testPath("build/../A.cc"), Cmd);
   ASSERT_TRUE(Idx.blockUntilIdleForTest());
 
-  // Make sure we only store the shard for main file.
-  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc")));
-  auto Shard = MSS.loadShard(testPath("A.cc"));
-  EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
-  EXPECT_THAT(Shard->Sources->keys(),
-  UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
-   "unittest:///B.h"));
-
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), HadErrors());
-  // FIXME: We should also persist headers while marking them with errors.
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), Not(HadErrors()));
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), Not(HadErrors()));
+  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc"), testPath("A.h"),
+  testPath("B.h"), testPath("C.h")));
+
+  {
+auto Shard = MSS.loadShard(testPath("A.cc"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
+ "unittest:///B.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("A.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///A.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("B.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("asdf")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///B.h", "unittest:///C.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("C.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre());
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///C.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///C.h"), HadErrors());
+  }
 }
 
 TEST_F(BackgroundIndexTest, CmdLineHash) {
Index: clang-tools-extra/clangd/index/Background.h
===
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -12,6 +12,7 @@
 #include "Context.h"
 #include "FSProvider.h"
 #include "GlobalCompilationDatabase.h"
+#include "SourceCode.h"
 #include "Threading.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
@@ -93,11 +94,17 @@
   static void preventThreadStarvationInTests();
 
 private:
+  /// Represents the state of a single file when indexing was performed.
+  struct ShardVersion {
+FileDigest Digest{0};
+bool HadErrors = false;
+  };
+
   /// Given index results from a TU, only update symbols coming from files with
-  /// different digests than \p DigestsSnapshot. Also stores new index
+  /// different digests than \p ShardVersionsSnapshot. Also stores new index
   /// information on IndexStorage.
   void update(llvm::StringRef MainFile, IndexFileIn Index,
-  const llvm::StringMap &DigestsSnapshot,
+  const llvm::StringMap &ShardVersionsSnapshot,
   BackgroundIndexStorage *IndexStorage, bool HadErrors);
 
   // configuration
@@ -115,8 +122,8 @@
   std::condition_variable IndexCV;
 
   FileSymbols IndexedSymbols;
-  llvm::StringMap IndexedFileDigests; // Key is absolute file path.
-  std::mutex DigestsMu;
+  llvm::StringMap ShardVersions; // Key is absolute file path.
+  std::mutex ShardVersionsMu;
 
   BackgroundIndexStorage::Factory IndexStorageFactory;
   struct Source {
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -101,28 +101,6 @@
   return IG;
 }
 
-// Creates a filter to not collect index results from files with unchanged
-// digests.
-// \p FileDigests contains

[PATCH] D63936: [clang][Driver][ARM] Favor -mfpu over default CPU features

2019-07-04 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard added inline comments.



Comment at: llvm/lib/Support/ARMTargetParser.cpp:412
 
-  if (Extensions & AEK_CRC)
-Features.push_back("+crc");
-  else
-Features.push_back("-crc");
-
-  if (Extensions & AEK_DSP)
-Features.push_back("+dsp");
-  else
-Features.push_back("-dsp");
-
-  if (Extensions & AEK_FP16FML)
-Features.push_back("+fp16fml");
-  else
-Features.push_back("-fp16fml");
-
-  if (Extensions & AEK_RAS)
-Features.push_back("+ras");
-  else
-Features.push_back("-ras");
-
-  if (Extensions & AEK_DOTPROD)
-Features.push_back("+dotprod");
-  else
-Features.push_back("-dotprod");
+  for (const auto AE : ARCHExtNames) {
+if ((Extensions & AE.ID) == AE.ID && AE.Feature)

labrinea wrote:
> ostannard wrote:
> > labrinea wrote:
> > > SjoerdMeijer wrote:
> > > > This could be a little local helper function, share the code, as 
> > > > exactly the same is done in `ARM::appendArchExtFeatures`
> > > We are not doing exactly the same thing in these functions. Here we 
> > > extract features out of a bitmap, which is a map containing a bitwise OR 
> > > of separate feature bitmasks. If a bitmask that corresponds to a known 
> > > feature is present - and here I mean all the bits of that mask are 
> > > present - then we push the feature, otherwise not. 
> > > 
> > > In `ARM::appendArchExtFeatures` we compare a given bitmask, which 
> > > corresponds to a specific feature, against all the known bitmasks 
> > > (individual features) one by one. In contrast to 
> > > `ARM::getExtensionFeatures` here we also handle negative features, and 
> > > that means the prohibition of a feature can disable other features that 
> > > depend on it as well.
> > Does this correctly handle the combination of integer-only MVE with a 
> > scalar FPU? I think -march=...+mve+fp should enable AEK_FP and AEK_SIMD 
> > (+mve), but shouldn't enable +mve.fp.
> The target features explicitly specified on the command line are handled by 
> `ARM::appendArchExtFeatures` (see [[ https://reviews.llvm.org/D64048 | D64048 
> ]]). That said, yes, -march=...+mve+fp does enable scalar floating point and 
> integer-only mve, but doesn't enable mve with floating point. I could 
> possibly add such a test on that revision.
> 
> On the other hand, `ARM::getExtensionFeatures` cannot tell the difference 
> between the two configurations you describe, and it's not possible to do so, 
> because they are represented on a bitmap returned from 
> `ARM::getDefaultExtensions`, which reads the table. That said, if there was 
> an entry in the table containing `AEK_FP | AEK_SIMD` that would enable 
> mve.fp. However, I don't think this is a problem in practice. My 
> understanding is that the table indicates FPU support with `FK_*`, and 
> Extension support with `AEK_*`.  That said, I believe AEK_FP is only used for 
> command line option handling.
> 
> Maybe a fix for this problem would be to replace `AEK_FP | AEK_SIMD` with 
> something like `AEK_MVE_FP` but then we wouldn't be able to do what is 
> proposed in [[ https://reviews.llvm.org/D64048 | D64048 ]].
Is this system (in particular the behaviour added in D64048) going to be able 
to handle all of the other dependencies between architectural features? For 
example, MVE also depends on the DSP extension, but 
`-march=armv8.1-m.main+mve+nodsp` currently defines both __ARM_FEATURE_MVE and 
__ARM_FEATURE_DSP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63936



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


[PATCH] D62960: SVE opaque type for C intrinsics demo

2019-07-04 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm updated this revision to Diff 207991.
rsandifo-arm added a comment.

Changes since last version:

- Define the SVE types only for AArch64 targets
- Use the vendor extension 'u' mangling, as per the spec
- Report an error for @encode on the types
- Fixed the licence text on the new file
- Added more tests

Although I'd originally posted the patch so that the sizeless type
support had specific types to test, it'd be really useful if the patch
could go in independently of the sizeless type stuff, since the
patch contains the common subset of functionality needed by the
sizeless type patches and by the implementation of the intrinsics
(which apart from this patch are essentially separate pieces of work).


Repository:
  rC Clang

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

https://reviews.llvm.org/D62960

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/AArch64SVEACLETypes.def
  include/clang/Basic/TargetInfo.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/PrintfFormatString.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/AArch64.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Index/USRGeneration.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/AST/ast-dump-aarch64-sve-types.c
  test/CodeGen/aarch64-sve.c
  test/CodeGenCXX/aarch64-mangle-sve-vectors-msvc.cpp
  test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
  test/CodeGenCXX/aarch64-sve-typeinfo.cpp
  test/CodeGenObjC/aarch64-sve-types.m
  test/PCH/aarch64-sve-types.c
  test/Sema/aarch64-sve-types.c
  test/SemaObjC/aarch64-sve-types.m
  tools/libclang/CIndex.cpp
  unittests/AST/ASTImporterTest.cpp

Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -4574,6 +4574,44 @@
   EXPECT_EQ(Imported->getPreviousDecl(), Friend);
 }
 
+struct SVEBuiltins : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(SVEBuiltins, ImportTypes) {
+  static const char *const TypeNames[] = {
+"__SVInt8_t",
+"__SVInt16_t",
+"__SVInt32_t",
+"__SVInt64_t",
+"__SVUint8_t",
+"__SVUint16_t",
+"__SVUint32_t",
+"__SVUint64_t",
+"__SVFloat16_t",
+"__SVFloat32_t",
+"__SVFloat64_t",
+"__SVBool_t"
+  };
+
+  TranslationUnitDecl *ToTU = getToTuDecl("", Lang_CXX);
+  TranslationUnitDecl *FromTU = getTuDecl("", Lang_CXX, "input.cc");
+  for (auto *TypeName : TypeNames) {
+auto *ToTypedef = FirstDeclMatcher().match(
+  ToTU, typedefDecl(hasName(TypeName)));
+QualType ToType = ToTypedef->getUnderlyingType();
+
+auto *FromTypedef = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName(TypeName)));
+QualType FromType = FromTypedef->getUnderlyingType();
+
+QualType ImportedType = ImportType(FromType, FromTypedef, Lang_CXX);
+EXPECT_EQ(ImportedType, ToType);
+  }
+}
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, SVEBuiltins,
+::testing::Values(ArgVector{"-target",
+"aarch64-linux-gnu"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -1527,6 +1527,9 @@
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
+  // SVE Types
+#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/AArch64SVEACLETypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: test/SemaObjC/aarch64-sve-types.m
===
--- /dev/null
+++ test/SemaObjC/aarch64-sve-types.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s
+
+// Check that we don't abort when SVE types are made nullable.  This
+// interface is invalid anyway, but we won't diagnose that until the
+// sizeless type extension is added.
+@interface foo
+@property(nullable) __SVInt8_t s8; // expected-error {{cannot be applied to non-pointer type}}
+@property(nullable) __SVInt16_t s16; // expected-error {{cannot be applied to non-pointer type}}
+@property(nullable) __SVInt32_t s32; // expected-error {{cannot be applied to non-pointer type}}
+@property(nullable) __SVInt64_t s64; // expected-error {{cannot be applied to non-pointer type}}
+
+@prop

[PATCH] D64019: [clangd] Turn background-index on by default

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:191
 "Index project code in the background and persist index on disk. "
 "Experimental"),
+llvm::cl::init(true));

hokein wrote:
> should we remove the `experimental` term here?
i would rather do that if we are happy with the feedbacks(or no feedbacks) 
within the following weeks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64019



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


[PATCH] D62960: Add SVE opaque built-in types

2019-07-04 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

In D62960#1566265 , @rovka wrote:

> This looks much better, thanks! Shouldn't there be more tests, e.g. for 
> mangling and maybe the ASTImporter?


Thanks.  I've added tests for ASTImporter and mangling in the latest version, 
as well as tests for typeinfo, AST dumping, Objective C errors, PCH 
serialisation and (until we diagnose them as an error) sizeof/alignof queries.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62960



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


[PATCH] D64074: [OpenCL][Sema] Fix builtin rewriting

2019-07-04 Thread Marco Antognini via Phabricator via cfe-commits
mantognini updated this revision to Diff 207994.
mantognini added a comment.

Addressed missing colon in FIXME comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64074

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenOpenCL/builtins.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl


Index: clang/test/CodeGenOpenCL/to_addr_builtin.cl
===
--- clang/test/CodeGenOpenCL/to_addr_builtin.cl
+++ clang/test/CodeGenOpenCL/to_addr_builtin.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=CL2.0 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=c++ -o 
- %s | FileCheck %s
 
 // CHECK: %[[A:.*]] = type { float, float, float }
 typedef struct {
Index: clang/test/CodeGenOpenCL/pipe_builtin.cl
===
--- clang/test/CodeGenOpenCL/pipe_builtin.cl
+++ clang/test/CodeGenOpenCL/pipe_builtin.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=CL2.0 -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o - 
%s | FileCheck %s
 
 // CHECK-DAG: %opencl.pipe_ro_t = type opaque
 // CHECK-DAG: %opencl.pipe_wo_t = type opaque
Index: clang/test/CodeGenOpenCL/builtins.cl
===
--- clang/test/CodeGenOpenCL/builtins.cl
+++ clang/test/CodeGenOpenCL/builtins.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -finclude-default-header -cl-std=CL2.0 -O0 -emit-llvm -o 
- -triple "spir-unknown-unknown" | FileCheck %s
+// RUN: %clang_cc1 %s -finclude-default-header -cl-std=c++ -fblocks -O0 
-emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s
 
 void testBranchingOnEnqueueKernel(queue_t default_queue, unsigned flags, 
ndrange_t ndrange) {
 // Ensure `enqueue_kernel` can be branched upon.
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5360,7 +5360,7 @@
 ///  FunctionDecl is returned.
 /// TODO: Handle pointer return types.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
&Context,
-const FunctionDecl *FDecl,
+FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
 
   QualType DeclType = FDecl->getType();
@@ -5408,7 +5408,7 @@
   FunctionProtoType::ExtProtoInfo EPI;
   QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
 OverloadParams, EPI);
-  DeclContext *Parent = Context.getTranslationUnitDecl();
+  DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(Context, Parent,
 FDecl->getLocation(),
 FDecl->getLocation(),
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1477,6 +1477,7 @@
 BUILTIN(__builtin_coro_end, "bv*Ib", "n")
 BUILTIN(__builtin_coro_suspend, "cIb", "n")
 BUILTIN(__builtin_coro_param, "bv*v*", "n")
+
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
 LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
@@ -1512,6 +1513,8 @@
 LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
 
 // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
+// FIXME: Pointer parameters of OpenCL builtins should have their address space
+// requirement defined.
 LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)


Index: clang/test/CodeGenOpenCL/to_addr_builtin.cl
===
--- clang/test/CodeGenOpenCL/to_addr_builtin.cl
+++ clang/test/CodeGenOpenCL/to_addr_builtin.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=c++ -o - %s | FileCheck %s
 
 // CHECK: %[[A:.*]] = type { float, float, float }
 typedef struct {
Index: clang/test/CodeGenOpenCL/pipe_builtin.cl
===
--- clang/test/CodeGenOpenCL/pipe_builtin.cl
+++ clang/test/CodeGenOpenCL/pipe_builtin.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_su

[PATCH] D64074: [OpenCL][Sema] Fix builtin rewriting

2019-07-04 Thread Marco Antognini via Phabricator via cfe-commits
mantognini added a comment.

I'll commit this along with D64083  in a few 
days in case John has any feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64074



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


[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-07-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/include/clang/AST/ASTImporter.h:331
+///
+/// \return the equivalent APValue in the "from" Constext or the import
+/// error.

martong wrote:
> typo: `Constext` -> `Context`
> Also, we return with the APValue in the "to" context, not the one in the 
> "from" context.
The typo is still there: `Constext` has an extra `s`.



Comment at: clang/lib/AST/ASTImporter.cpp:8503
 
+llvm::Expected ASTImporter::Import(const APValue &FromValue) {
+  APValue Result;

Tyker wrote:
> martong wrote:
> > Looks okay, but could we have unit tests for this in ASTImporterTest.cpp?
> I tested importing using the same test file as serialization 
> `clang/test/PCH/APValue.cpp` with `-ast-merge` which uses importing. this 
> prevent duplicating the test code for importing and serializing. is the 
> unit-test in ASTImporterTest.cpp necessary anyway ?
Okay, that's fine I missed that previously, so there is no need for the 
unit-tests in this case.
Though maybe the `-ast-merge` part of the test should reside in the  
`clang/test/ASTMerge` directory, because that is where all the other 
`-ast-merge` tests are. 
I am not sure how to solve that nicely, because i see you use the same file for 
both the serialization and for the import.
Perhaps there should be a common header file which is included both in 
`test/PCH/APValue.cpp` and in `test/ASTMerge/apvalue/test.cpp`?




Repository:
  rC Clang

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

https://reviews.llvm.org/D63640



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


[PATCH] D64137: [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 207996.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments:

- emit textmate scope names
- rescope to the selected node rather than TU decl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64137

Files:
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -278,6 +278,14 @@
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
 
+TEST(TweakTest, AnnotateHighlightings) {
+  llvm::StringLiteral ID = "AnnotateHighlightings";
+  checkAvailable(ID, "^vo^id^ ^f(^) {^}^"); // available everywhere.
+  const char *Input = "void ^f() {}";
+  const char *Output = "void /* entity.name.function.cpp */f() {}";
+  checkTransform(ID, Input, Output);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
===
--- clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -12,6 +12,7 @@
 # $ to a list of sources, see
 # clangd/tool/CMakeLists.txt for an example.
 add_clang_library(clangDaemonTweaks OBJECT
+  AnnotateHighlightings.cpp
   DumpAST.cpp
   RawStringLiteral.cpp
   SwapIfBranches.cpp
Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -0,0 +1,80 @@
+//===--- AnnotateHighlightings.cpp ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticHighlighting.h"
+#include "refactor/Tweak.h"
+#include "llvm/ADT/ScopeExit.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  static const auto& TextMateLookupTable = getTextMateScopeLookupTable();
+  auto LookupIndex = static_cast(Kind);
+  assert(LookupIndex < TextMateLookupTable.size() &&
+ !TextMateLookupTable[LookupIndex].empty());
+  return TextMateLookupTable[LookupIndex].front();
+}
+
+/// Annotate all highlighting tokens in the current file. This is a hidden tweak
+/// which is used to debug semantic highlightings.
+/// Before:
+///   void f() { int abc; }
+///   ^
+/// After:
+///   void /* entity.name.function.cpp */ f() { int /* variable.cpp */ abc; }
+class AnnotateHighlightings : public Tweak {
+public:
+  const char *id() const override final;
+
+  bool prepare(const Selection &Inputs) override {
+for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
+ N = N->Parent)
+  InterestedDecl = N->ASTNode.get();
+return InterestedDecl;
+  }
+  Expected apply(const Selection &Inputs) override;
+
+  std::string title() const override { return "Annotate highlighting tokens";}
+  Intent intent() const override { return Refactor; }
+  bool hidden() const override { return true; }
+
+private:
+  const Decl* InterestedDecl = nullptr;
+};
+REGISTER_TWEAK(AnnotateHighlightings)
+
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+  auto CleanupTask = llvm::make_scope_exit(
+  [&]() { Inputs.AST.getASTContext().setTraversalScope(BackupScopes); });
+
+  Inputs.AST.getASTContext().setTraversalScope(
+  {const_cast(InterestedDecl)});
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  auto &SM = Inputs.AST.getSourceManager();
+  tooling::Replacements Result;
+  for (const auto &Token : HighlightingTokens) {
+assert(Token.R.start.line == Token.R.end.line &&
+   "Token must be at the same line");
+auto InsertOffset = positionToOffset(Inputs.Code, Token.R.start);
+if (!InsertOffset)
+  return InsertOffset.takeError();
+
+auto InsertReplacement = tooling::Replacement(
+SM.getFileEntryForID(SM.getMainFileID())->getName(), *InsertOffset, 0,
+("/* " + toTextMateScope(Token.Kind) + " */").str());
+if (auto Err = Result.add(InsertReplacement))
+  return std::move(Err);
+  }
+  return Effect::applyEdit(Result);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
_

[PATCH] D62960: Add SVE opaque built-in types

2019-07-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

The ASTImporter and the test for it looks good to me, thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D62960



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


[clang-tools-extra] r365120 - [clangd] Also cache failures while indexing

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 02:51:43 2019
New Revision: 365120

URL: http://llvm.org/viewvc/llvm-project?rev=365120&view=rev
Log:
[clangd] Also cache failures while indexing

Summary:
Clangd currently doesn't cache any indexing failures, which results in
retrying those failed files even if their contents haven't changed.

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365120&r1=365119&r2=365120&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4 02:51:43 2019
@@ -9,7 +9,9 @@
 #include "index/Background.h"
 #include "ClangdUnit.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Logger.h"
+#include "Path.h"
 #include "SourceCode.h"
 #include "Symbol.h"
 #include "Threading.h"
@@ -17,6 +19,8 @@
 #include "URI.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
+#include "index/Ref.h"
+#include "index/Relation.h"
 #include "index/Serialization.h"
 #include "index/SymbolCollector.h"
 #include "clang/Basic/SourceLocation.h"
@@ -25,6 +29,8 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/Threading.h"
 
@@ -271,7 +277,8 @@ void BackgroundIndex::enqueueTask(Task T
 /// information on IndexStorage.
 void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
  const llvm::StringMap 
&DigestsSnapshot,
- BackgroundIndexStorage *IndexStorage) {
+ BackgroundIndexStorage *IndexStorage,
+ bool HadErrors) {
   // Partition symbols/references into files.
   struct File {
 llvm::DenseSet Symbols;
@@ -283,6 +290,14 @@ void BackgroundIndex::update(llvm::Strin
   URIToFileCache URICache(MainFile);
   for (const auto &IndexIt : *Index.Sources) {
 const auto &IGN = IndexIt.getValue();
+// In case of failures, we only store main file of TU. That way we can 
still
+// get symbols from headers if some other TU can compile them. Note that
+// sources do not contain any information regarding missing headers, since
+// we don't even know what absolute path they should fall in.
+// FIXME: Also store contents from other files whenever the current 
contents
+// for those files are missing or if they had errors before.
+if (HadErrors && !IGN.IsTU)
+  continue;
 const auto AbsPath = URICache.resolve(IGN.URI);
 const auto DigestIt = DigestsSnapshot.find(AbsPath);
 // File has different contents.
@@ -347,8 +362,10 @@ void BackgroundIndex::update(llvm::Strin
 auto RelS = llvm::make_unique(std::move(Relations).build());
 auto IG = llvm::make_unique(
 getSubGraph(URI::create(Path), Index.Sources.getValue()));
+
 // We need to store shards before updating the index, since the latter
 // consumes slabs.
+// FIXME: Also skip serializing the shard if it is already up-to-date.
 if (IndexStorage) {
   IndexFileOut Shard;
   Shard.Symbols = SS.get();
@@ -360,6 +377,7 @@ void BackgroundIndex::update(llvm::Strin
 elog("Failed to write background-index shard for file {0}: {1}", Path,
  std::move(Error));
 }
+
 {
   std::lock_guard Lock(DigestsMu);
   auto Hash = FileIt.second.Digest;
@@ -460,12 +478,6 @@ llvm::Error BackgroundIndex::index(tooli
 return Err;
 
   Action->EndSourceFile();
-  if (Clang->hasDiagnostics() &&
-  Clang->getDiagnostics().hasUncompilableErrorOccurred()) {
-return llvm::createStringError(
-llvm::inconvertibleErrorCode(),
-"IndexingAction failed: has uncompilable errors");
-  }
 
   assert(Index.Symbols && Index.Refs && Index.Sources &&
  "Symbols, Refs and Sources must be set.");
@@ -477,7 +489,12 @@ llvm::Error BackgroundIndex::index(tooli
   SPAN_ATTACH(Tracer, "refs", int(Index.Refs->numRefs()));
   SPAN_ATTACH(Tracer, "sources", int(Index.Sources->size()));
 
-  update(AbsolutePath, std::move(Index), DigestsSnapshot, IndexStorage);
+  bool HadErrors = Clang->hasDiagnostics() &&
+   Clang->getDiagnostics().hasUncompilableErrorOccurred();
+  update(AbsolutePath, std::move(Index), DigestsSnapshot, 

[clang-tools-extra] r365123 - [clangd] Make HadErrors part of background index's internal state

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 02:52:12 2019
New Revision: 365123

URL: http://llvm.org/viewvc/llvm-project?rev=365123&view=rev
Log:
[clangd] Make HadErrors part of background index's internal state

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365123&r1=365122&r2=365123&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4 02:52:12 2019
@@ -101,28 +101,6 @@ IncludeGraph getSubGraph(const URI &U, c
   return IG;
 }
 
-// Creates a filter to not collect index results from files with unchanged
-// digests.
-// \p FileDigests contains file digests for the current indexed files.
-decltype(SymbolCollector::Options::FileFilter)
-createFileFilter(const llvm::StringMap &FileDigests) {
-  return [&FileDigests](const SourceManager &SM, FileID FID) {
-const auto *F = SM.getFileEntryForID(FID);
-if (!F)
-  return false; // Skip invalid files.
-auto AbsPath = getCanonicalPath(F, SM);
-if (!AbsPath)
-  return false; // Skip files without absolute path.
-auto Digest = digestFile(SM, FID);
-if (!Digest)
-  return false;
-auto D = FileDigests.find(*AbsPath);
-if (D != FileDigests.end() && D->second == Digest)
-  return false; // Skip files that haven't changed.
-return true;
-  };
-}
-
 // We cannot use vfs->makeAbsolute because Cmd.FileName is either absolute or
 // relative to Cmd.Directory, which might not be the same as current working
 // directory.
@@ -274,12 +252,12 @@ void BackgroundIndex::enqueueTask(Task T
 }
 
 /// Given index results from a TU, only update symbols coming from files that
-/// are different or missing from than \p DigestsSnapshot. Also stores new 
index
-/// information on IndexStorage.
-void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
- const llvm::StringMap 
&DigestsSnapshot,
- BackgroundIndexStorage *IndexStorage,
- bool HadErrors) {
+/// are different or missing from than \p ShardVersionsSnapshot. Also stores 
new
+/// index information on IndexStorage.
+void BackgroundIndex::update(
+llvm::StringRef MainFile, IndexFileIn Index,
+const llvm::StringMap &ShardVersionsSnapshot,
+BackgroundIndexStorage *IndexStorage, bool HadErrors) {
   // Partition symbols/references into files.
   struct File {
 llvm::DenseSet Symbols;
@@ -291,18 +269,14 @@ void BackgroundIndex::update(llvm::Strin
   URIToFileCache URICache(MainFile);
   for (const auto &IndexIt : *Index.Sources) {
 const auto &IGN = IndexIt.getValue();
-// In case of failures, we only store main file of TU. That way we can 
still
-// get symbols from headers if some other TU can compile them. Note that
-// sources do not contain any information regarding missing headers, since
-// we don't even know what absolute path they should fall in.
-// FIXME: Also store contents from other files whenever the current 
contents
-// for those files are missing or if they had errors before.
-if (HadErrors && !(IGN.Flags & IncludeGraphNode::SourceFlag::IsTU))
-  continue;
+// Note that sources do not contain any information regarding missing
+// headers, since we don't even know what absolute path they should fall 
in.
 const auto AbsPath = URICache.resolve(IGN.URI);
-const auto DigestIt = DigestsSnapshot.find(AbsPath);
-// File has different contents.
-if (DigestIt == DigestsSnapshot.end() || DigestIt->getValue() != 
IGN.Digest)
+const auto DigestIt = ShardVersionsSnapshot.find(AbsPath);
+// File has different contents, or indexing was successfull this time.
+if (DigestIt == ShardVersionsSnapshot.end() ||
+DigestIt->getValue().Digest != IGN.Digest ||
+(DigestIt->getValue().HadErrors && !HadErrors))
   Files.try_emplace(AbsPath).first->getValue().Digest = IGN.Digest;
   }
   // This map is used to figure out where to store relations.
@@ -385,13 +359,17 @@ void BackgroundIndex::update(llvm::Strin
 }
 
 {
-  std::lock_guard Lock(DigestsMu);
+  std::lock_guard Lock(ShardVersionsMu);
   auto Hash = FileIt.second.Digest;
-  // Skip if file is already up to date.
-  auto DigestIt = IndexedFileDigests.try_emplace(Path);
-  if (!DigestIt.second && DigestIt.first->second == Hash)
+  auto DigestIt = ShardVersions.try_emplace(Path);
+  Sh

[clang-tools-extra] r365121 - [clangd] Store hash of command line in index shards.

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 02:51:53 2019
New Revision: 365121

URL: http://llvm.org/viewvc/llvm-project?rev=365121&view=rev
Log:
[clangd] Store hash of command line in index shards.

Summary: This is to enable cache invalidation when command line flags changes.

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365121&r1=365120&r2=365121&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4 02:51:53 2019
@@ -25,6 +25,7 @@
 #include "index/SymbolCollector.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringMap.h"
@@ -373,6 +374,11 @@ void BackgroundIndex::update(llvm::Strin
   Shard.Relations = RelS.get();
   Shard.Sources = IG.get();
 
+  // Only store command line hash for main files of the TU, since our
+  // current model keeps only one version of a header file.
+  if (Path == MainFile)
+Shard.Cmd = Index.Cmd.getPointer();
+
   if (auto Error = IndexStorage->storeShard(Path, Shard))
 elog("Failed to write background-index shard for file {0}: {1}", Path,
  std::move(Error));
@@ -479,6 +485,7 @@ llvm::Error BackgroundIndex::index(tooli
 
   Action->EndSourceFile();
 
+  Index.Cmd = Inputs.CompileCommand;
   assert(Index.Symbols && Index.Refs && Index.Sources &&
  "Symbols, Refs and Sources must be set.");
 

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=365121&r1=365120&r2=365121&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Thu Jul  4 02:51:53 
2019
@@ -13,9 +13,13 @@
 #include "SymbolOrigin.h"
 #include "Trace.h"
 #include "dex/Dex.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -403,6 +407,30 @@ Relation readRelation(Reader &Data) {
   return {Subject, Predicate, Object};
 }
 
+struct InternedCompileCommand {
+  llvm::StringRef Directory;
+  std::vector CommandLine;
+};
+
+void writeCompileCommand(const InternedCompileCommand &Cmd,
+ const StringTableOut &Strings,
+ llvm::raw_ostream &CmdOS) {
+  writeVar(Strings.index(Cmd.Directory), CmdOS);
+  writeVar(Cmd.CommandLine.size(), CmdOS);
+  for (llvm::StringRef C : Cmd.CommandLine)
+writeVar(Strings.index(C), CmdOS);
+}
+
+InternedCompileCommand
+readCompileCommand(Reader CmdReader, llvm::ArrayRef Strings) {
+  InternedCompileCommand Cmd;
+  Cmd.Directory = CmdReader.consumeString(Strings);
+  Cmd.CommandLine.resize(CmdReader.consumeVar());
+  for (llvm::StringRef &C : Cmd.CommandLine)
+C = CmdReader.consumeString(Strings);
+  return Cmd;
+}
+
 // FILE ENCODING
 // A file is a RIFF chunk with type 'CdIx'.
 // It contains the sections:
@@ -490,6 +518,18 @@ llvm::Expected readRIFF(llv
   return makeError("malformed or truncated relations");
 Result.Relations = std::move(Relations).build();
   }
+  if (Chunks.count("cmdl")) {
+Reader CmdReader(Chunks.lookup("cmdl"));
+if (CmdReader.err())
+  return makeError("malformed or truncated commandline section");
+InternedCompileCommand Cmd =
+readCompileCommand(CmdReader, Strings->Strings);
+Result.Cmd.emplace();
+Result.Cmd->Directory = Cmd.Directory;
+Result.Cmd->CommandLine.reserve(Cmd.CommandLine.size());
+for (llvm::StringRef C : Cmd.CommandLine)
+  Result.Cmd->CommandLine.emplace_back(C);
+  }
   return std::move(Result);
 }
 
@@ -547,6 +587,17 @@ void writeRIFF(const IndexFileOut &Data,
 }
   }
 
+  InternedCompileCommand InternedCmd;
+  if (Data.Cmd) {
+InternedCmd.CommandLine.reserve(Data.Cmd->CommandLine.size());
+InternedCmd.Directory = Data.Cmd->Directory;
+Strings.intern(InternedCmd.Directory);
+   

[clang-tools-extra] r365122 - [clangd] Add HadErrors field into shards

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 02:52:04 2019
New Revision: 365122

URL: http://llvm.org/viewvc/llvm-project?rev=365122&view=rev
Log:
[clangd] Add HadErrors field into shards

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/trunk/clangd/unittests/IndexActionTests.cpp
clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp

Modified: clang-tools-extra/trunk/clangd/Headers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=365122&r1=365121&r2=365122&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.h (original)
+++ clang-tools-extra/trunk/clangd/Headers.h Thu Jul  4 02:52:04 2019
@@ -62,8 +62,15 @@ llvm::raw_ostream &operator<<(llvm::raw_
 // dependencies. Doesn't own the strings it references (IncludeGraph is
 // self-contained).
 struct IncludeGraphNode {
-  // True if current file is a main file rather than a header.
-  bool IsTU = false;
+  enum class SourceFlag : uint8_t {
+None = 0,
+// Whether current file is a main file rather than a header.
+IsTU = 1 << 0,
+// Whether current file had any uncompilable errors during indexing.
+HadErrors = 1 << 1,
+  };
+
+  SourceFlag Flags = SourceFlag::None;
   llvm::StringRef URI;
   FileDigest Digest{{0}};
   std::vector DirectIncludes;
@@ -74,6 +81,22 @@ struct IncludeGraphNode {
 // edges and multi edges.
 using IncludeGraph = llvm::StringMap;
 
+inline IncludeGraphNode::SourceFlag operator|(IncludeGraphNode::SourceFlag A,
+  IncludeGraphNode::SourceFlag B) {
+  return static_cast(static_cast(A) |
+   static_cast(B));
+}
+
+inline bool operator&(IncludeGraphNode::SourceFlag A,
+  IncludeGraphNode::SourceFlag B) {
+  return static_cast(A) & static_cast(B);
+}
+
+inline IncludeGraphNode::SourceFlag &
+operator|=(IncludeGraphNode::SourceFlag &A, IncludeGraphNode::SourceFlag B) {
+  return A = A | B;
+}
+
 // Information captured about the inclusion graph in a translation unit.
 // This includes detailed information about the direct #includes, and summary
 // information about all transitive includes.

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365122&r1=365121&r2=365122&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4 02:52:04 2019
@@ -297,7 +297,7 @@ void BackgroundIndex::update(llvm::Strin
 // we don't even know what absolute path they should fall in.
 // FIXME: Also store contents from other files whenever the current 
contents
 // for those files are missing or if they had errors before.
-if (HadErrors && !IGN.IsTU)
+if (HadErrors && !(IGN.Flags & IncludeGraphNode::SourceFlag::IsTU))
   continue;
 const auto AbsPath = URICache.resolve(IGN.URI);
 const auto DigestIt = DigestsSnapshot.find(AbsPath);
@@ -498,10 +498,13 @@ llvm::Error BackgroundIndex::index(tooli
 
   bool HadErrors = Clang->hasDiagnostics() &&
Clang->getDiagnostics().hasUncompilableErrorOccurred();
+  if (HadErrors) {
+log("Failed to compile {0}, index may be incomplete", AbsolutePath);
+for (auto &It : *Index.Sources)
+  It.second.Flags |= IncludeGraphNode::SourceFlag::HadErrors;
+  }
   update(AbsolutePath, std::move(Index), DigestsSnapshot, IndexStorage,
  HadErrors);
-  if (HadErrors)
-log("Failed to compile {0}, index may be incomplete", AbsolutePath);
 
   if (BuildIndexPeriodMs > 0)
 SymbolsUpdatedSinceLastIndex = true;
@@ -581,7 +584,8 @@ BackgroundIndex::loadShard(const tooling
   SI.AbsolutePath = CurDependency.Path;
   SI.Shard = std::move(Shard);
   SI.Digest = I.getValue().Digest;
-  SI.CountReferences = I.getValue().IsTU;
+  SI.CountReferences =
+  I.getValue().Flags & IncludeGraphNode::SourceFlag::IsTU;
   IntermediateSymbols.push_back(std::move(SI));
   // Check if the source needs re-indexing.
   // Get the digest, skip it if file doesn't exist.

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=365122&r1=365121&r2=365122&view=diff
===

[PATCH] D63986: [clangd] Also cache failures while indexing

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365120: [clangd] Also cache failures while indexing 
(authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63986?vs=207484&id=208001#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63986

Files:
  clang-tools-extra/trunk/clangd/index/Background.cpp
  clang-tools-extra/trunk/clangd/index/Background.h
  clang-tools-extra/trunk/clangd/index/IndexAction.cpp
  clang-tools-extra/trunk/clangd/index/Serialization.h
  clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Index: clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
@@ -491,5 +491,40 @@
   }
 }
 
+TEST_F(BackgroundIndexTest, UncompilableFiles) {
+  MockFSProvider FS;
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Idx(Context::empty(), FS, CDB,
+  [&](llvm::StringRef) { return &MSS; });
+
+  tooling::CompileCommand Cmd;
+  FS.Files[testPath("A.h")] = "void foo();";
+  FS.Files[testPath("B.h")] = "#include \"C.h\"\nasdf;";
+  FS.Files[testPath("C.h")] = "";
+  FS.Files[testPath("A.cc")] = R"cpp(
+  #include "A.h"
+  #include "B.h"
+  #include "not_found_header.h"
+
+  void foo() {}
+  )cpp";
+  Cmd.Filename = "../A.cc";
+  Cmd.Directory = testPath("build");
+  Cmd.CommandLine = {"clang++", "../A.cc"};
+  CDB.setCompileCommand(testPath("build/../A.cc"), Cmd);
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
+
+  // Make sure we only store the shard for main file.
+  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc")));
+  auto Shard = MSS.loadShard(testPath("A.cc"));
+  EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
+  EXPECT_THAT(Shard->Sources->keys(),
+  UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
+   "unittest:///B.h"));
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/index/Background.h
===
--- clang-tools-extra/trunk/clangd/index/Background.h
+++ clang-tools-extra/trunk/clangd/index/Background.h
@@ -98,7 +98,7 @@
   /// information on IndexStorage.
   void update(llvm::StringRef MainFile, IndexFileIn Index,
   const llvm::StringMap &DigestsSnapshot,
-  BackgroundIndexStorage *IndexStorage);
+  BackgroundIndexStorage *IndexStorage, bool HadErrors);
 
   // configuration
   const FileSystemProvider &FSProvider;
Index: clang-tools-extra/trunk/clangd/index/Serialization.h
===
--- clang-tools-extra/trunk/clangd/index/Serialization.h
+++ clang-tools-extra/trunk/clangd/index/Serialization.h
@@ -62,7 +62,8 @@
   IndexFileOut(const IndexFileIn &I)
   : Symbols(I.Symbols ? I.Symbols.getPointer() : nullptr),
 Refs(I.Refs ? I.Refs.getPointer() : nullptr),
-Relations(I.Relations ? I.Relations.getPointer() : nullptr) {}
+Relations(I.Relations ? I.Relations.getPointer() : nullptr),
+Sources(I.Sources ? I.Sources.getPointer() : nullptr) {}
 };
 // Serializes an index file.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const IndexFileOut &O);
Index: clang-tools-extra/trunk/clangd/index/Background.cpp
===
--- clang-tools-extra/trunk/clangd/index/Background.cpp
+++ clang-tools-extra/trunk/clangd/index/Background.cpp
@@ -9,7 +9,9 @@
 #include "index/Background.h"
 #include "ClangdUnit.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Logger.h"
+#include "Path.h"
 #include "SourceCode.h"
 #include "Symbol.h"
 #include "Threading.h"
@@ -17,6 +19,8 @@
 #include "URI.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
+#include "index/Ref.h"
+#include "index/Relation.h"
 #include "index/Serialization.h"
 #include "index/SymbolCollector.h"
 #include "clang/Basic/SourceLocation.h"
@@ -25,6 +29,8 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/Threading.h"
 
@@ -271,7 +277,8 @@
 /// information on IndexStorage.
 void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
  const llvm::StringMap &DigestsSnapshot,
- BackgroundIndexStorage *IndexStorage) {
+ BackgroundIndexStora

[PATCH] D63920: [CTU] Add support for virtual functions

2019-07-04 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 208002.
martong added a comment.

- Remove ipa mode from the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63920

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/Inputs/ctu-other.cpp
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  clang/test/Analysis/ctu-main.cpp

Index: clang/test/Analysis/ctu-main.cpp
===
--- clang/test/Analysis/ctu-main.cpp
+++ clang/test/Analysis/ctu-main.cpp
@@ -45,6 +45,7 @@
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -53,6 +54,11 @@
   };
 };
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
 namespace chns {
 int chf1(int x);
 }
@@ -98,6 +104,14 @@
 };
 extern U extU;
 
+void test_virtual_functions(mycls* obj) {
+  // The dynamic type is known.
+  clang_analyzer_eval(mycls().fvcl(1) == 8);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
+  // We cannot decide about the dynamic type.
+  clang_analyzer_eval(obj->fvcl(1) == 8);  // expected-warning{{FALSE}} expected-warning{{TRUE}}
+}
+
 int main() {
   clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
   clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -116,7 +130,7 @@
   clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
 
   clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
-  // expected-warning@Inputs/ctu-other.cpp:80{{REACHABLE}}
+  // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
   MACRODIAG(); // expected-warning{{REACHABLE}}
 
   clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}
Index: clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
===
--- clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
+++ clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
@@ -3,8 +3,10 @@
 c:@F@g#I# ctu-other.cpp.ast
 c:@S@mycls@F@fscl#I#S ctu-other.cpp.ast
 c:@S@mycls@F@fcl#I# ctu-other.cpp.ast
+c:@S@mycls@F@fvcl#I# ctu-other.cpp.ast
 c:@N@myns@S@embed_cls@F@fecl#I# ctu-other.cpp.ast
 c:@S@mycls@S@embed_cls2@F@fecl2#I# ctu-other.cpp.ast
+c:@S@derived@F@fvcl#I# ctu-other.cpp.ast
 c:@F@f#I# ctu-other.cpp.ast
 c:@N@myns@F@fns#I# ctu-other.cpp.ast
 c:@F@h#I# ctu-other.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-other.cpp
===
--- clang/test/Analysis/Inputs/ctu-other.cpp
+++ clang/test/Analysis/Inputs/ctu-other.cpp
@@ -38,6 +38,7 @@
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -49,6 +50,9 @@
 int mycls::fcl(int x) {
   return x + 5;
 }
+int mycls::fvcl(int x) {
+  return x + 7;
+}
 int mycls::fscl(int x) {
   return x + 6;
 }
@@ -56,6 +60,15 @@
   return x - 11;
 }
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
+int derived::fvcl(int x) {
+  return x + 8;
+}
+
 namespace chns {
 int chf2(int x);
 
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -755,8 +755,11 @@
 
   // Does the decl that we found have an implementation?
   const FunctionDecl *Definition;
-  if (!Result->hasBody(Definition))
+  if (!Result->hasBody(Definition)) {
+if (!DynType.canBeASubClass())
+  return AnyFunctionCall::getRuntimeDefinition();
 return {};
+  }
 
   // We found a definition. If we're not sure that this devirtualization is
   // actually what will happen at runtime, make sure to provide the region so
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64133: [clangd] Add HadErrors field into shards

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365122: [clangd] Add HadErrors field into shards (authored 
by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64133?vs=207832&id=208004#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64133

Files:
  clang-tools-extra/trunk/clangd/Headers.h
  clang-tools-extra/trunk/clangd/index/Background.cpp
  clang-tools-extra/trunk/clangd/index/IndexAction.cpp
  clang-tools-extra/trunk/clangd/index/Serialization.cpp
  clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/trunk/clangd/unittests/IndexActionTests.cpp
  clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp

Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp
===
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Serialization.h"
+#include "Headers.h"
 #include "Logger.h"
 #include "RIFF.h"
 #include "SymbolLocation.h"
@@ -278,7 +279,7 @@
 IncludeGraphNode readIncludeGraphNode(Reader &Data,
   llvm::ArrayRef Strings) {
   IncludeGraphNode IGN;
-  IGN.IsTU = Data.consume8();
+  IGN.Flags = static_cast(Data.consume8());
   IGN.URI = Data.consumeString(Strings);
   llvm::StringRef Digest = Data.consume(IGN.Digest.size());
   std::copy(Digest.bytes_begin(), Digest.bytes_end(), IGN.Digest.begin());
@@ -291,7 +292,7 @@
 void writeIncludeGraphNode(const IncludeGraphNode &IGN,
const StringTableOut &Strings,
llvm::raw_ostream &OS) {
-  OS.write(IGN.IsTU);
+  OS.write(static_cast(IGN.Flags));
   writeVar(Strings.index(IGN.URI), OS);
   llvm::StringRef Hash(reinterpret_cast(IGN.Digest.data()),
IGN.Digest.size());
@@ -443,7 +444,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 10;
+constexpr static uint32_t Version = 11;
 
 llvm::Expected readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);
Index: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
===
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "IndexAction.h"
+#include "Headers.h"
 #include "Logger.h"
 #include "index/Relation.h"
 #include "index/SymbolOrigin.h"
@@ -67,7 +68,8 @@
 }
 if (auto Digest = digestFile(SM, FileID))
   Node.Digest = std::move(*Digest);
-Node.IsTU = FileID == SM.getMainFileID();
+if (FileID == SM.getMainFileID())
+  Node.Flags |= IncludeGraphNode::SourceFlag::IsTU;
 Node.URI = I->getKey();
   }
 
Index: clang-tools-extra/trunk/clangd/index/Background.cpp
===
--- clang-tools-extra/trunk/clangd/index/Background.cpp
+++ clang-tools-extra/trunk/clangd/index/Background.cpp
@@ -297,7 +297,7 @@
 // we don't even know what absolute path they should fall in.
 // FIXME: Also store contents from other files whenever the current contents
 // for those files are missing or if they had errors before.
-if (HadErrors && !IGN.IsTU)
+if (HadErrors && !(IGN.Flags & IncludeGraphNode::SourceFlag::IsTU))
   continue;
 const auto AbsPath = URICache.resolve(IGN.URI);
 const auto DigestIt = DigestsSnapshot.find(AbsPath);
@@ -498,10 +498,13 @@
 
   bool HadErrors = Clang->hasDiagnostics() &&
Clang->getDiagnostics().hasUncompilableErrorOccurred();
+  if (HadErrors) {
+log("Failed to compile {0}, index may be incomplete", AbsolutePath);
+for (auto &It : *Index.Sources)
+  It.second.Flags |= IncludeGraphNode::SourceFlag::HadErrors;
+  }
   update(AbsolutePath, std::move(Index), DigestsSnapshot, IndexStorage,
  HadErrors);
-  if (HadErrors)
-log("Failed to compile {0}, index may be incomplete", AbsolutePath);
 
   if (BuildIndexPeriodMs > 0)
 SymbolsUpdatedSinceLastIndex = true;
@@ -581,7 +584,8 @@
   SI.AbsolutePath = CurDependency.Path;
   SI.Shard = std::move(Shard);
   SI.Digest = I.getValue().Digest;
-  SI.CountReferences = I.getValue().IsTU;
+  SI.CountReferences =
+  I.getValue().Flags & IncludeGraphNode::SourceFlag::IsTU;
   IntermediateSymbols.push_back(std::move(SI));
  

[PATCH] D64018: [clangd] Store hash of command line in index shards.

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365121: [clangd] Store hash of command line in index shards. 
(authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64018?vs=207721&id=208003#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64018

Files:
  clang-tools-extra/trunk/clangd/index/Background.cpp
  clang-tools-extra/trunk/clangd/index/Serialization.cpp
  clang-tools-extra/trunk/clangd/index/Serialization.h
  clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp

Index: clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp
@@ -8,6 +8,7 @@
 
 #include "index/Index.h"
 #include "index/Serialization.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock.h"
@@ -240,6 +241,36 @@
   }
 }
 
+TEST(SerializationTest, CmdlTest) {
+  auto In = readIndexFile(YAML);
+  EXPECT_TRUE(bool(In)) << In.takeError();
+
+  tooling::CompileCommand Cmd;
+  Cmd.Directory = "testdir";
+  Cmd.CommandLine.push_back("cmd1");
+  Cmd.CommandLine.push_back("cmd2");
+  Cmd.Filename = "ignored";
+  Cmd.Heuristic = "ignored";
+  Cmd.Output = "ignored";
+
+  IndexFileOut Out(*In);
+  Out.Format = IndexFileFormat::RIFF;
+  Out.Cmd = &Cmd;
+  {
+std::string Serialized = llvm::to_string(Out);
+
+auto In = readIndexFile(Serialized);
+ASSERT_TRUE(bool(In)) << In.takeError();
+ASSERT_TRUE(In->Cmd);
+
+const tooling::CompileCommand &SerializedCmd = In->Cmd.getValue();
+EXPECT_EQ(SerializedCmd.CommandLine, Cmd.CommandLine);
+EXPECT_EQ(SerializedCmd.Directory, Cmd.Directory);
+EXPECT_NE(SerializedCmd.Filename, Cmd.Filename);
+EXPECT_NE(SerializedCmd.Heuristic, Cmd.Heuristic);
+EXPECT_NE(SerializedCmd.Output, Cmd.Output);
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
@@ -2,6 +2,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "index/Background.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Threading.h"
 #include "gmock/gmock.h"
@@ -526,5 +527,49 @@
"unittest:///B.h"));
 }
 
+TEST_F(BackgroundIndexTest, CmdLineHash) {
+  MockFSProvider FS;
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr, /*FallbackFlags=*/{},
+ /*ResourceDir=*/std::string(""));
+  BackgroundIndex Idx(Context::empty(), FS, CDB,
+  [&](llvm::StringRef) { return &MSS; });
+
+  tooling::CompileCommand Cmd;
+  FS.Files[testPath("A.cc")] = "#include \"A.h\"";
+  FS.Files[testPath("A.h")] = "";
+  Cmd.Filename = "../A.cc";
+  Cmd.Directory = testPath("build");
+  Cmd.CommandLine = {"clang++", "../A.cc", "-fsyntax-only"};
+  CDB.setCompileCommand(testPath("build/../A.cc"), Cmd);
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
+
+  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc"), testPath("A.h")));
+  // Make sure we only store the Cmd for main file.
+  EXPECT_FALSE(MSS.loadShard(testPath("A.h"))->Cmd);
+
+  {
+tooling::CompileCommand CmdStored = *MSS.loadShard(testPath("A.cc"))->Cmd;
+EXPECT_EQ(CmdStored.CommandLine, Cmd.CommandLine);
+EXPECT_EQ(CmdStored.Directory, Cmd.Directory);
+  }
+
+  // FIXME: Changing compile commands should be enough to invalidate the cache.
+  FS.Files[testPath("A.cc")] = " ";
+  Cmd.CommandLine = {"clang++", "../A.cc", "-Dfoo", "-fsyntax-only"};
+  CDB.setCompileCommand(testPath("build/../A.cc"), Cmd);
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
+
+  EXPECT_FALSE(MSS.loadShard(testPath("A.h"))->Cmd);
+
+  {
+tooling::CompileCommand CmdStored = *MSS.loadShard(testPath("A.cc"))->Cmd;
+EXPECT_EQ(CmdStored.CommandLine, Cmd.CommandLine);
+EXPECT_EQ(CmdStored.Directory, Cmd.Directory);
+  }
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp
===
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp
@@ -13,9 +13,13 @@
 #include "SymbolOrigin.h"
 #include "Trace.h"
 #include "dex/Dex

[PATCH] D64147: [clangd] Make HadErrors part of background index's internal state

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365123: [clangd] Make HadErrors part of background 
index's internal state (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64147?vs=207986&id=208005#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64147

Files:
  clang-tools-extra/trunk/clangd/index/Background.cpp
  clang-tools-extra/trunk/clangd/index/Background.h
  clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Index: clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
@@ -524,18 +524,41 @@
   CDB.setCompileCommand(testPath("build/../A.cc"), Cmd);
   ASSERT_TRUE(Idx.blockUntilIdleForTest());
 
-  // Make sure we only store the shard for main file.
-  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc")));
-  auto Shard = MSS.loadShard(testPath("A.cc"));
-  EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
-  EXPECT_THAT(Shard->Sources->keys(),
-  UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
-   "unittest:///B.h"));
-
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), HadErrors());
-  // FIXME: We should also persist headers while marking them with errors.
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), Not(HadErrors()));
-  EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), Not(HadErrors()));
+  EXPECT_THAT(Storage.keys(), ElementsAre(testPath("A.cc"), testPath("A.h"),
+  testPath("B.h"), testPath("C.h")));
+
+  {
+auto Shard = MSS.loadShard(testPath("A.cc"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///A.cc", "unittest:///A.h",
+ "unittest:///B.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///A.cc"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("A.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("foo")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///A.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///A.h"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("B.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(Named("asdf")));
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///B.h", "unittest:///C.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///B.h"), HadErrors());
+  }
+
+  {
+auto Shard = MSS.loadShard(testPath("C.h"));
+EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre());
+EXPECT_THAT(Shard->Sources->keys(),
+UnorderedElementsAre("unittest:///C.h"));
+EXPECT_THAT(Shard->Sources->lookup("unittest:///C.h"), HadErrors());
+  }
 }
 
 TEST_F(BackgroundIndexTest, CmdLineHash) {
Index: clang-tools-extra/trunk/clangd/index/Background.cpp
===
--- clang-tools-extra/trunk/clangd/index/Background.cpp
+++ clang-tools-extra/trunk/clangd/index/Background.cpp
@@ -101,28 +101,6 @@
   return IG;
 }
 
-// Creates a filter to not collect index results from files with unchanged
-// digests.
-// \p FileDigests contains file digests for the current indexed files.
-decltype(SymbolCollector::Options::FileFilter)
-createFileFilter(const llvm::StringMap &FileDigests) {
-  return [&FileDigests](const SourceManager &SM, FileID FID) {
-const auto *F = SM.getFileEntryForID(FID);
-if (!F)
-  return false; // Skip invalid files.
-auto AbsPath = getCanonicalPath(F, SM);
-if (!AbsPath)
-  return false; // Skip files without absolute path.
-auto Digest = digestFile(SM, FID);
-if (!Digest)
-  return false;
-auto D = FileDigests.find(*AbsPath);
-if (D != FileDigests.end() && D->second == Digest)
-  return false; // Skip files that haven't changed.
-return true;
-  };
-}
-
 // We cannot use vfs->makeAbsolute because Cmd.FileName is either absolute or
 // relative to Cmd.Directory, which might not be the same as current working
 // directory.
@@ -274,12 +252,12 @@
 }
 
 /// Given index results from a TU, only update symbols coming from files that
-/// are different or missing from than \p DigestsSnapshot. Also stores new index
-/// information on IndexStorage.
-void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
- const llvm::StringMap &DigestsSnapshot,
- BackgroundIndexStorage *

[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Added highlighting for variable references using VisitDeclRefExpr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64199

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,18 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -35,25 +35,31 @@
   }
 
   bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+addNamedDecl(Var, HighlightingKind::Variable);
 return true;
   }
   bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+addNamedDecl(Func, HighlightingKind::Function);
+return true;
+  }
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  // Don't want to highlight operators.
+  return true;
+
+addToken(Ref->getLocation(), HighlightingKind::Variable);
 return true;
   }
 
 private:
-  void addToken(const NamedDecl *D, HighlightingKind Kind) {
-if (D->getLocation().isMacroID())
+  void addToken(SourceLocation Loc, HighlightingKind Kind) {
+if (Loc.isMacroID())
   // FIXME: skip tokens inside macros for now.
   return;
 
-if (D->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
-  return;
-
-auto R = getTokenRange(SM, Ctx.getLangOpts(), D->getLocation());
+auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {
   // R should always have a value, if it doesn't something is very wrong.
   elog("Tried to add semantic token with an invalid range");
@@ -62,6 +68,13 @@
 
 Tokens.push_back({Kind, R.getValue()});
   }
+
+  void addNamedDecl(const NamedDecl *D, HighlightingKind Kind) {
+if (D->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return;
+addToken(D->getLocation(), Kind);
+  }
 };
 
 // Encode binary data into base64.


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,18 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -35,25 +35,31 @@
   }
 
   bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+addNamedDecl(Var, HighlightingKind::Variable);
 return true;
   }
   bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+addNamedDecl(Func, HighlightingKind::Function);
+return true;
+  }
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  // Don't want to highlight operators.
+  return true;
+
+addToken(Ref->getLocation(), HighlightingKind::Variable);
 return true;
   }
 
 private:
-  void ad

[clang-tools-extra] r365124 - [clangd] Turn background-index on by default

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 02:56:24 2019
New Revision: 365124

URL: http://llvm.org/viewvc/llvm-project?rev=365124&view=rev
Log:
[clangd] Turn background-index on by default

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=365124&r1=365123&r2=365124&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Jul  4 02:56:24 2019
@@ -189,7 +189,7 @@ static llvm::cl::opt EnableBackgro
 llvm::cl::desc(
 "Index project code in the background and persist index on disk. "
 "Experimental"),
-llvm::cl::init(false), llvm::cl::Hidden);
+llvm::cl::init(true));
 
 static llvm::cl::opt BackgroundIndexRebuildPeriod(
 "background-index-rebuild-period",


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


[PATCH] D63920: [CTU] Add support for virtual functions

2019-07-04 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63920



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


[PATCH] D63920: [CTU] Add support for virtual functions

2019-07-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63920



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


[PATCH] D64137: [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 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: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:16
+
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  static const auto& TextMateLookupTable = getTextMateScopeLookupTable();

can we move this to SemanticHighlighting.h, and define 
getTextMateScopeLookupTable() in terms of it? It seems much more fundamental.



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:53
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+  auto CleanupTask = llvm::make_scope_exit(

This needs a comment



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:59
+  {const_cast(InterestedDecl)});
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  auto &SM = Inputs.AST.getSourceManager();

nit: can you give the overridden traversal scope as narrow a scope as possible? 
(put it in a block, or just reset explicitly immediately afterwards?) I'm a 
little paranoid about this scope being reused.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64137



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


[PATCH] D64019: [clangd] Turn background-index on by default

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365124: [clangd] Turn background-index on by default 
(authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64019?vs=207346&id=208007#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64019

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -189,7 +189,7 @@
 llvm::cl::desc(
 "Index project code in the background and persist index on disk. "
 "Experimental"),
-llvm::cl::init(false), llvm::cl::Hidden);
+llvm::cl::init(true));
 
 static llvm::cl::opt BackgroundIndexRebuildPeriod(
 "background-index-rebuild-period",


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -189,7 +189,7 @@
 llvm::cl::desc(
 "Index project code in the background and persist index on disk. "
 "Experimental"),
-llvm::cl::init(false), llvm::cl::Hidden);
+llvm::cl::init(true));
 
 static llvm::cl::opt BackgroundIndexRebuildPeriod(
 "background-index-rebuild-period",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63936: [clang][Driver][ARM] Favor -mfpu over default CPU features

2019-07-04 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea added inline comments.



Comment at: llvm/lib/Support/ARMTargetParser.cpp:412
 
-  if (Extensions & AEK_CRC)
-Features.push_back("+crc");
-  else
-Features.push_back("-crc");
-
-  if (Extensions & AEK_DSP)
-Features.push_back("+dsp");
-  else
-Features.push_back("-dsp");
-
-  if (Extensions & AEK_FP16FML)
-Features.push_back("+fp16fml");
-  else
-Features.push_back("-fp16fml");
-
-  if (Extensions & AEK_RAS)
-Features.push_back("+ras");
-  else
-Features.push_back("-ras");
-
-  if (Extensions & AEK_DOTPROD)
-Features.push_back("+dotprod");
-  else
-Features.push_back("-dotprod");
+  for (const auto AE : ARCHExtNames) {
+if ((Extensions & AE.ID) == AE.ID && AE.Feature)

ostannard wrote:
> labrinea wrote:
> > ostannard wrote:
> > > labrinea wrote:
> > > > SjoerdMeijer wrote:
> > > > > This could be a little local helper function, share the code, as 
> > > > > exactly the same is done in `ARM::appendArchExtFeatures`
> > > > We are not doing exactly the same thing in these functions. Here we 
> > > > extract features out of a bitmap, which is a map containing a bitwise 
> > > > OR of separate feature bitmasks. If a bitmask that corresponds to a 
> > > > known feature is present - and here I mean all the bits of that mask 
> > > > are present - then we push the feature, otherwise not. 
> > > > 
> > > > In `ARM::appendArchExtFeatures` we compare a given bitmask, which 
> > > > corresponds to a specific feature, against all the known bitmasks 
> > > > (individual features) one by one. In contrast to 
> > > > `ARM::getExtensionFeatures` here we also handle negative features, and 
> > > > that means the prohibition of a feature can disable other features that 
> > > > depend on it as well.
> > > Does this correctly handle the combination of integer-only MVE with a 
> > > scalar FPU? I think -march=...+mve+fp should enable AEK_FP and AEK_SIMD 
> > > (+mve), but shouldn't enable +mve.fp.
> > The target features explicitly specified on the command line are handled by 
> > `ARM::appendArchExtFeatures` (see [[ https://reviews.llvm.org/D64048 | 
> > D64048 ]]). That said, yes, -march=...+mve+fp does enable scalar floating 
> > point and integer-only mve, but doesn't enable mve with floating point. I 
> > could possibly add such a test on that revision.
> > 
> > On the other hand, `ARM::getExtensionFeatures` cannot tell the difference 
> > between the two configurations you describe, and it's not possible to do 
> > so, because they are represented on a bitmap returned from 
> > `ARM::getDefaultExtensions`, which reads the table. That said, if there was 
> > an entry in the table containing `AEK_FP | AEK_SIMD` that would enable 
> > mve.fp. However, I don't think this is a problem in practice. My 
> > understanding is that the table indicates FPU support with `FK_*`, and 
> > Extension support with `AEK_*`.  That said, I believe AEK_FP is only used 
> > for command line option handling.
> > 
> > Maybe a fix for this problem would be to replace `AEK_FP | AEK_SIMD` with 
> > something like `AEK_MVE_FP` but then we wouldn't be able to do what is 
> > proposed in [[ https://reviews.llvm.org/D64048 | D64048 ]].
> Is this system (in particular the behaviour added in D64048) going to be able 
> to handle all of the other dependencies between architectural features? For 
> example, MVE also depends on the DSP extension, but 
> `-march=armv8.1-m.main+mve+nodsp` currently defines both __ARM_FEATURE_MVE 
> and __ARM_FEATURE_DSP.
No, `-march=armv8.1-m.main+mve+nodsp` doesn't turn off neither mve nor dsp and 
it looks like a bug if they depend on each other. It seems you are right, the 
code in `ARMTargetInfo::handleTargetFeatures` enables both when mve is set:

```
} else if (Feature == "+mve") {
  DSP = 1;
  MVE |= MVE_INT;
} else if (Feature == "+mve.fp") {
  DSP = 1;
  HasLegalHalfType = true;
  FPU |= FPARMV8;
  MVE |= MVE_INT | MVE_FP;
  HW_FP |= HW_FP_SP | HW_FP_HP;
}
```
If there's a dependency then it should be present in the table of target 
parser. Then the above command would turn both off. I'll update the table and 
add some tests in [[ https://reviews.llvm.org/D64048 | D64048 ]].


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63936



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


r365126 - Fix -Wdocumentation warning.

2019-07-04 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Jul  4 03:28:31 2019
New Revision: 365126

URL: http://llvm.org/viewvc/llvm-project?rev=365126&view=rev
Log:
Fix -Wdocumentation warning.

Modified:
cfe/trunk/include/clang/AST/ASTImporter.h

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=365126&r1=365125&r2=365126&view=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Thu Jul  4 03:28:31 2019
@@ -300,7 +300,7 @@ class TypeSourceInfo;
 /// as little as it can, e.g., by importing declarations as forward
 /// declarations that can be completed at a later point.
 ///
-/// \param LookupTable The importer specific lookup table which may be
+/// \param SharedState The importer specific lookup table which may be
 /// shared amongst several ASTImporter objects.
 /// If not set then the original C/C++ lookup is used.
 ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,


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


[PATCH] D64048: [TargetParser][ARM] Account dependencies when processing target features

2019-07-04 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea updated this revision to Diff 208010.
labrinea added a comment.

Added the dependency of mve on dsp and some missing tests to cover those cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64048

Files:
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/ARMTargetParser.cpp

Index: llvm/lib/Support/ARMTargetParser.cpp
===
--- llvm/lib/Support/ARMTargetParser.cpp
+++ llvm/lib/Support/ARMTargetParser.cpp
@@ -508,16 +508,30 @@
   return ARM::FK_INVALID;
 }
 
+static unsigned getAEKID(StringRef ArchExtName) {
+  for (const auto AE : ARM::ARCHExtNames)
+if (AE.getName() == ArchExtName)
+  return AE.ID;
+  return ARM::AEK_INVALID;
+}
+
 bool ARM::appendArchExtFeatures(
   StringRef CPU, ARM::ArchKind AK, StringRef ArchExt,
   std::vector &Features) {
-  StringRef StandardFeature = getArchExtFeature(ArchExt);
-  if (!StandardFeature.empty()) {
-Features.push_back(StandardFeature);
-return true;
-  }
 
+  size_t StartingNumFeatures = Features.size();
   const bool Negated = stripNegationPrefix(ArchExt);
+  unsigned ID = getAEKID(ArchExt);
+
+  if (ID == AEK_INVALID)
+return false;
+
+  for (const auto AE : ARCHExtNames) {
+if (Negated && (AE.ID & ID) == ID && AE.NegFeature)
+  Features.push_back(AE.NegFeature);
+else if (AE.ID == ID && AE.Feature)
+  Features.push_back(AE.Feature);
+  }
 
   if (CPU == "")
 CPU = "generic";
@@ -537,7 +551,7 @@
 }
 return ARM::getFPUFeatures(FPUKind, Features);
   }
-  return false;
+  return StartingNumFeatures != Features.size();
 }
 
 StringRef ARM::getHWDivName(unsigned HWDivKind) {
Index: llvm/include/llvm/Support/ARMTargetParser.def
===
--- llvm/include/llvm/Support/ARMTargetParser.def
+++ llvm/include/llvm/Support/ARMTargetParser.def
@@ -148,8 +148,8 @@
 ARM_ARCH_EXT_NAME("dotprod",  ARM::AEK_DOTPROD,  "+dotprod","-dotprod")
 ARM_ARCH_EXT_NAME("dsp",  ARM::AEK_DSP,  "+dsp",   "-dsp")
 ARM_ARCH_EXT_NAME("fp",   ARM::AEK_FP,   nullptr,  nullptr)
-ARM_ARCH_EXT_NAME("mve",  ARM::AEK_SIMD, "+mve",   "-mve")
-ARM_ARCH_EXT_NAME("mve.fp",   (ARM::AEK_SIMD | ARM::AEK_FP), "+mve.fp", "-mve.fp")
+ARM_ARCH_EXT_NAME("mve", (ARM::AEK_DSP | ARM::AEK_SIMD), "+mve", "-mve")
+ARM_ARCH_EXT_NAME("mve.fp",  (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP), "+mve.fp", "-mve.fp")
 ARM_ARCH_EXT_NAME("idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB), nullptr, nullptr)
 ARM_ARCH_EXT_NAME("mp",   ARM::AEK_MP,   nullptr,  nullptr)
 ARM_ARCH_EXT_NAME("simd", ARM::AEK_SIMD, nullptr,  nullptr)
Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -762,12 +762,29 @@
 // CHECK-V81M-MVE: #define __ARM_FEATURE_MVE 1
 // CHECK-V81M-MVE: #define __ARM_FEATURE_SIMD32 1
 
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_DSP 1
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 3
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_SIMD32 1
-// CHECK-V81M-MVE-FP: #define __ARM_FPV5__ 1
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP %s
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_DSP 1
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_MVE 3
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_SIMD32 1
+// CHECK-V81M-MVEFP: #define __ARM_FPV5__ 1
+
+// nofp discards mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nofp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOFP %s
+// CHECK-V81M-MVEFP-NOFP-NOT: #define __ARM_FEATURE_MVE
+
+// nomve discards mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nomve -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOMVE %s
+// CHECK-V81M-MVEFP-NOMVE-NOT: #define __ARM_FEATURE_MVE
+
+// mve+fp doesn't imply mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s
+// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 1
+
+// nodsp discards both dsp and mve
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+nodsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-NODSP %s
+// CHECK-V81M-MVE-NODSP-NOT: #define

[PATCH] D64137: [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 208012.
hokein marked 4 inline comments as done.
hokein added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64137

Files:
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -278,6 +278,14 @@
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
 
+TEST(TweakTest, AnnotateHighlightings) {
+  llvm::StringLiteral ID = "AnnotateHighlightings";
+  checkAvailable(ID, "^vo^id^ ^f(^) {^}^"); // available everywhere.
+  const char *Input = "void ^f() {}";
+  const char *Output = "void /* entity.name.function.cpp */f() {}";
+  checkTransform(ID, Input, Output);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
===
--- clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -12,6 +12,7 @@
 # $ to a list of sources, see
 # clangd/tool/CMakeLists.txt for an example.
 add_clang_library(clangDaemonTweaks OBJECT
+  AnnotateHighlightings.cpp
   DumpAST.cpp
   RawStringLiteral.cpp
   SwapIfBranches.cpp
Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -0,0 +1,83 @@
+//===--- AnnotateHighlightings.cpp ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticHighlighting.h"
+#include "refactor/Tweak.h"
+#include "llvm/ADT/ScopeExit.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// FIXME: move it to SemanticHighlighting.h.
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
+  auto LookupIndex = static_cast(Kind);
+  assert(LookupIndex < TextMateLookupTable.size() &&
+ !TextMateLookupTable[LookupIndex].empty());
+  return TextMateLookupTable[LookupIndex].front();
+}
+
+/// Annotate all highlighting tokens in the current file. This is a hidden tweak
+/// which is used to debug semantic highlightings.
+/// Before:
+///   void f() { int abc; }
+///   ^
+/// After:
+///   void /* entity.name.function.cpp */ f() { int /* variable.cpp */ abc; }
+class AnnotateHighlightings : public Tweak {
+public:
+  const char *id() const override final;
+
+  bool prepare(const Selection &Inputs) override {
+for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
+ N = N->Parent)
+  InterestedDecl = N->ASTNode.get();
+return InterestedDecl;
+  }
+  Expected apply(const Selection &Inputs) override;
+
+  std::string title() const override { return "Annotate highlighting tokens"; }
+  Intent intent() const override { return Refactor; }
+  bool hidden() const override { return true; }
+
+private:
+  const Decl *InterestedDecl = nullptr;
+};
+REGISTER_TWEAK(AnnotateHighlightings)
+
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  // Store the existing scopes.
+  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+  // Narrow the traversal scope to the selected node.
+  Inputs.AST.getASTContext().setTraversalScope(
+  {const_cast(InterestedDecl)});
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  // Restore the traversal scope.
+  Inputs.AST.getASTContext().setTraversalScope(BackupScopes);
+
+  auto &SM = Inputs.AST.getSourceManager();
+  tooling::Replacements Result;
+  for (const auto &Token : HighlightingTokens) {
+assert(Token.R.start.line == Token.R.end.line &&
+   "Token must be at the same line");
+auto InsertOffset = positionToOffset(Inputs.Code, Token.R.start);
+if (!InsertOffset)
+  return InsertOffset.takeError();
+
+auto InsertReplacement = tooling::Replacement(
+SM.getFileEntryForID(SM.getMainFileID())->getName(), *InsertOffset, 0,
+("/* " + toTextMateScope(Token.Kind) + " */").str());
+if (auto Err = Result.add(InsertReplacement))
+  return std::move(Err);
+  }
+  return Effect::applyEdit(Result);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace 

[clang-tools-extra] r365130 - [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Jul  4 03:49:32 2019
New Revision: 365130

URL: http://llvm.org/viewvc/llvm-project?rev=365130&view=rev
Log:
[clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

Reviewers: sammccall, jvikstrom

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

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
Modified:
clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Added: clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp?rev=365130&view=auto
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp 
(added)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp 
Thu Jul  4 03:49:32 2019
@@ -0,0 +1,82 @@
+//===--- AnnotateHighlightings.cpp ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticHighlighting.h"
+#include "refactor/Tweak.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// FIXME: move it to SemanticHighlighting.h.
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
+  auto LookupIndex = static_cast(Kind);
+  assert(LookupIndex < TextMateLookupTable.size() &&
+ !TextMateLookupTable[LookupIndex].empty());
+  return TextMateLookupTable[LookupIndex].front();
+}
+
+/// Annotate all highlighting tokens in the current file. This is a hidden 
tweak
+/// which is used to debug semantic highlightings.
+/// Before:
+///   void f() { int abc; }
+///   ^
+/// After:
+///   void /* entity.name.function.cpp */ f() { int /* variable.cpp */ abc; }
+class AnnotateHighlightings : public Tweak {
+public:
+  const char *id() const override final;
+
+  bool prepare(const Selection &Inputs) override {
+for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
+ N = N->Parent)
+  InterestedDecl = N->ASTNode.get();
+return InterestedDecl;
+  }
+  Expected apply(const Selection &Inputs) override;
+
+  std::string title() const override { return "Annotate highlighting tokens"; }
+  Intent intent() const override { return Refactor; }
+  bool hidden() const override { return true; }
+
+private:
+  const Decl *InterestedDecl = nullptr;
+};
+REGISTER_TWEAK(AnnotateHighlightings)
+
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  // Store the existing scopes.
+  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+  // Narrow the traversal scope to the selected node.
+  Inputs.AST.getASTContext().setTraversalScope(
+  {const_cast(InterestedDecl)});
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  // Restore the traversal scope.
+  Inputs.AST.getASTContext().setTraversalScope(BackupScopes);
+
+  auto &SM = Inputs.AST.getSourceManager();
+  tooling::Replacements Result;
+  for (const auto &Token : HighlightingTokens) {
+assert(Token.R.start.line == Token.R.end.line &&
+   "Token must be at the same line");
+auto InsertOffset = positionToOffset(Inputs.Code, Token.R.start);
+if (!InsertOffset)
+  return InsertOffset.takeError();
+
+auto InsertReplacement = tooling::Replacement(
+SM.getFileEntryForID(SM.getMainFileID())->getName(), *InsertOffset, 0,
+("/* " + toTextMateScope(Token.Kind) + " */").str());
+if (auto Err = Result.add(InsertReplacement))
+  return std::move(Err);
+  }
+  return Effect::applyEdit(Result);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang

Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt?rev=365130&r1=365129&r2=365130&view=diff
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt Thu Jul  4 
03:49:32 2019
@@ -12,6 +12,7 @@ set(LLVM_LINK_COMPONENTS
 # $ to a list of sources, see
 # clangd/tool/CMakeLists.txt for an example.
 add_clang_library(clangDaemonTweaks OBJECT
+  AnnotateHighlightings.cpp
   DumpAST.cpp
   RawStringLiteral.cpp
   SwapIfBranches.cpp

Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
URL

[PATCH] D64137: [clangd] Add a hidden tweak to annotate all highlighting tokens of the file.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365130: [clangd] Add a hidden tweak to annotate all 
highlighting tokens of the file. (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64137?vs=208012&id=208013#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64137

Files:
  clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
===
--- clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/CMakeLists.txt
@@ -12,6 +12,7 @@
 # $ to a list of sources, see
 # clangd/tool/CMakeLists.txt for an example.
 add_clang_library(clangDaemonTweaks OBJECT
+  AnnotateHighlightings.cpp
   DumpAST.cpp
   RawStringLiteral.cpp
   SwapIfBranches.cpp
Index: clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -0,0 +1,82 @@
+//===--- AnnotateHighlightings.cpp ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticHighlighting.h"
+#include "refactor/Tweak.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// FIXME: move it to SemanticHighlighting.h.
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
+  auto LookupIndex = static_cast(Kind);
+  assert(LookupIndex < TextMateLookupTable.size() &&
+ !TextMateLookupTable[LookupIndex].empty());
+  return TextMateLookupTable[LookupIndex].front();
+}
+
+/// Annotate all highlighting tokens in the current file. This is a hidden tweak
+/// which is used to debug semantic highlightings.
+/// Before:
+///   void f() { int abc; }
+///   ^
+/// After:
+///   void /* entity.name.function.cpp */ f() { int /* variable.cpp */ abc; }
+class AnnotateHighlightings : public Tweak {
+public:
+  const char *id() const override final;
+
+  bool prepare(const Selection &Inputs) override {
+for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
+ N = N->Parent)
+  InterestedDecl = N->ASTNode.get();
+return InterestedDecl;
+  }
+  Expected apply(const Selection &Inputs) override;
+
+  std::string title() const override { return "Annotate highlighting tokens"; }
+  Intent intent() const override { return Refactor; }
+  bool hidden() const override { return true; }
+
+private:
+  const Decl *InterestedDecl = nullptr;
+};
+REGISTER_TWEAK(AnnotateHighlightings)
+
+Expected AnnotateHighlightings::apply(const Selection &Inputs) {
+  // Store the existing scopes.
+  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+  // Narrow the traversal scope to the selected node.
+  Inputs.AST.getASTContext().setTraversalScope(
+  {const_cast(InterestedDecl)});
+  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  // Restore the traversal scope.
+  Inputs.AST.getASTContext().setTraversalScope(BackupScopes);
+
+  auto &SM = Inputs.AST.getSourceManager();
+  tooling::Replacements Result;
+  for (const auto &Token : HighlightingTokens) {
+assert(Token.R.start.line == Token.R.end.line &&
+   "Token must be at the same line");
+auto InsertOffset = positionToOffset(Inputs.Code, Token.R.start);
+if (!InsertOffset)
+  return InsertOffset.takeError();
+
+auto InsertReplacement = tooling::Replacement(
+SM.getFileEntryForID(SM.getMainFileID())->getName(), *InsertOffset, 0,
+("/* " + toTextMateScope(Token.Kind) + " */").str());
+if (auto Err = Result.add(InsertReplacement))
+  return std::move(Err);
+  }
+  return Effect::applyEdit(Result);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
@@ -278,6 +278,14 @@
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
 
+TEST(TweakTest, AnnotateHighlightings) {
+  llvm

[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-07-04 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 208015.
Tyker added a comment.

fixed the comment for good, sorry for that.


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

https://reviews.llvm.org/D63640

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/APValue.cpp

Index: clang/test/PCH/APValue.cpp
===
--- /dev/null
+++ clang/test/PCH/APValue.cpp
@@ -0,0 +1,211 @@
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -include-pch %t.pch -ast-dump-all | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -ast-merge %t.pch -ast-dump-all | FileCheck %s
+
+#ifndef EMIT
+#define EMIT
+
+namespace Integer {
+
+constexpr int Unique_Int = int(6789);
+//CHECK:  VarDecl {{.*}} Unique_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'int' 6789
+
+constexpr __uint128_t Unique_Int128 = ((__uint128_t)0x75f17d6b3588f843 << 64) | 0xb13dea7c9c324e51;
+//CHECK:  VarDecl {{.*}} Unique_Int128 
+//CHECK-NEXT: ConstantExpr {{.*}} 'unsigned __int128' 156773562844924187900898496343692168785
+
+}
+
+namespace FloatingPoint {
+
+constexpr double Unique_Double = double(567890.67890);
+//CHECK:  VarDecl {{.*}} Unique_Double
+//CHECK-NEXT: ConstantExpr {{.*}} 'double' 5.678907e+05
+
+}
+
+// FIXME: Add test for FixePoint, ComplexInt, ComplexFloat, AddrLabelDiff.
+
+namespace Struct {
+
+struct B {
+  int i;
+  double d;
+};
+
+constexpr B Basic_Struct = B{1, 0.7};
+//CHECK:  VarDecl {{.*}} Basic_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::B' {1, 7.00e-01}
+
+struct C {
+  int i = 9;
+};
+
+struct A : B {
+  int i;
+  double d;
+  C c;
+};
+
+constexpr A Advanced_Struct = A{Basic_Struct, 1, 79.789, {}};
+//CHECK:  VarDecl {{.*}} Advanced_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::A' {{[{][{]}}1, 7.00e-01}, 1, 7.978900e+01, {9}}
+
+}
+
+namespace Vector {
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Vector_Int = (v4si){8, 2, 3};
+//CHECK:  VarDecl {{.*}} Vector_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'Vector::v4si':'__attribute__((__vector_size__(4 * sizeof(int int' {8, 2, 3, 0}
+
+}
+
+namespace Array {
+
+constexpr int Array_Int[] = {1, 2, 3, 4, 5, 6};
+//CHECK:  VarDecl {{.*}} Array_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'const int [6]' {1, 2, 3, 4, 5, 6}
+
+struct A {
+  int i = 789;
+  double d = 67890.09876;
+};
+
+constexpr A Array2_Struct[][3] = {{{}, {-45678, 9.8}, {9}}, {{}}};
+//CHECK:  VarDecl {{.*}} Array2_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'Array::A const [2][3]' {{[{][{]}}{789, 6.789010e+04}, {-45678, 9.80e+00}, {9, 6.789010e+04}}, {{[{][{]}}789, 6.789010e+04}, {789, 6.789010e+04}, {789, 6.789010e+04}}}
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Array_Vector[] = {{1, 2, 3, 4}, {4, 5, 6, 7}};
+//CHECK:  VarDecl {{.*}} Array_Vector
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Array::v4si [2]' {{[{][{]}}1, 2, 3, 4}, {4, 5, 6, 7}}
+
+}
+
+namespace Union {
+
+struct A {
+  int i = 6789;
+  float f = 987.9876;
+};
+
+union U {
+  int i;
+  A a{567890, 9876.5678f};
+};
+
+constexpr U Unique_Union1 = U{0};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.i = 0}
+
+constexpr U Unique_Union2 = U{};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.a = {567890, 9.876567e+03}}
+
+}
+
+namespace MemberPointer{
+
+struct A {
+  struct B {
+struct C {
+  struct D {
+struct E {
+  struct F {
+struct G {
+  int i;
+};
+  };
+};
+  };
+};
+  };
+};
+
+constexpr auto MemberPointer1 = &A::B::C::D::E::F::G::i;
+//CHECK:  VarDecl {{.*}} MemberPointer1
+//CHECK-NEXT: ConstantExpr {{.*}} 'int MemberPointer::A::B::C::D::E::F::G::*' &G::i
+
+struct A1 {
+  struct B1 {
+int f() const {
+  return 0;
+}
+  };
+
+};
+
+constexpr auto MemberPointer2 = &A1::B1::f;
+//CHECK:  VarDecl {{.*}} MemberPointer2
+//CHECK-NEXT: ConstantExpr {{.*}} 'int (MemberPointer::A1::B1::*)() const' &B1::f
+
+}
+
+namespace std {
+  struct type_info;
+};
+
+namespace LValue {
+
+constexpr int LValueInt = 0;
+constexpr const int& ConstIntRef = LValueInt;
+//CHECK:  VarDecl {{.*}} ConstIntRef
+//CHECK-NEXT: ConstantExpr {{.*}} 'const int' lvalue &LValueInt
+constexpr const int* IntPtr =

[clang-tools-extra] r365132 - [clangd] Query driver reads stderr and passes driver as first argument

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 04:34:23 2019
New Revision: 365132

URL: http://llvm.org/viewvc/llvm-project?rev=365132&view=rev
Log:
[clangd] Query driver reads stderr and passes driver as first argument

Summary:
gcc invokes cc1 through a path deduced from argv[0] therefore it must
be correctly set.
Also it prints the search path to stderr not stdout, this also applies to clang.

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
clang-tools-extra/trunk/clangd/test/system-include-extractor.test

Modified: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp?rev=365132&r1=365131&r2=365132&view=diff
==
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp Thu Jul  4 04:34:23 
2019
@@ -102,20 +102,19 @@ std::vector extractSystemIn
 return {};
   }
 
-  llvm::SmallString<128> OutputPath;
-  auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
-   OutputPath);
-  if (EC) {
+  llvm::SmallString<128> StdErrPath;
+  if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
+   StdErrPath)) {
 elog("System include extraction: failed to create temporary file with "
  "error {0}",
  EC.message());
 return {};
   }
   auto CleanUp = llvm::make_scope_exit(
-  [&OutputPath]() { llvm::sys::fs::remove(OutputPath); });
+  [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); });
 
   llvm::Optional Redirects[] = {
-  {""}, llvm::StringRef(OutputPath), {""}};
+  {""}, {""}, llvm::StringRef(StdErrPath)};
 
   auto Type = driver::types::lookupTypeForExtension(Ext);
   if (Type == driver::types::TY_INVALID) {
@@ -123,22 +122,21 @@ std::vector extractSystemIn
 return {};
   }
   // Should we also preserve flags like "-sysroot", "-nostdinc" ?
-  const llvm::StringRef Args[] = {"-E", "-x", driver::types::getTypeName(Type),
-  "-", "-v"};
+  const llvm::StringRef Args[] = {
+  Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"};
 
-  int RC =
-  llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, Redirects);
-  if (RC) {
+  if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
+ Redirects)) {
 elog("System include extraction: driver execution failed with return code: 
"
  "{0}",
  llvm::to_string(RC));
 return {};
   }
 
-  auto BufOrError = llvm::MemoryBuffer::getFile(OutputPath);
+  auto BufOrError = llvm::MemoryBuffer::getFile(StdErrPath);
   if (!BufOrError) {
 elog("System include extraction: failed to read {0} with error {1}",
- OutputPath, BufOrError.getError().message());
+ StdErrPath, BufOrError.getError().message());
 return {};
   }
 

Modified: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/system-include-extractor.test?rev=365132&r1=365131&r2=365132&view=diff
==
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test (original)
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test Thu Jul  
4 04:34:23 2019
@@ -3,11 +3,12 @@
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here: >&2' >> 
%t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h


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


[PATCH] D64202: [clangd] Some tweaks on semantic highlighting lookuptable.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, jvikstrom.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

- move toTextMateScope to SemanticHighlighting.h;
- move the buildLookupTable to LSP layer (as LSP requires such form);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64202

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp

Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -12,15 +12,6 @@
 namespace clangd {
 namespace {
 
-// FIXME: move it to SemanticHighlighting.h.
-llvm::StringRef toTextMateScope(HighlightingKind Kind) {
-  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
-  auto LookupIndex = static_cast(Kind);
-  assert(LookupIndex < TextMateLookupTable.size() &&
- !TextMateLookupTable[LookupIndex].empty());
-  return TextMateLookupTable[LookupIndex].front();
-}
-
 /// Annotate all highlighting tokens in the current file. This is a hidden tweak
 /// which is used to debug semantic highlightings.
 /// Before:
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -25,7 +25,9 @@
 
 enum class HighlightingKind {
   Variable = 0,
-  Function = 1,
+  Function,
+
+  Last, // placeholder for last value.
 };
 
 // Contains all information needed for the highlighting a token.
@@ -40,9 +42,9 @@
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-// Gets the TextMate scopes as a double nested array where the
-// SemanticHighlightKind indexes correctly into this vector.
-std::vector> getTextMateScopeLookupTable();
+/// Converts a HighlightingKind to a corresponding TextMate scope
+/// (https://manual.macromates.com/en/language_grammars).
+llvm::StringRef toTextMateScope(HighlightingKind Kind);
 
 // Convert to LSP's semantic highlighting information.
 std::vector
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -149,16 +149,19 @@
   return Lines;
 }
 
-std::vector> getTextMateScopeLookupTable() {
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
+  assert(Kind != HighlightingKind::Last &&
+ "must not pass Last to the function");
   // FIXME: Add scopes for C and Objective C.
-  std::map> Scopes = {
-  {HighlightingKind::Variable, {"variable.cpp"}},
-  {HighlightingKind::Function, {"entity.name.function.cpp"}}};
-  std::vector> NestedScopes(Scopes.size());
-  for (const auto &Scope : Scopes)
-NestedScopes[static_cast(Scope.first)] = Scope.second;
-
-  return NestedScopes;
+  switch (Kind) {
+  case HighlightingKind::Function:
+return "entity.name.function.cpp";
+  case HighlightingKind::Variable:
+return "variable.cpp";
+  default:
+break;
+  }
+  llvm_unreachable("unhandled HighlightingKind");
 }
 
 } // namespace clangd
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -82,6 +82,16 @@
   return Defaults;
 }
 
+// Build a lookup table (HighlightingKind => {TextMate Scopes}), which is sent
+// to the LSP client.
+std::vector> buildTextMateScopeLookupTable() {
+  std::vector> LookupTable;
+  // HighlightingKind is using as the index.
+  for (int KindValue = 0; KindValue < (int)HighlightingKind::Last; ++KindValue)
+LookupTable.push_back({toTextMateScope((HighlightingKind)(KindValue))});
+  return LookupTable;
+}
+
 } // namespace
 
 // MessageHandler dispatches incoming LSP messages.
@@ -414,7 +424,7 @@
 Result.getObject("capabilities")
 ->insert(
 {"semanticHighlighting",
- llvm::json::Object{{"scopes", getTextMateScopeLookupTable()}}});
+ llvm::json::Object{{"scopes", buildTextMateScopeLookupTable()}}});
   Reply(std::move(Result));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-07-04 Thread Tyker via Phabricator via cfe-commits
Tyker marked 2 inline comments as done.
Tyker added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8503
 
+llvm::Expected ASTImporter::Import(const APValue &FromValue) {
+  APValue Result;

martong wrote:
> Tyker wrote:
> > martong wrote:
> > > Looks okay, but could we have unit tests for this in ASTImporterTest.cpp?
> > I tested importing using the same test file as serialization 
> > `clang/test/PCH/APValue.cpp` with `-ast-merge` which uses importing. this 
> > prevent duplicating the test code for importing and serializing. is the 
> > unit-test in ASTImporterTest.cpp necessary anyway ?
> Okay, that's fine I missed that previously, so there is no need for the 
> unit-tests in this case.
> Though maybe the `-ast-merge` part of the test should reside in the  
> `clang/test/ASTMerge` directory, because that is where all the other 
> `-ast-merge` tests are. 
> I am not sure how to solve that nicely, because i see you use the same file 
> for both the serialization and for the import.
> Perhaps there should be a common header file which is included both in 
> `test/PCH/APValue.cpp` and in `test/ASTMerge/apvalue/test.cpp`?
> 
> 
we can have a common header,  but i don't know where to put it. having a in 
`PCH` that includes a header form `ASTMerge` seems weird and vice versa. 


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

https://reviews.llvm.org/D63640



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


[PATCH] D64196: [clangd] Query driver reads stderr and passes driver as first argument

2019-07-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365132: [clangd] Query driver reads stderr and passes driver 
as first argument (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64196?vs=207983&id=208018#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64196

Files:
  clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/trunk/clangd/test/system-include-extractor.test


Index: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test
@@ -3,11 +3,12 @@
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here: >&2' >> 
%t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
@@ -102,20 +102,19 @@
 return {};
   }
 
-  llvm::SmallString<128> OutputPath;
-  auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
-   OutputPath);
-  if (EC) {
+  llvm::SmallString<128> StdErrPath;
+  if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
+   StdErrPath)) {
 elog("System include extraction: failed to create temporary file with "
  "error {0}",
  EC.message());
 return {};
   }
   auto CleanUp = llvm::make_scope_exit(
-  [&OutputPath]() { llvm::sys::fs::remove(OutputPath); });
+  [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); });
 
   llvm::Optional Redirects[] = {
-  {""}, llvm::StringRef(OutputPath), {""}};
+  {""}, {""}, llvm::StringRef(StdErrPath)};
 
   auto Type = driver::types::lookupTypeForExtension(Ext);
   if (Type == driver::types::TY_INVALID) {
@@ -123,22 +122,21 @@
 return {};
   }
   // Should we also preserve flags like "-sysroot", "-nostdinc" ?
-  const llvm::StringRef Args[] = {"-E", "-x", driver::types::getTypeName(Type),
-  "-", "-v"};
+  const llvm::StringRef Args[] = {
+  Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"};
 
-  int RC =
-  llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, Redirects);
-  if (RC) {
+  if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
+ Redirects)) {
 elog("System include extraction: driver execution failed with return code: 
"
  "{0}",
  llvm::to_string(RC));
 return {};
   }
 
-  auto BufOrError = llvm::MemoryBuffer::getFile(OutputPath);
+  auto BufOrError = llvm::MemoryBuffer::getFile(StdErrPath);
   if (!BufOrError) {
 elog("System include extraction: failed to read {0} with error {1}",
- OutputPath, BufOrError.getError().message());
+ StdErrPath, BufOrError.getError().message());
 return {};
   }
 


Index: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test
@@ -3,11 +3,12 @@
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_

r365133 - [CTU] Add support for virtual functions

2019-07-04 Thread Gabor Marton via cfe-commits
Author: martong
Date: Thu Jul  4 04:39:00 2019
New Revision: 365133

URL: http://llvm.org/viewvc/llvm-project?rev=365133&view=rev
Log:
[CTU] Add support for virtual functions

Reviewers: Szelethus, xazax.hun

Subscribers: rnkovacs, dkrupp, gamesh411, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
cfe/trunk/test/Analysis/ctu-main.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=365133&r1=365132&r2=365133&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Thu Jul  4 04:39:00 2019
@@ -766,8 +766,11 @@ RuntimeDefinition CXXInstanceCall::getRu
 
   // Does the decl that we found have an implementation?
   const FunctionDecl *Definition;
-  if (!Result->hasBody(Definition))
+  if (!Result->hasBody(Definition)) {
+if (!DynType.canBeASubClass())
+  return AnyFunctionCall::getRuntimeDefinition();
 return {};
+  }
 
   // We found a definition. If we're not sure that this devirtualization is
   // actually what will happen at runtime, make sure to provide the region so

Modified: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/ctu-other.cpp?rev=365133&r1=365132&r2=365133&view=diff
==
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp (original)
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp Thu Jul  4 04:39:00 2019
@@ -38,6 +38,7 @@ int embed_cls::fecl(int x) {
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -49,6 +50,9 @@ public:
 int mycls::fcl(int x) {
   return x + 5;
 }
+int mycls::fvcl(int x) {
+  return x + 7;
+}
 int mycls::fscl(int x) {
   return x + 6;
 }
@@ -56,6 +60,15 @@ int mycls::embed_cls2::fecl2(int x) {
   return x - 11;
 }
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
+int derived::fvcl(int x) {
+  return x + 8;
+}
+
 namespace chns {
 int chf2(int x);
 

Modified: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt?rev=365133&r1=365132&r2=365133&view=diff
==
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt (original)
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt Thu Jul  4 
04:39:00 2019
@@ -3,8 +3,10 @@ c:@N@myns@N@embed_ns@F@fens#I# ctu-other
 c:@F@g#I# ctu-other.cpp.ast
 c:@S@mycls@F@fscl#I#S ctu-other.cpp.ast
 c:@S@mycls@F@fcl#I# ctu-other.cpp.ast
+c:@S@mycls@F@fvcl#I# ctu-other.cpp.ast
 c:@N@myns@S@embed_cls@F@fecl#I# ctu-other.cpp.ast
 c:@S@mycls@S@embed_cls2@F@fecl2#I# ctu-other.cpp.ast
+c:@S@derived@F@fvcl#I# ctu-other.cpp.ast
 c:@F@f#I# ctu-other.cpp.ast
 c:@N@myns@F@fns#I# ctu-other.cpp.ast
 c:@F@h#I# ctu-other.cpp.ast

Modified: cfe/trunk/test/Analysis/ctu-main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ctu-main.cpp?rev=365133&r1=365132&r2=365133&view=diff
==
--- cfe/trunk/test/Analysis/ctu-main.cpp (original)
+++ cfe/trunk/test/Analysis/ctu-main.cpp Thu Jul  4 04:39:00 2019
@@ -45,6 +45,7 @@ public:
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -53,6 +54,11 @@ public:
   };
 };
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
 namespace chns {
 int chf1(int x);
 }
@@ -98,6 +104,14 @@ union U {
 };
 extern U extU;
 
+void test_virtual_functions(mycls* obj) {
+  // The dynamic type is known.
+  clang_analyzer_eval(mycls().fvcl(1) == 8);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
+  // We cannot decide about the dynamic type.
+  clang_analyzer_eval(obj->fvcl(1) == 8);  // expected-warning{{FALSE}} 
expected-warning{{TRUE}}
+}
+
 int main() {
   clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
   clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -116,7 +130,7 @@ int main() {
   clang_analyzer_eval(fun_using_anon_struct(8) == 8); // 
expected-warning{{TRUE}}
 
   clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
-  // expected-warning@Inputs/ctu-other.cpp:80{{REACHABLE}}
+  // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
   MACRODIAG(); // expected-warning{{REACHABLE}}
 
   clang_a

[PATCH] D63920: [CTU] Add support for virtual functions

2019-07-04 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365133: [CTU] Add support for virtual functions (authored by 
martong, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63920?vs=208002&id=208019#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63920

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
  cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
  cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  cfe/trunk/test/Analysis/ctu-main.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -766,8 +766,11 @@
 
   // Does the decl that we found have an implementation?
   const FunctionDecl *Definition;
-  if (!Result->hasBody(Definition))
+  if (!Result->hasBody(Definition)) {
+if (!DynType.canBeASubClass())
+  return AnyFunctionCall::getRuntimeDefinition();
 return {};
+  }
 
   // We found a definition. If we're not sure that this devirtualization is
   // actually what will happen at runtime, make sure to provide the region so
Index: cfe/trunk/test/Analysis/ctu-main.cpp
===
--- cfe/trunk/test/Analysis/ctu-main.cpp
+++ cfe/trunk/test/Analysis/ctu-main.cpp
@@ -45,6 +45,7 @@
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -53,6 +54,11 @@
   };
 };
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
 namespace chns {
 int chf1(int x);
 }
@@ -98,6 +104,14 @@
 };
 extern U extU;
 
+void test_virtual_functions(mycls* obj) {
+  // The dynamic type is known.
+  clang_analyzer_eval(mycls().fvcl(1) == 8);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
+  // We cannot decide about the dynamic type.
+  clang_analyzer_eval(obj->fvcl(1) == 8);  // expected-warning{{FALSE}} expected-warning{{TRUE}}
+}
+
 int main() {
   clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
   clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -116,7 +130,7 @@
   clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
 
   clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
-  // expected-warning@Inputs/ctu-other.cpp:80{{REACHABLE}}
+  // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
   MACRODIAG(); // expected-warning{{REACHABLE}}
 
   clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}
Index: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
===
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
@@ -3,8 +3,10 @@
 c:@F@g#I# ctu-other.cpp.ast
 c:@S@mycls@F@fscl#I#S ctu-other.cpp.ast
 c:@S@mycls@F@fcl#I# ctu-other.cpp.ast
+c:@S@mycls@F@fvcl#I# ctu-other.cpp.ast
 c:@N@myns@S@embed_cls@F@fecl#I# ctu-other.cpp.ast
 c:@S@mycls@S@embed_cls2@F@fecl2#I# ctu-other.cpp.ast
+c:@S@derived@F@fvcl#I# ctu-other.cpp.ast
 c:@F@f#I# ctu-other.cpp.ast
 c:@N@myns@F@fns#I# ctu-other.cpp.ast
 c:@F@h#I# ctu-other.cpp.ast
Index: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
===
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
@@ -38,6 +38,7 @@
 class mycls {
 public:
   int fcl(int x);
+  virtual int fvcl(int x);
   static int fscl(int x);
 
   class embed_cls2 {
@@ -49,6 +50,9 @@
 int mycls::fcl(int x) {
   return x + 5;
 }
+int mycls::fvcl(int x) {
+  return x + 7;
+}
 int mycls::fscl(int x) {
   return x + 6;
 }
@@ -56,6 +60,15 @@
   return x - 11;
 }
 
+class derived : public mycls {
+public:
+  virtual int fvcl(int x) override;
+};
+
+int derived::fvcl(int x) {
+  return x + 8;
+}
+
 namespace chns {
 int chf2(int x);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63773: [clangd] dummy variable extraction on a function scope

2019-07-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:42
+  // Generate Replacement for replacing selected expression with given VarName
+  tooling::Replacement replaceWithVar(std::string VarName) const;
+  // Generate Replacement for declaring the selected Expr as a new variable

nit: StringRef almost always for params you don't mutate



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:46
+  // returns true if the Expr can be extracted
+  inline bool isExtractable() const;
+

define trivial (and even simple) methods inline



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:65
+};
+/// Extracts an expression to the variable dummy
+/// Before:

nit: can you move the tweak to the end, to avoid alternating between the inner 
logic implementation and the outer interface?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:88
+// this is to avoid the function name being extracted in a function call.
+// e.g. int a = [[f]]();
+bool isAFunctionRef(const clang::Expr *Expr) {

I'd suggest naming this something more after the intent than after the 
structure, as we may want to refine it over time, e.g. `isTooTrivialToExtract` 
or `isEligibleToExtract`



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:90
+bool isAFunctionRef(const clang::Expr *Expr) {
+  const clang::DeclRefExpr *DeclRef = dyn_cast_or_null(Expr);
+  if (DeclRef && isa(DeclRef->getDecl()))

Extracting just a declrefexpr (and replacing it with another declrefexpr) 
doesn't seem useful. Any reason to only do this for functions, rather than all 
declrefexprs?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:90
+bool isAFunctionRef(const clang::Expr *Expr) {
+  const clang::DeclRefExpr *DeclRef = dyn_cast_or_null(Expr);
+  if (DeclRef && isa(DeclRef->getDecl()))

sammccall wrote:
> Extracting just a declrefexpr (and replacing it with another declrefexpr) 
> doesn't seem useful. Any reason to only do this for functions, rather than 
> all declrefexprs?
a syntactically similar case is MemberExpr where isImplicitAccess() is true. 
(This is referring to a method of the current class, without qualification)



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:91
+  const clang::DeclRefExpr *DeclRef = dyn_cast_or_null(Expr);
+  if (DeclRef && isa(DeclRef->getDecl()))
+return true;

you may want to check whether this does the right thing for a function template



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:120
+  if ((Expr = Node->ASTNode.get())) {
+Expr->dump();
+ReferencedDecls = computeReferencedDecls(Expr);

remove debug dumping



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:122
+ReferencedDecls = computeReferencedDecls(Expr);
+Extractable =
+!isAFunctionRef(Expr) && (InsertionPoint = computeInsertionPoint());

Can we be a bit more explicit about the control flow and boolean initialization 
here?
e.g. `if (isAFunctionRef(Expr)) return; if (InsertionPoint = 
computeInsertionPoint()) Extractable = true;`



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:135
+// variable out of scope
+bool ExtractionContext::canInsertBefore(const clang::Stmt *Scope) const {
+  if (!Scope)

The name doesn't really match the behavior here - there are lots of other 
reasons we couldn't insert before a point.
this sounds more like `ExtractionContext::exprIsValidOutside` or something?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:137
+  if (!Scope)
+return true;
+  SourceLocation ScopeBegin = Scope->getBeginLoc();

this behavior is not at all obvious at the callsite. I'd suggest making the 
caller check for null, and taking a reference.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:158
+const clang::Stmt *ExtractionContext::computeInsertionPoint() const {
+  bool WaitForSwitch = false;
+  for (const SelectionTree::Node *CurNode = getExprNode(); CurNode->Parent;

The scope of this patch is growing in ways that don't seem to be related to the 
review.

Can you revert the switch-related changes and move them to another patch?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:165
+  break;
+if (const clang::Stmt *Ancestor = CurNode->Parent->ASTNode.get()) {
+  if (WaitForSwitch) {

this is the Parent, not an Ancestor, I think?



Comment at: clang-too

[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:46
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==

The `DeclRefExpr` is a very general expression, which can reference a variable, 
a function, an enum, etc. I think we want to distinguish with them (rather than 
putting all into `Variable` type).

 And we are missing large majority of entities now, I think we could start 
collecting more entities (class, method, enum, etc).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[PATCH] D64202: [clangd] Some tweaks on semantic highlighting lookuptable.

2019-07-04 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: clang-tools-extra/clangd/ClangdLSPServer.cpp:87
+// to the LSP client.
+std::vector> buildTextMateScopeLookupTable() {
+  std::vector> LookupTable;

while here, can we have "highlight" in the name? like 
"buildHighlightScopeLookupTable"?



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:161
+return "variable.cpp";
+  default:
+break;

use `case Last` instead of `default` for better warnings.
https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:30
+
+  Last, // placeholder for last value.
 };

the name is a little confusing as it's last-plus-one. NumKinds is a common 
idiom I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64202



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


[PATCH] D49074: [Analyzer] [WIP] Basic support for multiplication and division in the constraint manager

2019-07-04 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

I tested this on several open-source projects. Lots of false-positives 
disappeared. There are also some new findings, mainly new false-positives but 
not because of this feature but of "loops executed 0 times".


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

https://reviews.llvm.org/D49074



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


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:46
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==

hokein wrote:
> The `DeclRefExpr` is a very general expression, which can reference a 
> variable, a function, an enum, etc. I think we want to distinguish with them 
> (rather than putting all into `Variable` type).
> 
>  And we are missing large majority of entities now, I think we could start 
> collecting more entities (class, method, enum, etc).
IMO the way to ensure consistency is to make the highlight a function of the 
decl, regardless of whether you found it in the decl itself, a declrefexpr, etc.

so something like:

```
// (overloaded)
addToken(SourceLocation Loc, NamedDecl *D) {
  if (isa(D))
return addToken(Loc, HighlightingKind::Variable);
  // ... etc
}

bool VisitDeclRefExpr(DeclRefExpr *Ref) { 
  // bail out for operators here (if it's only *usages* you don't want to 
highlight)
  addToken(Ref->getLocation(), Ref->getDecl());
}

bool VisitNamedDecl(NamedDecl *ND) {
  addToken(ND->getLocation(), ND);
}
```




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[clang-tools-extra] r365134 - [clangd] Fix a lifetime bug in QueryDriver

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 05:24:17 2019
New Revision: 365134

URL: http://llvm.org/viewvc/llvm-project?rev=365134&view=rev
Log:
[clangd] Fix a lifetime bug in QueryDriver

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

Modified: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp?rev=365134&r1=365133&r2=365134&view=diff
==
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp Thu Jul  4 05:24:17 
2019
@@ -48,6 +48,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -221,16 +222,19 @@ public:
 
 llvm::SmallString<128> Driver(Cmd->CommandLine.front());
 llvm::sys::fs::make_absolute(Cmd->Directory, Driver);
+llvm::StringRef Ext = llvm::sys::path::extension(File).trim('.');
+auto Key = std::make_pair(Driver.str(), Ext);
 
-llvm::ArrayRef SystemIncludes;
+std::vector SystemIncludes;
 {
   std::lock_guard Lock(Mu);
 
-  llvm::StringRef Ext = llvm::sys::path::extension(File).trim('.');
-  auto It = DriverToIncludesCache.try_emplace({Driver, Ext});
-  if (It.second)
-It.first->second = extractSystemIncludes(Driver, Ext, 
QueryDriverRegex);
-  SystemIncludes = It.first->second;
+  auto It = DriverToIncludesCache.find(Key);
+  if (It != DriverToIncludesCache.end())
+SystemIncludes = It->second;
+  else
+DriverToIncludesCache[Key] = SystemIncludes =
+extractSystemIncludes(Key.first, Key.second, QueryDriverRegex);
 }
 
 return addSystemIncludes(*Cmd, SystemIncludes);
@@ -239,8 +243,8 @@ public:
 private:
   mutable std::mutex Mu;
   // Caches includes extracted from a driver.
-  mutable llvm::DenseMap,
- std::vector>
+  mutable std::map,
+   std::vector>
   DriverToIncludesCache;
   mutable llvm::Regex QueryDriverRegex;
 


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


[PATCH] D64202: [clangd] Some tweaks on semantic highlighting lookuptable.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 208020.
hokein marked 3 inline comments as done.
hokein added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64202

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp

Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -12,15 +12,6 @@
 namespace clangd {
 namespace {
 
-// FIXME: move it to SemanticHighlighting.h.
-llvm::StringRef toTextMateScope(HighlightingKind Kind) {
-  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
-  auto LookupIndex = static_cast(Kind);
-  assert(LookupIndex < TextMateLookupTable.size() &&
- !TextMateLookupTable[LookupIndex].empty());
-  return TextMateLookupTable[LookupIndex].front();
-}
-
 /// Annotate all highlighting tokens in the current file. This is a hidden tweak
 /// which is used to debug semantic highlightings.
 /// Before:
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -25,7 +25,9 @@
 
 enum class HighlightingKind {
   Variable = 0,
-  Function = 1,
+  Function,
+
+  NumKinds,
 };
 
 // Contains all information needed for the highlighting a token.
@@ -40,9 +42,9 @@
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-// Gets the TextMate scopes as a double nested array where the
-// SemanticHighlightKind indexes correctly into this vector.
-std::vector> getTextMateScopeLookupTable();
+/// Converts a HighlightingKind to a corresponding TextMate scope
+/// (https://manual.macromates.com/en/language_grammars).
+llvm::StringRef toTextMateScope(HighlightingKind Kind);
 
 // Convert to LSP's semantic highlighting information.
 std::vector
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -149,16 +149,17 @@
   return Lines;
 }
 
-std::vector> getTextMateScopeLookupTable() {
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
   // FIXME: Add scopes for C and Objective C.
-  std::map> Scopes = {
-  {HighlightingKind::Variable, {"variable.cpp"}},
-  {HighlightingKind::Function, {"entity.name.function.cpp"}}};
-  std::vector> NestedScopes(Scopes.size());
-  for (const auto &Scope : Scopes)
-NestedScopes[static_cast(Scope.first)] = Scope.second;
-
-  return NestedScopes;
+  switch (Kind) {
+  case HighlightingKind::Function:
+return "entity.name.function.cpp";
+  case HighlightingKind::Variable:
+return "variable.cpp";
+  case HighlightingKind::NumKinds:
+llvm_unreachable("must not pass NumKinds to the function");
+  }
+  llvm_unreachable("unhandled HighlightingKind");
 }
 
 } // namespace clangd
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -82,6 +82,17 @@
   return Defaults;
 }
 
+// Build a lookup table (HighlightingKind => {TextMate Scopes}), which is sent
+// to the LSP client.
+std::vector> buildHighlightScopeLookupTable() {
+  std::vector> LookupTable;
+  // HighlightingKind is using as the index.
+  for (int KindValue = 0; KindValue < (int)HighlightingKind::NumKinds;
+   ++KindValue)
+LookupTable.push_back({toTextMateScope((HighlightingKind)(KindValue))});
+  return LookupTable;
+}
+
 } // namespace
 
 // MessageHandler dispatches incoming LSP messages.
@@ -414,7 +425,7 @@
 Result.getObject("capabilities")
 ->insert(
 {"semanticHighlighting",
- llvm::json::Object{{"scopes", getTextMateScopeLookupTable()}}});
+ llvm::json::Object{{"scopes", buildHighlightScopeLookupTable()}}});
   Reply(std::move(Result));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r365135 - [clangd] Some tweaks on semantic highlighting lookuptable.

2019-07-04 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Jul  4 05:27:21 2019
New Revision: 365135

URL: http://llvm.org/viewvc/llvm-project?rev=365135&view=rev
Log:
[clangd] Some tweaks on semantic highlighting lookuptable.

Summary:
- move toTextMateScope to SemanticHighlighting.h;
- move the buildLookupTable to LSP layer (as LSP requires such form);

Reviewers: sammccall, jvikstrom

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=365135&r1=365134&r2=365135&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Jul  4 05:27:21 2019
@@ -82,6 +82,17 @@ CompletionItemKindBitset defaultCompleti
   return Defaults;
 }
 
+// Build a lookup table (HighlightingKind => {TextMate Scopes}), which is sent
+// to the LSP client.
+std::vector> buildHighlightScopeLookupTable() {
+  std::vector> LookupTable;
+  // HighlightingKind is using as the index.
+  for (int KindValue = 0; KindValue < (int)HighlightingKind::NumKinds;
+   ++KindValue)
+LookupTable.push_back({toTextMateScope((HighlightingKind)(KindValue))});
+  return LookupTable;
+}
+
 } // namespace
 
 // MessageHandler dispatches incoming LSP messages.
@@ -414,7 +425,7 @@ void ClangdLSPServer::onInitialize(const
 Result.getObject("capabilities")
 ->insert(
 {"semanticHighlighting",
- llvm::json::Object{{"scopes", getTextMateScopeLookupTable()}}});
+ llvm::json::Object{{"scopes", 
buildHighlightScopeLookupTable()}}});
   Reply(std::move(Result));
 }
 

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=365135&r1=365134&r2=365135&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Thu Jul  4 05:27:21 
2019
@@ -149,16 +149,17 @@ toSemanticHighlightingInformation(llvm::
   return Lines;
 }
 
-std::vector> getTextMateScopeLookupTable() {
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
   // FIXME: Add scopes for C and Objective C.
-  std::map> Scopes = {
-  {HighlightingKind::Variable, {"variable.cpp"}},
-  {HighlightingKind::Function, {"entity.name.function.cpp"}}};
-  std::vector> NestedScopes(Scopes.size());
-  for (const auto &Scope : Scopes)
-NestedScopes[static_cast(Scope.first)] = Scope.second;
-
-  return NestedScopes;
+  switch (Kind) {
+  case HighlightingKind::Function:
+return "entity.name.function.cpp";
+  case HighlightingKind::Variable:
+return "variable.cpp";
+  case HighlightingKind::NumKinds:
+llvm_unreachable("must not pass NumKinds to the function");
+  }
+  llvm_unreachable("unhandled HighlightingKind");
 }
 
 } // namespace clangd

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=365135&r1=365134&r2=365135&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Thu Jul  4 05:27:21 
2019
@@ -25,7 +25,9 @@ namespace clangd {
 
 enum class HighlightingKind {
   Variable = 0,
-  Function = 1,
+  Function,
+
+  NumKinds,
 };
 
 // Contains all information needed for the highlighting a token.
@@ -40,9 +42,9 @@ bool operator==(const HighlightingToken
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-// Gets the TextMate scopes as a double nested array where the
-// SemanticHighlightKind indexes correctly into this vector.
-std::vector> getTextMateScopeLookupTable();
+/// Converts a HighlightingKind to a corresponding TextMate scope
+/// (https://manual.macromates.com/en/language_grammars).
+llvm::StringRef toTextMateScope(HighlightingKind Kind);
 
 // Convert to LSP's semantic highlighting information.
 std::vector

Modified: 
clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp?rev=365135&r1=365134&r2=365135&view=diff
==
--- clang-tools-extra/trunk/cl

[PATCH] D64202: [clangd] Some tweaks on semantic highlighting lookuptable.

2019-07-04 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365135: [clangd] Some tweaks on semantic highlighting 
lookuptable. (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64202?vs=208020&id=208021#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64202

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp

Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -149,16 +149,17 @@
   return Lines;
 }
 
-std::vector> getTextMateScopeLookupTable() {
+llvm::StringRef toTextMateScope(HighlightingKind Kind) {
   // FIXME: Add scopes for C and Objective C.
-  std::map> Scopes = {
-  {HighlightingKind::Variable, {"variable.cpp"}},
-  {HighlightingKind::Function, {"entity.name.function.cpp"}}};
-  std::vector> NestedScopes(Scopes.size());
-  for (const auto &Scope : Scopes)
-NestedScopes[static_cast(Scope.first)] = Scope.second;
-
-  return NestedScopes;
+  switch (Kind) {
+  case HighlightingKind::Function:
+return "entity.name.function.cpp";
+  case HighlightingKind::Variable:
+return "variable.cpp";
+  case HighlightingKind::NumKinds:
+llvm_unreachable("must not pass NumKinds to the function");
+  }
+  llvm_unreachable("unhandled HighlightingKind");
 }
 
 } // namespace clangd
Index: clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -12,15 +12,6 @@
 namespace clangd {
 namespace {
 
-// FIXME: move it to SemanticHighlighting.h.
-llvm::StringRef toTextMateScope(HighlightingKind Kind) {
-  static const auto &TextMateLookupTable = getTextMateScopeLookupTable();
-  auto LookupIndex = static_cast(Kind);
-  assert(LookupIndex < TextMateLookupTable.size() &&
- !TextMateLookupTable[LookupIndex].empty());
-  return TextMateLookupTable[LookupIndex].front();
-}
-
 /// Annotate all highlighting tokens in the current file. This is a hidden tweak
 /// which is used to debug semantic highlightings.
 /// Before:
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h
@@ -25,7 +25,9 @@
 
 enum class HighlightingKind {
   Variable = 0,
-  Function = 1,
+  Function,
+
+  NumKinds,
 };
 
 // Contains all information needed for the highlighting a token.
@@ -40,9 +42,9 @@
 // main AST.
 std::vector getSemanticHighlightings(ParsedAST &AST);
 
-// Gets the TextMate scopes as a double nested array where the
-// SemanticHighlightKind indexes correctly into this vector.
-std::vector> getTextMateScopeLookupTable();
+/// Converts a HighlightingKind to a corresponding TextMate scope
+/// (https://manual.macromates.com/en/language_grammars).
+llvm::StringRef toTextMateScope(HighlightingKind Kind);
 
 // Convert to LSP's semantic highlighting information.
 std::vector
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -82,6 +82,17 @@
   return Defaults;
 }
 
+// Build a lookup table (HighlightingKind => {TextMate Scopes}), which is sent
+// to the LSP client.
+std::vector> buildHighlightScopeLookupTable() {
+  std::vector> LookupTable;
+  // HighlightingKind is using as the index.
+  for (int KindValue = 0; KindValue < (int)HighlightingKind::NumKinds;
+   ++KindValue)
+LookupTable.push_back({toTextMateScope((HighlightingKind)(KindValue))});
+  return LookupTable;
+}
+
 } // namespace
 
 // MessageHandler dispatches incoming LSP messages.
@@ -414,7 +425,7 @@
 Result.getObject("capabilities")
 ->insert(
 {"semanticHighlighting",
- llvm::json::Object{{"scopes", getTextMateScopeLookupTable()}}});
+ llvm::json::Object{{"scopes", buildHighlightScopeLookupTable()}}});
   Reply(std::move(Result));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 208028.
jvikstrom added a comment.

Added overload for addToken and added more code to the test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -28,7 +28,7 @@
 
   return Tokens;
 }
-
+#include 
 void checkHighlightings(llvm::StringRef Code) {
   Annotations Test(Code);
   auto AST = TestTU::withCode(Test.code()).build();
@@ -43,6 +43,14 @@
   }
 
   auto ActualTokens = getSemanticHighlightings(AST);
+  std::cout << "\n\n";
+  for(auto Tok : ExpectedTokens) {
+std::cout << "E:: " << Tok.R.start.line << ":" << Tok.R.start.character << std::endl;
+  }
+  for(auto Tok : ActualTokens) {
+std::cout << "A:: " << Tok.R.start.line << ":" << Tok.R.start.character << std::endl;
+  }
+
   EXPECT_THAT(ActualTokens, testing::UnorderedElementsAreArray(ExpectedTokens));
 }
 
@@ -57,10 +65,20 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -35,25 +35,42 @@
   }
 
   bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+addNamedDecl(Var);
 return true;
   }
   bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+addNamedDecl(Func);
+return true;
+  }
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  // Don't want to highlight operator usages.
+  return true;
+
+addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }
 
 private:
-  void addToken(const NamedDecl *D, HighlightingKind Kind) {
-if (D->getLocation().isMacroID())
-  // FIXME: skip tokens inside macros for now.
+  void addToken(SourceLocation Loc, const Decl* D) {
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Variable);
   return;
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);
+  return;
+}
+  }
 
-if (D->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+  void addToken(SourceLocation Loc, HighlightingKind Kind) {
+if (Loc.isMacroID())
+  // FIXME: skip tokens inside macros for now.
   return;
 
-auto R = getTokenRange(SM, Ctx.getLangOpts(), D->getLocation());
+auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {
   // R should always have a value, if it doesn't something is very wrong.
   elog("Tried to add semantic token with an invalid range");
@@ -62,6 +79,13 @@
 
 Tokens.push_back({Kind, R.getValue()});
   }
+
+  void addNamedDecl(const NamedDecl *D) {
+if (D->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return;
+addToken(D->getLocation(), D);
+  }
 };
 
 // Encode binary data into base64.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 208029.
jvikstrom added a comment.

Removed VisitVarDecl and VisitFuncDecl in favor of VisitNamedDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -28,7 +28,7 @@
 
   return Tokens;
 }
-
+#include 
 void checkHighlightings(llvm::StringRef Code) {
   Annotations Test(Code);
   auto AST = TestTU::withCode(Test.code()).build();
@@ -43,6 +43,14 @@
   }
 
   auto ActualTokens = getSemanticHighlightings(AST);
+  std::cout << "\n\n";
+  for(auto Tok : ExpectedTokens) {
+std::cout << "E:: " << Tok.R.start.line << ":" << Tok.R.start.character << std::endl;
+  }
+  for(auto Tok : ActualTokens) {
+std::cout << "A:: " << Tok.R.start.line << ":" << Tok.R.start.character << std::endl;
+  }
+
   EXPECT_THAT(ActualTokens, testing::UnorderedElementsAreArray(ExpectedTokens));
 }
 
@@ -57,10 +65,20 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -34,26 +34,42 @@
 return Tokens;
   }
 
-  bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return true;
+addToken(ND->getLocation(), ND);
 return true;
   }
-  bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  // Don't want to highlight operator usages.
+  return true;
+
+addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }
 
 private:
-  void addToken(const NamedDecl *D, HighlightingKind Kind) {
-if (D->getLocation().isMacroID())
-  // FIXME: skip tokens inside macros for now.
+  void addToken(SourceLocation Loc, const Decl* D) {
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Variable);
+  return;
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);
   return;
+}
+  }
 
-if (D->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+  void addToken(SourceLocation Loc, HighlightingKind Kind) {
+if (Loc.isMacroID())
+  // FIXME: skip tokens inside macros for now.
   return;
 
-auto R = getTokenRange(SM, Ctx.getLangOpts(), D->getLocation());
+auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {
   // R should always have a value, if it doesn't something is very wrong.
   elog("Tried to add semantic token with an invalid range");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [clang-tools-extra] r365123 - [clangd] Make HadErrors part of background index's internal state

2019-07-04 Thread via cfe-commits
Hi Kadir,

Your change is causing a build failure on our internal linux build bot running 
gcc 5.4:

FAILED: CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/lib/ccache/g++  
 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/tools/extra/clangd 
-I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd
 -I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/include 
-Itools/clang/include -Iinclude 
-I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/include -fPIC 
-fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment 
-fdiagnostics-color -ffunction-sections -fdata-sections -fno-common 
-Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG  -fno-exceptions 
-fno-rtti -MMD -MT 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 -MF 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o.d
 -o 
tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 -c 
/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.cpp
In file included from 
/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdServer.h:24:0,
 from 
/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.h:12,
 from 
/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.cpp:9:
/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/index/Background.h:99:24:
 error: array must be initialized with a brace-enclosed initializer
 FileDigest Digest{0};
^

Can you please take a look?

Douglas Yung

-Original Message-
From: cfe-commits  On Behalf Of Kadir 
Cetinkaya via cfe-commits
Sent: Thursday, July 4, 2019 2:52
To: cfe-commits@lists.llvm.org
Subject: [clang-tools-extra] r365123 - [clangd] Make HadErrors part of 
background index's internal state

Author: kadircet
Date: Thu Jul  4 02:52:12 2019
New Revision: 365123

URL: http://llvm.org/viewvc/llvm-project?rev=365123&view=rev
Log:
[clangd] Make HadErrors part of background index's internal state

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365123&r1=365122&r2=365123&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4 
+++ 02:52:12 2019
@@ -101,28 +101,6 @@ IncludeGraph getSubGraph(const URI &U, c
   return IG;
 }
 
-// Creates a filter to not collect index results from files with unchanged -// 
digests.
-// \p FileDigests contains file digests for the current indexed files.
-decltype(SymbolCollector::Options::FileFilter)
-createFileFilter(const llvm::StringMap &FileDigests) {
-  return [&FileDigests](const SourceManager &SM, FileID FID) {
-const auto *F = SM.getFileEntryForID(FID);
-if (!F)
-  return false; // Skip invalid files.
-auto AbsPath = getCanonicalPath(F, SM);
-if (!AbsPath)
-  return false; // Skip files without absolute path.
-auto Digest = digestFile(SM, FID);
-if (!Digest)
-  return false;
-auto D = FileDigests.find(*AbsPath);
-if (D != FileDigests.end() && D->second == Digest)
-  return false; // Skip files that haven't changed.
-return true;
-  };
-}
-
 // We cannot use vfs->makeAbsolute because Cmd.FileName is either absolute or  
// relative to Cmd.Directory, which might not be the same as current working  
// directory.
@@ -274,12 +252,12 @@ void BackgroundIndex::enqueueTask(Task T  }
 
 /// Given index results from a TU, only update symbols coming from files that 
-/// are different or missing from than \p DigestsSnapshot. Also stores new 
index -/// information on IndexStorage.
-void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
- const llvm::StringMap 
&DigestsSnapshot,
- BackgroundIndexStorage *IndexStorage,
- bool HadErrors) {
+/// are different or missing from than \p ShardVersionsSnapshot. Also 
+s

[clang-tools-extra] r365140 - [clangd] Fix breakage on gcc 5.4

2019-07-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jul  4 06:47:51 2019
New Revision: 365140

URL: http://llvm.org/viewvc/llvm-project?rev=365140&view=rev
Log:
[clangd] Fix breakage on gcc 5.4

Modified:
clang-tools-extra/trunk/clangd/index/Background.h

Modified: clang-tools-extra/trunk/clangd/index/Background.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=365140&r1=365139&r2=365140&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.h (original)
+++ clang-tools-extra/trunk/clangd/index/Background.h Thu Jul  4 06:47:51 2019
@@ -96,7 +96,7 @@ public:
 private:
   /// Represents the state of a single file when indexing was performed.
   struct ShardVersion {
-FileDigest Digest{0};
+FileDigest Digest{{0}};
 bool HadErrors = false;
   };
 


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


Re: [clang-tools-extra] r365123 - [clangd] Make HadErrors part of background index's internal state

2019-07-04 Thread Kadir Çetinkaya via cfe-commits
https://reviews.llvm.org/rL365140 should fix it, please let me know if it
doesnt.

On Thu, Jul 4, 2019 at 3:45 PM  wrote:

> Hi Kadir,
>
> Your change is causing a build failure on our internal linux build bot
> running gcc 5.4:
>
> FAILED: CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache
> /usr/lib/ccache/g++   -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
> -Itools/clang/tools/extra/clangd
> -I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd
> -I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/include
> -Itools/clang/include -Iinclude
> -I/home/siadmin/jenkins/w/opensource/opensource_build/llvm/include -fPIC
> -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wno-missing-field-initializers -pedantic -Wno-long-long
> -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
> -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common
> -Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG  -fno-exceptions
> -fno-rtti -MMD -MT
> tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
> -MF
> tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o.d
> -o
> tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
> -c
> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.cpp
> In file included from
> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdServer.h:24:0,
>  from
> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.h:12,
>  from
> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/ClangdLSPServer.cpp:9:
> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/tools/clang/tools/extra/clangd/index/Background.h:99:24:
> error: array must be initialized with a brace-enclosed initializer
>  FileDigest Digest{0};
> ^
>
> Can you please take a look?
>
> Douglas Yung
>
> -Original Message-
> From: cfe-commits  On Behalf Of Kadir
> Cetinkaya via cfe-commits
> Sent: Thursday, July 4, 2019 2:52
> To: cfe-commits@lists.llvm.org
> Subject: [clang-tools-extra] r365123 - [clangd] Make HadErrors part of
> background index's internal state
>
> Author: kadircet
> Date: Thu Jul  4 02:52:12 2019
> New Revision: 365123
>
> URL: http://llvm.org/viewvc/llvm-project?rev=365123&view=rev
> Log:
> [clangd] Make HadErrors part of background index's internal state
>
> Reviewers: sammccall
>
> Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D64147
>
> Modified:
> clang-tools-extra/trunk/clangd/index/Background.cpp
> clang-tools-extra/trunk/clangd/index/Background.h
> clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
>
> Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=365123&r1=365122&r2=365123&view=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
> +++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul  4
> +++ 02:52:12 2019
> @@ -101,28 +101,6 @@ IncludeGraph getSubGraph(const URI &U, c
>return IG;
>  }
>
> -// Creates a filter to not collect index results from files with
> unchanged -// digests.
> -// \p FileDigests contains file digests for the current indexed files.
> -decltype(SymbolCollector::Options::FileFilter)
> -createFileFilter(const llvm::StringMap &FileDigests) {
> -  return [&FileDigests](const SourceManager &SM, FileID FID) {
> -const auto *F = SM.getFileEntryForID(FID);
> -if (!F)
> -  return false; // Skip invalid files.
> -auto AbsPath = getCanonicalPath(F, SM);
> -if (!AbsPath)
> -  return false; // Skip files without absolute path.
> -auto Digest = digestFile(SM, FID);
> -if (!Digest)
> -  return false;
> -auto D = FileDigests.find(*AbsPath);
> -if (D != FileDigests.end() && D->second == Digest)
> -  return false; // Skip files that haven't changed.
> -return true;
> -  };
> -}
> -
>  // We cannot use vfs->makeAbsolute because Cmd.FileName is either
> absolute or  // relative to Cmd.Directory, which might not be the same as
> current working  // directory.
> @@ -274,12 +252,12 @@ void BackgroundIndex::enqueueTask(Task T  }
>
>  /// Given index results from a TU, only update symbols coming from files
> that -/// are different or missing from than \p DigestsSnapshot. Also
> stores new index -/// information on IndexStorage.
> -void BackgroundIndex::update(llvm::

[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 208030.
jvikstrom added a comment.

Removed debug prints from test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,20 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -34,26 +34,42 @@
 return Tokens;
   }
 
-  bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return true;
+addToken(ND->getLocation(), ND);
 return true;
   }
-  bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  // Don't want to highlight operator usages.
+  return true;
+
+addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }
 
 private:
-  void addToken(const NamedDecl *D, HighlightingKind Kind) {
-if (D->getLocation().isMacroID())
-  // FIXME: skip tokens inside macros for now.
+  void addToken(SourceLocation Loc, const Decl* D) {
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Variable);
+  return;
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);
   return;
+}
+  }
 
-if (D->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+  void addToken(SourceLocation Loc, HighlightingKind Kind) {
+if (Loc.isMacroID())
+  // FIXME: skip tokens inside macros for now.
   return;
 
-auto R = getTokenRange(SM, Ctx.getLangOpts(), D->getLocation());
+auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {
   // R should always have a value, if it doesn't something is very wrong.
   elog("Tried to add semantic token with an invalid range");


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,20 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -34,26 +34,42 @@
 return Tokens;
   }
 
-  bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return true;
+addToken(ND->getLocation(), ND);
 return true;
   }
-  bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() ==
+DeclarationName::CXXOperatorName)
+  //

[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:38
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.

I think you might want to bail out (both here and in VisitDeclRefExpr) if the 
name kind isn't identifier.

Reason is you're only coloring the token at location, and most of the other 
name kinds can span multiple tokens or otherwise need special consideration.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:61
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);

note that methods, constructors, and destructors inherit from functiondecl, so 
if you want to exclude/distinguish those, order matters here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[PATCH] D64128: [CodeGen] Generate llvm.ptrmask instead of inttoptr(and(ptrtoint, C)) if possible.

2019-07-04 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Thanks for the quick responses and the helpful comments. Thank you very much 
Hal, for summarizing the argument from previous discussions. My initial 
understanding indeed was that by generating ptrmask directly for C/C++ 
expressions, we can circumvent the issues that come with ptrtoint/inttoptr in 
LLVM.

One key point that might not be too clear is that the question should be 
whether `(T*) ((intptr_t) x & N)` points to the same underlying object as 
`x`,// iff the mask `N` preserves all 'relevant' bits of the pointer `x`//. I 
am not sure if 'relevant' bits is the best term, but I use it to refer to all 
bits that do not have to be zero due to alignment requirements or pointer size 
restrictions. With that in mind, let me try to cover the possible cases in 
terms of C++'s  safely-derived pointers, depending on `x`. (I'm referencing 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf)

1. if `x` is a safely-derived pointer, then mask is a no-op and the result of 
the expression is a safely-derived pointer; as `x` was safely-derived, all bits 
that are masked out must already be 0, so according to 3.7.4.3.3, 
`reinterpret_cast(x)` should be equal to 
`reinterpret_cast(((intptr_t) x & N))`.

2. if `x` is not a safely-derived pointer, but it becomes one after masking: 
then `x` must be the result of a series of bitwise operations, that only modify 
the bits masked out later by `N`. Otherwise the whole series of bitwise 
operations including the masking would violate `3.7.4.3.3 - the result of an 
additive or bitwise operation, one of whose operands is an integer 
representation of a safely-derived pointer value P, if that result converted by 
reinterpret_cast would compare equal to a safely-derived pointer 
computable from reinterpret_cast(P)`

3. if `x` is not a safely-derived pointer and the mask does not turn it into a 
safely-derived pointer: in that case, the masking should again not change the 
safely-derived property, and both would be invalid under strict pointer safety.

I think the key case is 2., where the mask operation is the last step in a 
series of bitwise operations, taking an integer representation of a 
safely-derived pointer value `P` and after masking we get `P` again. E.g. 
packing/unpacking bits of a tagged pointer `(P | 1) & ~1`. After writing all 
that down, there seems to be one problem though: technically we have a series 
of bitwise operations and the intermediate values are not integer values of 
safely-derived pointers. One could argue that the bitwise operations together 
cancel out each other and are a no-op, resulting in the original pointer.

Does this summary make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64128



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


[PATCH] D64128: [CodeGen] Generate llvm.ptrmask instead of inttoptr(and(ptrtoint, C)) if possible.

2019-07-04 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D64128#1569836 , @hfinkel wrote:

> In D64128#1569817 , @rjmccall wrote:
>
> > The pointer/integer conversion is "implementation-defined", but it's not 
> > totally unconstrained.  C notes that "The mapping functions for converting 
> > a pointer to an integer or an integer to a pointer are intended to be 
> > consistent with the addressing structure of the execution environment.", 
> > and we do have to honor that.  The standard allows that "the result ... 
> > might not point to an entity of the referenced type", but when in fact it's 
> > guaranteed to do so (i.e. it's not just a coincidental result of an 
> > implementation decision like the exact address of a global variable — no 
> > "guessing"), I do think we have an obligation to make it work.  And on a 
> > practical level, there has to be *some* way of playing clever address 
> > tricks in the language in order to implement things like allocators and so 
> > forth.  So this makes me very antsy.
>
>
> I don't disagree. But I believe the question is if we have:
>
>   int *x = malloc(4);
>   int *y = malloc(4);
>   if (x & ~15 == y) {
> *(x & ~15) = 5; // Is this allowed, and if so, must the compiler assume 
> that it might set the value of *y?
>   }
>   


If the mask could change the 'relevant' bits of a pointer, like in this 
example, we would not generate a ptrmask call. We would only generate ptrmask 
calls here, if the mask only masks out bits that need to be zero due to 
alignment requirements (and high bits if the pointer size is limited).

> Also, and I could be wrong, but my impression is that all of this is extra - 
> this motivating use case requires generating the intrinsic from the code in 
> lib/CodeGen/TargetInfo.cpp - generating it from C/C++ expressions is just a 
> potential additional benefit.

Yes, adding it to clang is extra, my main motivation for the intrinsic was to 
improve performance of tagged pointers used by a different frontend. Generating 
the intrinsic from C/C++ would just be an additional benefit, to improve 
handling of tagged pointers and similar code and provide wider testing for the 
intrinsic. For the LLVM/Clang codebase, most cases we generate ptrmask with 
this patch come from `PointerIntPair` and those should be fairly easy to handle 
with a builtin, if we cannot generate it automatically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64128



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


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 208041.
jvikstrom marked 2 inline comments as done.
jvikstrom added a comment.

Added testcae. Added another bailout from VisitNamedDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,31 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
+  )cpp",
+  R"cpp(
+struct A {
+  A();
+  ~A();
+  void $Function[[abc]]();
+};
+void $Function[[foo]]() {
+  A $Variable[[a]];
+  $Variable[[a]].abc();
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -34,26 +34,46 @@
 return Tokens;
   }
 
-  bool VisitVarDecl(VarDecl *Var) {
-addToken(Var, HighlightingKind::Variable);
+  bool VisitNamedDecl(NamedDecl *ND) {
+// FIXME: This also skips constructors and destructors.
+if (ND->getDeclName().getNameKind() != DeclarationName::Identifier)
+  return true;
+
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.
+  return true;
+addToken(ND->getLocation(), ND);
 return true;
   }
-  bool VisitFunctionDecl(FunctionDecl *Func) {
-addToken(Func, HighlightingKind::Function);
+
+  bool VisitDeclRefExpr(DeclRefExpr *Ref) {
+if (Ref->getNameInfo().getName().getNameKind() !=
+DeclarationName::Identifier)
+  // Only want to highlight identifiers.
+  return true;
+
+addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }
 
 private:
-  void addToken(const NamedDecl *D, HighlightingKind Kind) {
-if (D->getLocation().isMacroID())
-  // FIXME: skip tokens inside macros for now.
+  void addToken(SourceLocation Loc, const Decl *D) {
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Variable);
   return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Function);
+  return;
+}
+  }
 
-if (D->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+  void addToken(SourceLocation Loc, HighlightingKind Kind) {
+if (Loc.isMacroID())
+  // FIXME: skip tokens inside macros for now.
   return;
 
-auto R = getTokenRange(SM, Ctx.getLangOpts(), D->getLocation());
+auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {
   // R should always have a value, if it doesn't something is very wrong.
   elog("Tried to add semantic token with an invalid range");


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -57,10 +57,31 @@
 void $Function[[foo]](int $Variable[[a]]) {
   auto $Variable[[VeryLongVariableName]] = 12312;
   A $Variable[[aa]];
+  auto $Variable[[l]] = $Variable[[aa]].SomeMember + $Variable[[a]];
 }
   )cpp",
   R"cpp(
 void $Function[[foo]](int);
+  )cpp",
+  R"cpp(
+void $Function[[gah]]();
+void $Function[[foo]]() {
+  int $Variable[[b]];
+  auto $Variable[[FN]] = [ $Variable[[b]]](int $Variable[[a]]) -> void {};
+  $Variable[[FN]](12312);
+  auto $Variable[[bou]] = $Function[[gah]];
+}
+  )cpp",
+  R"cpp(
+struct A {
+  A();
+  ~A();
+  void $Function[[abc]]();
+};
+void $Function[[foo]]() {
+  A $Variable[[a]];
+  $Variable[[a]].abc();
+}
   )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHig

[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:38
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.

sammccall wrote:
> I think you might want to bail out (both here and in VisitDeclRefExpr) if the 
> name kind isn't identifier.
> 
> Reason is you're only coloring the token at location, and most of the other 
> name kinds can span multiple tokens or otherwise need special consideration.
I must have missed the Identifier NameKind because I was first-hand looking for 
something like that. 
Thanks.

Are you aware of any testcase I could add for this by the way?



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:61
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);

sammccall wrote:
> note that methods, constructors, and destructors inherit from functiondecl, 
> so if you want to exclude/distinguish those, order matters here
I'm aware of that, but thanks for the heads up. Although should I add it in a 
comment somewhere in the method? Also added an additional testcase for classes 
and FIXMEs to the skip if statement in VisitNamedDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[PATCH] D63767: [NFC] Make some ObjectFormatType switches covering

2019-07-04 Thread Sean Fertile via Phabricator via cfe-commits
sfertile accepted this revision.
sfertile added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: wuzish.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63767



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


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 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.

(LG from my side)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[PATCH] D64199: [clangd] Added highlighting for variable references (declrefs)

2019-07-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:38
+  bool VisitNamedDecl(NamedDecl *ND) {
+if (ND->getDeclName().isEmpty())
+  // Don't add symbols that don't have any length.

jvikstrom wrote:
> sammccall wrote:
> > I think you might want to bail out (both here and in VisitDeclRefExpr) if 
> > the name kind isn't identifier.
> > 
> > Reason is you're only coloring the token at location, and most of the other 
> > name kinds can span multiple tokens or otherwise need special consideration.
> I must have missed the Identifier NameKind because I was first-hand looking 
> for something like that. 
> Thanks.
> 
> Are you aware of any testcase I could add for this by the way?
Such a testcase would ensure you're not coloring any part of `struct F { ~F(); 
}` as a method, or `operator <<` etc.




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:61
+}
+if(isa(D)) {
+  addToken(Loc, HighlightingKind::Function);

jvikstrom wrote:
> sammccall wrote:
> > note that methods, constructors, and destructors inherit from functiondecl, 
> > so if you want to exclude/distinguish those, order matters here
> I'm aware of that, but thanks for the heads up. Although should I add it in a 
> comment somewhere in the method? Also added an additional testcase for 
> classes and FIXMEs to the skip if statement in VisitNamedDecl.
I don't think it needs a comment, especially if you're not actually 
highlighting them (because they have weird DeclarationNames)

> FIXMEs to the skip if statement in VisitNamedDecl
I'm not actually sure there's anything to fix here - it's a bit hard to talk 
about constructor/destructor highlighting as distinct from type name 
highlighting in C++. If you want them highlighted as classes, then that should 
just start working when you start handling TypeLocs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64199



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


[PATCH] D64210: [ARM] Fix vector vsqadd intrinsics operands

2019-07-04 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio created this revision.
dnsampaio added a reviewer: LukeCheeseman.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.

Change the vsqadd vector instrinsics to have the second argument as signed 
values, not unsigned,
accordingly to 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics


Repository:
  rC Clang

https://reviews.llvm.org/D64210

Files:
  include/clang/Basic/arm_neon.td


Index: include/clang/Basic/arm_neon.td
===
--- include/clang/Basic/arm_neon.td
+++ include/clang/Basic/arm_neon.td
@@ -707,7 +707,7 @@
 
 

 // Unsigned Saturating Accumulated of Signed Value
-def USQADD : SInst<"vsqadd", "ddd", "UcUsUiUlQUcQUsQUiQUl">;
+def USQADD : SInst<"vsqadd", "ddx", "UcUsUiUlQUcQUsQUiQUl">;
 
 

 // Reciprocal/Sqrt


Index: include/clang/Basic/arm_neon.td
===
--- include/clang/Basic/arm_neon.td
+++ include/clang/Basic/arm_neon.td
@@ -707,7 +707,7 @@
 
 
 // Unsigned Saturating Accumulated of Signed Value
-def USQADD : SInst<"vsqadd", "ddd", "UcUsUiUlQUcQUsQUiQUl">;
+def USQADD : SInst<"vsqadd", "ddx", "UcUsUiUlQUcQUsQUiQUl">;
 
 
 // Reciprocal/Sqrt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64211: [ARM] Fix vector vuqadd intrinsics operands

2019-07-04 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio created this revision.
dnsampaio added a reviewer: LukeCheeseman.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.

Change the vuqadd vector instrinsics to have the second argument as unsigned 
values, not signed,
accordingly to 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics


Repository:
  rC Clang

https://reviews.llvm.org/D64211

Files:
  include/clang/Basic/arm_neon.td


Index: include/clang/Basic/arm_neon.td
===
--- include/clang/Basic/arm_neon.td
+++ include/clang/Basic/arm_neon.td
@@ -703,7 +703,7 @@
 
 

 // Signed Saturating Accumulated of Unsigned Value
-def SUQADD : SInst<"vuqadd", "ddd", "csilQcQsQiQl">;
+def SUQADD : SInst<"vuqadd", "ddu", "csilQcQsQiQl">;
 
 

 // Unsigned Saturating Accumulated of Signed Value


Index: include/clang/Basic/arm_neon.td
===
--- include/clang/Basic/arm_neon.td
+++ include/clang/Basic/arm_neon.td
@@ -703,7 +703,7 @@
 
 
 // Signed Saturating Accumulated of Unsigned Value
-def SUQADD : SInst<"vuqadd", "ddd", "csilQcQsQiQl">;
+def SUQADD : SInst<"vuqadd", "ddu", "csilQcQsQiQl">;
 
 
 // Unsigned Saturating Accumulated of Signed Value
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64210: [ARM] Fix vector vsqadd intrinsics operands

2019-07-04 Thread Luke Cheeseman via Phabricator via cfe-commits
LukeCheeseman added a comment.

Are there some changes/addition to tests attached to this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64210



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


[PATCH] D64211: [ARM] Fix vector vuqadd intrinsics operands

2019-07-04 Thread Luke Cheeseman via Phabricator via cfe-commits
LukeCheeseman added a comment.

Are there some changes/addition to tests attached to this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64211



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


[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-07-04 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

F9459646: spirit-c5ceba.json 
F9459650: Снимок экрана от 2019-07-04 18-54-58.png 


I've upload json-file and printscreen of its visualization (used 
https://speedscope.app). This is an example of how this patch works, making two 
`Frontend` sections.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63325



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


[PATCH] D43159: Modernize: Use nullptr more.

2019-07-04 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: include/__threading_support:323
 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
-  return *__t == 0;
+  return *__t == nullptr;
 }

mclow.lists wrote:
> mclow.lists wrote:
> > This one is wrong.
> `__libcpp_thread_t` is an alias for an operating-system specific type.
> On Mac OS, it is a pointer to some Darwin-specific type.
> On Ubuntu, it is a `const unsigned long`.
> 
> You can't compare it to `nullptr`.
> 
I think the comparison should be `*__t == __libcpp_thread_t()`.


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D43159



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


[clang-tools-extra] r365151 - [clangd] Mark a couple of unimportant flags as hidden. NFC

2019-07-04 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Jul  4 11:49:08 2019
New Revision: 365151

URL: http://llvm.org/viewvc/llvm-project?rev=365151&view=rev
Log:
[clangd] Mark a couple of unimportant flags as hidden. NFC

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=365151&r1=365150&r2=365151&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Jul  4 11:49:08 2019
@@ -76,7 +76,7 @@ static llvm::cl::opt In
 clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP 
protocol"),
 clEnumValN(JSONStreamStyle::Delimited, "delimited",
"messages delimited by --- lines, with # comment support")),
-llvm::cl::init(JSONStreamStyle::Standard));
+llvm::cl::init(JSONStreamStyle::Standard), llvm::cl::Hidden);
 
 static llvm::cl::opt
 PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
@@ -215,7 +215,8 @@ static llvm::cl::opt EnableFunctio
 llvm::cl::desc("When disabled, completions contain only parentheses for "
"function calls. When enabled, completions also contain "
"placeholders for method parameters"),
-llvm::cl::init(CodeCompleteOptions().EnableFunctionArgSnippets));
+llvm::cl::init(CodeCompleteOptions().EnableFunctionArgSnippets),
+llvm::cl::Hidden);
 
 static llvm::cl::opt ClangTidyChecks(
 "clang-tidy-checks",


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


[PATCH] D64128: [CodeGen] Generate llvm.ptrmask instead of inttoptr(and(ptrtoint, C)) if possible.

2019-07-04 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D64128#1569836 , @hfinkel wrote:

> In D64128#1569817 , @rjmccall wrote:
>
> > The pointer/integer conversion is "implementation-defined", but it's not 
> > totally unconstrained.  C notes that "The mapping functions for converting 
> > a pointer to an integer or an integer to a pointer are intended to be 
> > consistent with the addressing structure of the execution environment.", 
> > and we do have to honor that.  The standard allows that "the result ... 
> > might not point to an entity of the referenced type", but when in fact it's 
> > guaranteed to do so (i.e. it's not just a coincidental result of an 
> > implementation decision like the exact address of a global variable — no 
> > "guessing"), I do think we have an obligation to make it work.  And on a 
> > practical level, there has to be *some* way of playing clever address 
> > tricks in the language in order to implement things like allocators and so 
> > forth.  So this makes me very antsy.
>
>
> I don't disagree. But I believe the question is if we have:
>
>   int *x = malloc(4);
>   int *y = malloc(4);
>   if (x & ~15 == y) {
> *(x & ~15) = 5; // Is this allowed, and if so, must the compiler assume 
> that it might set the value of *y?
>   }
>   
>
> I certainly agree that we must allow the implementation of allocators, etc. 
> But allocators, I think, have the opposite problem. They actually have some 
> large underlying objects (from mmap or whatever), and we want the rest of the 
> system to treat some subobjects of these larger objects as though they were 
> independent objects of some given types. From the point of view of the 
> allocator, we have x, and we have `void *memory_pool`, and we need to allow 
> `x & N` to point into `memory_pool`, but because, from the allocator's 
> perspective, we never knew that x didn't point into memory_pool (as, in fact, 
> it likely does), that should be fine (*).
>
> There might be more of an issue, for example, if for a given object, I happen 
> to know that there's some interesting structure at the beginning of its page 
> (or some other boundary).


This is what I was thinking about for allocators; this is a common 
implementation technique for `free` / `realloc` / `malloc_size`.

> If I also have a pointer to this structure via some other means, then maybe 
> this will cause a problem. This kind of thing certainly falls outside of the 
> C/C++ abstract machine, and I'd lean toward a flag for supporting it (not on 
> by default).

If you mean a theoretical minimal C abstract machine that does not correspond 
to an actual target and is therefore not bound by any of the statements in the 
C standard that say things like "this is expected to have its obvious 
translation on the target", then yes, I completely agree.  If you're talking 
about the actual C programming language that does correspond to actual targets, 
then it's not clear at all that it's outside the C abstract machine, because 
AFAICT integer-pointer conversions are (1) well-specified on specific targets 
by this de facto requirement of corresponding directly to pointer 
representations and (2) well-behaved as long as the integer does correspond to 
the address of an actual object of that type.

Also, please understand that compiler writers have been telling our users for 
decades that (1) pointer arithmetic is subject to some restrictions on penalty 
of UB and (2) they can avoid those restrictions by using pointer-integer 
conversions and doing integer arithmetic instead.  So any proposal to weaken 
the latter as a workaround makes me very worried, especially if it's also 
enforcing alignment restrictions that we've generally chosen not to enforce 
when separated from actual memory accesses.

> Also, and I could be wrong, but my impression is that all of this is extra - 
> this motivating use case requires generating the intrinsic from the code in 
> lib/CodeGen/TargetInfo.cpp - generating it from C/C++ expressions is just a 
> potential additional benefit.

I agree that we could use this intrinsic there safely, with the "object" being 
the variadic arguments area of the original va_list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64128



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


r365153 - [modules] Add PP callbacks for entering and leaving a submodule.

2019-07-04 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Thu Jul  4 12:06:52 2019
New Revision: 365153

URL: http://llvm.org/viewvc/llvm-project?rev=365153&view=rev
Log:
[modules] Add PP callbacks for entering and leaving a submodule.


Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/lib/Lex/PPLexerChange.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=365153&r1=365152&r2=365153&view=diff
==
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Thu Jul  4 12:06:52 2019
@@ -132,6 +132,28 @@ public:
   SrcMgr::CharacteristicKind FileType) {
   }
 
+  /// Callback invoked whenever a submodule was entered.
+  ///
+  /// \param M The submodule we have entered.
+  ///
+  /// \param ImportLoc The location of import directive token.
+  ///
+  /// \param ForPragma If entering from pragma directive.
+  ///
+  virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
+bool ForPragma) { }
+
+  /// Callback invoked whenever a submodule was left.
+  ///
+  /// \param M The submodule we have left.
+  ///
+  /// \param ImportLoc The location of import directive token.
+  ///
+  /// \param ForPragma If entering from pragma directive.
+  ///
+  virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc,
+ bool ForPragma) { }
+
   /// Callback invoked whenever there was an explicit module-import
   /// syntax.
   ///
@@ -395,6 +417,18 @@ public:
Imported, FileType);
   }
 
+  void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
+bool ForPragma) override {
+First->EnteredSubmodule(M, ImportLoc, ForPragma);
+Second->EnteredSubmodule(M, ImportLoc, ForPragma);
+  }
+
+  void LeftSubmodule(Module *M, SourceLocation ImportLoc,
+ bool ForPragma) override {
+First->LeftSubmodule(M, ImportLoc, ForPragma);
+Second->LeftSubmodule(M, ImportLoc, ForPragma);
+  }
+
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
 const Module *Imported) override {
 First->moduleImport(ImportLoc, Path, Imported);

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=365153&r1=365152&r2=365153&view=diff
==
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Thu Jul  4 12:06:52 2019
@@ -647,6 +647,8 @@ void Preprocessor::EnterSubmodule(Module
 BuildingSubmoduleStack.push_back(
 BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
   PendingModuleMacroNames.size()));
+if (Callbacks)
+  Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
 return;
   }
 
@@ -691,6 +693,9 @@ void Preprocessor::EnterSubmodule(Module
   BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
 PendingModuleMacroNames.size()));
 
+  if (Callbacks)
+Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
+
   // Switch to this submodule as the current submodule.
   CurSubmoduleState = &State;
 
@@ -731,6 +736,10 @@ Module *Preprocessor::LeaveSubmodule(boo
 // are tracking macro visibility, don't build any, and preserve the list
 // of pending names for the surrounding submodule.
 BuildingSubmoduleStack.pop_back();
+
+if (Callbacks)
+  Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
+
 makeModuleVisible(LeavingMod, ImportLoc);
 return LeavingMod;
   }
@@ -815,6 +824,9 @@ Module *Preprocessor::LeaveSubmodule(boo
 
   BuildingSubmoduleStack.pop_back();
 
+  if (Callbacks)
+Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
+
   // A nested #include makes the included submodule visible.
   makeModuleVisible(LeavingMod, ImportLoc);
   return LeavingMod;


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


[PATCH] D53295: Mark store and load of block invoke function as invariant.group

2019-07-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D53295#1561890 , @rjmccall wrote:

> Great, thank you.  Yaxun, are you planning to pick this back up?  I know it's 
> been a long time.


Sorry I caught up with some other work. Currently there has been another change 
about block which eliminates most indirect block calls, therefore the need for 
this patch is not so imminent now.


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

https://reviews.llvm.org/D53295



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


[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.

2019-07-04 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev closed this revision.
v.g.vassilev added a comment.
Herald added subscribers: wuzish, MaskRay.

r365153.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62293



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


[PATCH] D62960: Add SVE opaque built-in types

2019-07-04 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/AST/ItaniumMangle.cpp:2680
+break;
+#include "clang/Basic/AArch64SVEACLETypes.def"
   }

rsandifo-arm wrote:
> rovka wrote:
> > erik.pilkington wrote:
> > > rsandifo-arm wrote:
> > > > erik.pilkington wrote:
> > > > > jfb wrote:
> > > > > > @rjmccall you probably should review this part.
> > > > > Sorry for the drive by comment, but: All of these mangling should 
> > > > > really be using the "vendor extension" production IMO:
> > > > > 
> > > > > ` ::= u `
> > > > > 
> > > > > As is, these manglings intrude on the users's namespace, (i.e. if 
> > > > > they had a type named `objc_selector` or something), and confuse 
> > > > > demanglers which incorrectly assume these are substitutable (vendor 
> > > > > extension builtin types are substitutable too though, but that should 
> > > > > be handled here).
> > > > It isn't obvious from the patch, but the SVE names that we're mangling 
> > > > are predefined names like __SVInt8_t. rather than user-facing names 
> > > > like svint8_t  The predefined names and their mangling are defined by 
> > > > the platform ABI (https://developer.arm.com/docs/100986/), so it 
> > > > wouldn't be valid for another part of the implementation to use those 
> > > > names for something else.
> > > > 
> > > > I realise you were making a general point here though, sorry.
> > > > 
> > > The mangling in the document you linked does use the vendor extension 
> > > production here though, i.e. the example is `void f(int8x8_t)`, which 
> > > mangles to _Z1f**u10__Int8x8_t**. It is true that this shouldn't ever 
> > > collide with another mangling in practice, but my point is there isn't 
> > > any need to smuggle it into the mangling by pretending it's a user 
> > > defined type, when the itanium grammar and related tools have a special 
> > > way for vendors to add builtin types.
> > I agree with Erik here, the example in the PCS document seems to suggest 
> > using u. I think either the patch needs to be updated or the document needs 
> > to be more clear about what the mangling is supposed to look like.
> Thanks for highlighting this problem, and sorry for not noticing myself when 
> pointing you at the doc.
> 
> Unfortunately, the specification and implementation already difer for the 
> Advanced SIMD types, with both clang and GCC omitting the 'u' despite the 
> spec saying it should be present.  So we're considering changing the spec to 
> match what's now the de facto ABI.
> 
> For SVE we do still have the opportunity to use 'u'.  I've left it as-is for 
> now though, until we've reached a decision about whether to follow existing 
> practice for Advanced SIMD or whether to do what the spec says.
These do seem more "builtin" than the SIMD types, but I don't think it deeply 
matters either way, since these are already reserved names.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62960



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


[PATCH] D53295: Mark store and load of block invoke function as invariant.group

2019-07-04 Thread John McCall via Phabricator via cfe-commits
rjmccall added a reviewer: ahatanak.
rjmccall added a comment.
Herald added a subscriber: dexonsmith.

Okay.  Akira, do you have any interest in looking into this as a general block 
optimization?


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

https://reviews.llvm.org/D53295



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


[PATCH] D63845: [WIP] Create a clang attribute that lets users specify LLVM attributes

2019-07-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D63845#1566987 , @jdoerfert wrote:

> In D63845#1561983 , @lebedev.ri 
> wrote:
>
> > In D63845#1561793 , @jdoerfert 
> > wrote:
> >
> > > In D63845#1560605 , 
> > > @aaron.ballman wrote:
> > >
> > > > In D63845#1559995 , 
> > > > @lebedev.ri wrote:
> > > >
> > > > > What's the target use-case here? What can't be solved with normal 
> > > > > attributes?
> > > >
> > >
> > >
> > > With "normal" you mean something like `__attribute__((noescape))`? We 
> > > don't have them for all attributes, I doubt we want to but I might be 
> > > wrong.
> >
> >
> > That is precisely the question.
> >  What is the motivation for exposing such LLVM-specific low-level unstable 
> > implementation detail?
>
>
> I would disagree to the unstable part. Keeping LLVM-IR backward compatibility 
> is always a priority and changing the meaning of an existing LLVM-IR 
> attribute will break various things already.
>  Why would you think it is unstable?


Because, to date, we've never made blanket any stability guarantees about LLVM 
attributes from within the context of Clang. Instead, LLVM attributes are 
introduced into Clang on a case by case basis when they've been determined to 
be stable enough to warrant exposing. This extra layer also gives us more 
flexibility in translating frontend attributes into backend attributes.

> Also, we basically do expose the low-level parts one by one through "normal" 
> attributes as soon as someone has enough motivation to write all the 
> necessary boilerplate (see more below). Why not merge all the logic/code-gen 
> into a single uniform framework that deals with LLVM-IR attributes?

Because that increases the chance of bad user experiences by lowering the bar 
that ensures newly added attributes behave well for user code. That boilerplate 
exists for a reason and forces a developer to make decisions (like what number 
and kind of arguments are accepted, what spellings make sense for the 
attribute, what subjects the attribute appertains to, etc).

> I also wonder if all these should cause a clang diagnostic, at least 
> under `-Wall`.
>>> 
>>> What do you mean?
>> 
>> These are very much a generally-incompatible, very fragile, extensions.
>>  They will not work on any other compiler, and will likely not work
>>  on a different version of clang. It is not okay not to diagnose such cases.
> 
> It totally depends on your definition of "will not work". They might not be 
> recognized and therefore be ignored, correct. They should not be 
> misinterpreted as (1) the name should make them unambiguous and (2) LLVM-IR 
> needs to be backward compatible anyway. Take different version of clang and 
> `__attribute__((noescape))` for example, or take gcc. All the problems apply 
> but it is even far less obvious that it is not a language feature and will 
> not be portable (across compilers). (Given that various commercial compilers 
> are build on top of LLVM/Clang there is an argument for forward 
> compatibility.) I agree on the diagnose issue, we should, as we do, warn for 
> unrecognized attributes. But again, both clang and gcc do that by default.
> 
> As a side node, I actually want to provide user with a 
> "macro-portability-layer" that hides the spelling and even allows to remove 
> the attributes for incompatible compilers.  Though, one step at a time.
> 
> How is versioning expected to be handled? New attribute vs old clang, and 
> vice versa.
>>> 
>>> Unknown attributes are not necessarily a problem, they should compile fine 
>>> ignoring the attribute, or am I wrong?
>> 
>> I don't know, that's why i'm asking.
> 
> (See above.)
> 
> In D63845#1564289 , @aaron.ballman 
> wrote:
> 
>> > In D63845#1561983 , @lebedev.ri 
>> > wrote:
>> > 
>> >> In D63845#1561793 , @jdoerfert 
>> >> wrote:
>> >>
>> >> > In D63845#1560605 , 
>> >> > @aaron.ballman wrote:
>> >> >
>> >> > > In D63845#1559995 , 
>> >> > > @lebedev.ri wrote:
>> >> > >
>> >> > > > What's the target use-case here? What can't be solved with normal 
>> >> > > > attributes?
>> >> > >
>> >> >
>> >> >
>> >> > With "normal" you mean something like `__attribute__((noescape))`? We 
>> >> > don't have them for all attributes, I doubt we want to but I might be 
>> >> > wrong.
>> >>
>> >>
>> >> That is precisely the question.
>> >>  What is the motivation for exposing such LLVM-specific low-level 
>> >> unstable implementation detail?
>> > 
>> > 
>> > There's a couple of potential use cases for this -- most of which are more 
>> > for LLVM developers than end users.
>>
>> That's why I am hesit

[PATCH] D64156: Make joined instances of JoinedOrSeparate flags point to the unaliased args, like all other arg types do

2019-07-04 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

ruiu: ping


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

https://reviews.llvm.org/D64156



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


[PATCH] D63161: Devirtualize destructor of final class.

2019-07-04 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

https://reviews.llvm.org/rL364359

Why this was reverted ?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63161



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


[PATCH] D63161: Devirtualize destructor of final class.

2019-07-04 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a subscriber: rdhindsa.
xbolva00 added a comment.

You, @rdhindsa, should report here why you reverted this commit.

It is really weird to revert random commits without more information.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63161



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


r365160 - [NFC] Make some ObjectFormatType switches covering

2019-07-04 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Thu Jul  4 14:40:28 2019
New Revision: 365160

URL: http://llvm.org/viewvc/llvm-project?rev=365160&view=rev
Log:
[NFC] Make some ObjectFormatType switches covering

Summary:
This patch removes the `default` case from some switches on
`llvm::Triple::ObjectFormatType`, and cases for the missing enumerators
are then added.

For `UnknownObjectFormat`, the action (`llvm_unreachable`) for the
`default` case is kept.

For the other unhandled cases, `report_fatal_error` is used instead.

Reviewers: sfertile, jasonliu, daltenty

Reviewed By: sfertile

Subscribers: wuzish, aheejin, jsji, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=365160&r1=365159&r2=365160&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Jul  4 14:40:28 2019
@@ -4921,7 +4921,7 @@ llvm::Value *CGObjCMac::EmitIvarOffset(C
 std::string CGObjCCommonMac::GetSectionName(StringRef Section,
 StringRef MachOAttributes) {
   switch (CGM.getTriple().getObjectFormat()) {
-  default:
+  case llvm::Triple::UnknownObjectFormat:
 llvm_unreachable("unexpected object file format");
   case llvm::Triple::MachO: {
 if (MachOAttributes.empty())
@@ -4936,6 +4936,10 @@ std::string CGObjCCommonMac::GetSectionN
 assert(Section.substr(0, 2) == "__" &&
"expected the name to begin with __");
 return ("." + Section.substr(2) + "$B").str();
+  case llvm::Triple::Wasm:
+  case llvm::Triple::XCOFF:
+llvm::report_fatal_error(
+"Objective-C support is unimplemented for object file format.");
   }
 }
 


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


[PATCH] D63767: [NFC] Make some ObjectFormatType switches covering

2019-07-04 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365160: [NFC] Make some ObjectFormatType switches covering 
(authored by hubert.reinterpretcast, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D63767?vs=206436&id=208083#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63767

Files:
  cfe/trunk/lib/CodeGen/CGObjCMac.cpp
  llvm/trunk/include/llvm/Support/TargetRegistry.h


Index: llvm/trunk/include/llvm/Support/TargetRegistry.h
===
--- llvm/trunk/include/llvm/Support/TargetRegistry.h
+++ llvm/trunk/include/llvm/Support/TargetRegistry.h
@@ -470,7 +470,7 @@
  bool DWARFMustBeAtTheEnd) const {
 MCStreamer *S;
 switch (T.getObjectFormat()) {
-default:
+case Triple::UnknownObjectFormat:
   llvm_unreachable("Unknown object format");
 case Triple::COFF:
   assert(T.isOSWindows() && "only Windows COFF is supported");
@@ -504,6 +504,8 @@
 S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW),
std::move(Emitter), RelaxAll);
   break;
+case Triple::XCOFF:
+  report_fatal_error("XCOFF MCObjectStreamer not implemented yet.");
 }
 if (ObjectTargetStreamerCtorFn)
   ObjectTargetStreamerCtorFn(*S, STI);
Index: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp
@@ -4921,7 +4921,7 @@
 std::string CGObjCCommonMac::GetSectionName(StringRef Section,
 StringRef MachOAttributes) {
   switch (CGM.getTriple().getObjectFormat()) {
-  default:
+  case llvm::Triple::UnknownObjectFormat:
 llvm_unreachable("unexpected object file format");
   case llvm::Triple::MachO: {
 if (MachOAttributes.empty())
@@ -4936,6 +4936,10 @@
 assert(Section.substr(0, 2) == "__" &&
"expected the name to begin with __");
 return ("." + Section.substr(2) + "$B").str();
+  case llvm::Triple::Wasm:
+  case llvm::Triple::XCOFF:
+llvm::report_fatal_error(
+"Objective-C support is unimplemented for object file format.");
   }
 }
 


Index: llvm/trunk/include/llvm/Support/TargetRegistry.h
===
--- llvm/trunk/include/llvm/Support/TargetRegistry.h
+++ llvm/trunk/include/llvm/Support/TargetRegistry.h
@@ -470,7 +470,7 @@
  bool DWARFMustBeAtTheEnd) const {
 MCStreamer *S;
 switch (T.getObjectFormat()) {
-default:
+case Triple::UnknownObjectFormat:
   llvm_unreachable("Unknown object format");
 case Triple::COFF:
   assert(T.isOSWindows() && "only Windows COFF is supported");
@@ -504,6 +504,8 @@
 S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW),
std::move(Emitter), RelaxAll);
   break;
+case Triple::XCOFF:
+  report_fatal_error("XCOFF MCObjectStreamer not implemented yet.");
 }
 if (ObjectTargetStreamerCtorFn)
   ObjectTargetStreamerCtorFn(*S, STI);
Index: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp
@@ -4921,7 +4921,7 @@
 std::string CGObjCCommonMac::GetSectionName(StringRef Section,
 StringRef MachOAttributes) {
   switch (CGM.getTriple().getObjectFormat()) {
-  default:
+  case llvm::Triple::UnknownObjectFormat:
 llvm_unreachable("unexpected object file format");
   case llvm::Triple::MachO: {
 if (MachOAttributes.empty())
@@ -4936,6 +4936,10 @@
 assert(Section.substr(0, 2) == "__" &&
"expected the name to begin with __");
 return ("." + Section.substr(2) + "$B").str();
+  case llvm::Triple::Wasm:
+  case llvm::Triple::XCOFF:
+llvm::report_fatal_error(
+"Objective-C support is unimplemented for object file format.");
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62883: [analyzer] Track terminator conditions on which a tracked expressions depends

2019-07-04 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 208084.
Szelethus marked 6 inline comments as done.
Szelethus added a comment.

- Add two more test cases when a "Returning value" note is meaningful, and one 
where it's not
- Fix inlines!


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

https://reviews.llvm.org/D62883

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/track-control-dependency-conditions.cpp

Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- /dev/null
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -0,0 +1,285 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -verify=expected,tracking \
+// RUN:   -analyzer-config track-conditions=true \
+// RUN:   -analyzer-output=text \
+// RUN:   -analyzer-checker=core
+//
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -analyzer-output=text \
+// RUN:   -analyzer-checker=core
+
+namespace example_1 {
+int flag;
+bool coin();
+
+void foo() {
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+}
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  flag = 1;
+
+  foo(); // TODO: Add nodes here about flag's value being invalidated.
+  if (flag) // expected-note   {{Assuming 'flag' is 0}}
+// expected-note@-1{{Taking false branch}}
+x = new int;
+
+  foo(); // tracking-note{{Calling 'foo'}}
+ // tracking-note@-1{{Returning from 'foo'}}
+
+  if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
+// expected-note@-1{{Taking true branch}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace example_1
+
+namespace example_2 {
+int flag;
+bool coin();
+
+void foo() {
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+}
+
+void test() {
+  int *x = 0;
+  flag = 1;
+
+  foo();
+  if (flag) // expected-note   {{Assuming 'flag' is 0}}
+// expected-note@-1{{Taking false branch}}
+x = new int;
+
+  x = 0; // expected-note{{Null pointer value stored to 'x'}}
+
+  foo(); // tracking-note{{Calling 'foo'}}
+ // tracking-note@-1{{Returning from 'foo'}}
+
+  if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
+// expected-note@-1{{Taking true branch}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace example_2
+
+namespace global_variable_invalidation {
+int flag;
+bool coin();
+
+void foo() {
+  // coin() could write bar, do it's invalidated.
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+ // tracking-note@-1{{Value assigned to 'bar'}}
+}
+
+int bar;
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  flag = 1;
+
+  foo(); // tracking-note{{Calling 'foo'}}
+ // tracking-note@-1{{Returning from 'foo'}}
+
+  if (bar) // expected-note   {{Assuming 'bar' is not equal to 0}}
+   // expected-note@-1{{Taking true branch}}
+if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
+  // expected-note@-1{{Taking true branch}}
+  *x = 5; // expected-warning{{Dereference of null pointer}}
+  // expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace global_variable_invalidation
+
+namespace variable_declaration_in_condition {
+bool coin();
+
+bool foo() {
+  return coin(); // tracking-note{{Returning value}}
+}
+
+int bar;
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+  if (int flag = foo()) // tracking-note{{Calling 'foo'}}
+// tracking-note@-1{{Returning from 'foo'}}
+// tracking-note@-2{{'flag' initialized here}}
+
+// expected-note@-4{{Assuming 'flag' is not equal to 0}}
+// expected-note@-5{{Taking true branch}}
+
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace variable_declaration_in_condition
+
+namespace conversion_to_bool {
+bool coin();
+
+struct ConvertsToBool {
+  operator bool() const { return coin(); } // tracking-note{{Returning value}}
+};
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+
+  if (ConvertsToBool())
+// tracking-note@-1 {{Calling 'ConvertsToBool::operator bool'}}
+// tracking-note@-2{{Returning from 'ConvertsToBool::operator bool'}}
+
+// expected-note@-4{{Assuming the condition is true}}
+// expected-note@-5{{Taking tr

[PATCH] D64222: [sanitizers] Use covering ObjectFormatType switches

2019-07-04 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: sfertile, jasonliu, daltenty.
Herald added subscribers: sunfish, aheejin, hiraditya.
Herald added projects: clang, LLVM.

This patch removes the `default` case from some switches on 
`llvm::Triple::ObjectFormatType`, and cases for the missing enumerators 
(`UnknownObjectFormat`, `Wasm`, and `XCOFF`) are then added.

For `UnknownObjectFormat`, the effect of the action for the `default` case is 
maintained; otherwise, where `llvm_unreachable` is called, `report_fatal_error` 
is used instead.

Where the `default` case returns a default value, `report_fatal_error` is used 
for XCOFF as a placeholder. For `Wasm`, the effect of the action for the 
`default` case in maintained.

The code is structured to avoid strongly implying that the `Wasm` case is 
present for any reason other than to make the switch cover all 
`ObjectFormatType` enumerator values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64222

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1919,7 +1919,12 @@
   case Triple::COFF:  return ".ASAN$GL";
   case Triple::ELF:   return "asan_globals";
   case Triple::MachO: return "__DATA,__asan_globals,regular";
-  default: break;
+  case Triple::Wasm:
+  case Triple::XCOFF:
+report_fatal_error(
+"ModuleAddressSanitizer not implemented for object file format.");
+  case Triple::UnknownObjectFormat:
+break;
   }
   llvm_unreachable("unsupported object format");
 }
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -231,9 +231,13 @@
 return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
-  default:
-return false;
+  case Triple::XCOFF:
+llvm::report_fatal_error("ASan not implemented for XCOFF.");
+  case Triple::Wasm:
+  case Triple::UnknownObjectFormat:
+break;
   }
+  return false;
 }
 
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1919,7 +1919,12 @@
   case Triple::COFF:  return ".ASAN$GL";
   case Triple::ELF:   return "asan_globals";
   case Triple::MachO: return "__DATA,__asan_globals,regular";
-  default: break;
+  case Triple::Wasm:
+  case Triple::XCOFF:
+report_fatal_error(
+"ModuleAddressSanitizer not implemented for object file format.");
+  case Triple::UnknownObjectFormat:
+break;
   }
   llvm_unreachable("unsupported object format");
 }
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -231,9 +231,13 @@
 return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
-  default:
-return false;
+  case Triple::XCOFF:
+llvm::report_fatal_error("ASan not implemented for XCOFF.");
+  case Triple::Wasm:
+  case Triple::UnknownObjectFormat:
+break;
   }
+  return false;
 }
 
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63602: [Sanitizers] Don't use clang_rt.sancov_{begin, end} on Solaris

2019-07-04 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ping^2.  This one, like its companion https://reviews.llvm.org/D63601 has 
remained unreviewed for two weeks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63602



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


[PATCH] D64232: [analyzer] Prune calls to functions with linear CFGs that return a non-zero constrained value

2019-07-04 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, rnkovacs, baloghadamsoftware, 
dcoughlin, Charusso.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity.

During the evaluation of D62883 , I noticed a 
bunch of totally meaningless notes with the pattern of "Calling 'A'" -> 
"Returning value" -> "Returning from 'A'", which added no value to the report 
at all.

This patch (not only affecting tracked conditions mind you) prunes diagnostic 
messages to functions that return a value not constrained to be 0, and are also 
linear.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64232

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/diagnostics/find_last_store.c
  clang/test/Analysis/track-control-dependency-conditions.cpp
  clang/test/Analysis/uninit-vals.c

Index: clang/test/Analysis/uninit-vals.c
===
--- clang/test/Analysis/uninit-vals.c
+++ clang/test/Analysis/uninit-vals.c
@@ -149,8 +149,6 @@
   RetVoidFuncType f = foo_radar12278788_fp;
   return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}
 //expected-note@-1 {{Undefined or garbage value returned to caller}}
-//expected-note@-2 {{Calling 'foo_radar12278788_fp'}}
-//expected-note@-3 {{Returning from 'foo_radar12278788_fp'}}
 }
 
 void rdar13665798() {
@@ -164,8 +162,6 @@
 RetVoidFuncType f = foo_radar12278788_fp;
 return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}
   //expected-note@-1 {{Undefined or garbage value returned to caller}}
-  //expected-note@-2 {{Calling 'foo_radar12278788_fp'}}
-  //expected-note@-3 {{Returning from 'foo_radar12278788_fp'}}
   }();
 }
 
@@ -182,18 +178,14 @@
 void use(struct Point p); 
 
 void testUseHalfPoint() {
-  struct Point p = getHalfPoint(); // expected-note{{Calling 'getHalfPoint'}}
-   // expected-note@-1{{Returning from 'getHalfPoint'}}
-   // expected-note@-2{{'p' initialized here}}
+  struct Point p = getHalfPoint(); // expected-note{{'p' initialized here}}
   use(p); // expected-warning{{uninitialized}}
   // expected-note@-1{{uninitialized}}
 }
 
 void testUseHalfPoint2() {
   struct Point p;
-  p = getHalfPoint(); // expected-note{{Calling 'getHalfPoint'}}
-  // expected-note@-1{{Returning from 'getHalfPoint'}}
-  // expected-note@-2{{Value assigned to 'p'}}
+  p = getHalfPoint(); // expected-note{{Value assigned to 'p'}}
   use(p); // expected-warning{{uninitialized}}
   // expected-note@-1{{uninitialized}}
 }
Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -140,18 +140,16 @@
 bool coin();
 
 struct ConvertsToBool {
-  operator bool() const { return coin(); } // tracking-note{{Returning value}}
+  operator bool() const { return coin(); }
 };
 
 void test() {
   int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
 
   if (ConvertsToBool())
-// tracking-note@-1 {{Calling 'ConvertsToBool::operator bool'}}
-// tracking-note@-2{{Returning from 'ConvertsToBool::operator bool'}}
-// debug-note@-3{{Tracking condition 'ConvertsToBool()'}}
-// expected-note@-4{{Assuming the condition is true}}
-// expected-note@-5{{Taking true branch}}
+// debug-note@-1{{Tracking condition 'ConvertsToBool()'}}
+// expected-note@-2{{Assuming the condition is true}}
+// expected-note@-3{{Taking true branch}}
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -161,18 +159,16 @@
 namespace unimportant_returning_value_note {
 bool coin();
 
-bool flipCoin() { return coin(); } // tracking-note{{Returning value}}
+bool flipCoin() { return coin(); }
 
 void i(int *ptr) {
   if (ptr) // expected-note{{Assuming 'ptr' is null}}
// expected-note@-1{{Taking false branch}}
 ;
   if (!flipCoin())
-// tracking-note@-1{{Calling 'flipCoin'}}
-// tracking-note@-2{{Returning from 'flipCoin'}}
-// debug-note@-3{{Tracking condition '!flipCoin()'}}
-// expected-note@-4{{Assuming the condition is true}}
-// expected-note@-5{{Taking true branch}}
+// debug-note@-1{{Tracking condition '!flipCoin()'}}
+// expected-note@-2{{Assuming the condition is true}}
+// expected-note@-3{{Taking true b

[PATCH] D63538: [CFG] Add a new function to get the proper condition of a CFGBlock

2019-07-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks great, thanks!


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

https://reviews.llvm.org/D63538



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


[PATCH] D62883: [analyzer] Track terminator conditions on which a tracked expressions depends

2019-07-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Accept².




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1824-1825
+  // because of this, let's explain why we believe control reached this point.
+  // TODO: Shouldn't we track control dependencies of every bug location, 
rather
+  // than only tracked expressions?
+  if (LVState->getAnalysisManager().getAnalyzerOptions().ShouldTrackConditions)

To think: not sure you want to do this for memory leak reports, because the 
place where the leak is discovered (i.e., where we randomly decided to run 
garbage collection and noticed a leak) may be fairly weird. Path to that point 
may still be moderately interesting (after all, it presumably doesn't leak on 
other paths), but i'm still worried that we may bring in some completely 
unrelated stuff. I might be wrong.


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

https://reviews.llvm.org/D62883



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


[PATCH] D64232: [analyzer] Prune calls to functions with linear CFGs that return a non-zero constrained value

2019-07-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I guess this makes sense. The results look good. I'm slightly worried that 
we're fighting the symptoms rather than the root cause here: why were these 
values tracked that far in the first place when we already have no interest in 
tracking them at the end of the function? I.e., i suspect that your "mild 
tracking mode" would get rid of a lot of those automagically.




Comment at: clang/test/Analysis/uninit-vals.c:181
 void testUseHalfPoint() {
-  struct Point p = getHalfPoint(); // expected-note{{Calling 'getHalfPoint'}}
-   // expected-note@-1{{Returning from 
'getHalfPoint'}}
-   // expected-note@-2{{'p' initialized here}}
+  struct Point p = getHalfPoint(); // expected-note{{'p' initialized here}}
   use(p); // expected-warning{{uninitialized}}

Huh, so there's not even a note in `getHalfPoint()`, just calling..returning? 
This definitely needs some attention from `NoStoreFuncVisitor`.

Generally, i think this is probably the single place where we do really want 
some info about what happens in `getHalfPoint()`. The report that consists only 
of "p is initialized..." and "...p is uninitialized" is pretty weird. Btw, 
could you write down the full warning text in this test? How bad this actually 
is?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64232



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


[PATCH] D64123: Add clang-llvm-rename tool.

2019-07-04 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu updated this revision to Diff 208116.
ruiu added a comment.

- updated a few special mappings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64123

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-llvm-rename/CMakeLists.txt
  clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp

Index: clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp
@@ -0,0 +1,277 @@
+//=== ClangLLVMRename.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a refactoring tool to rename variables so that they start with a
+// lowercase letter. This tool is intended to be used to rename variables in
+// LLVM codebase in which variable names start with an uppercase letter at
+// the moment.
+//
+//   Usage:
+//   clang-llmv-rename   ...
+//
+//  ... specify the paths of files in the CMake source tree. This
+// path is looked up in the compile command database.
+//
+//
+// For each variable in given files, the tool first check whether the
+// variable's definition is in one of given files or not, and rename it if
+// and only if it can find a definition of the variable. If the tool cannot
+// modify a definition of a variable, it doesn't rename it, in order to keep
+// a program compiles.
+//
+// Note that this tool is not perfect; it doesn't resolve or even detect
+// name conflicts caused by renaming. You may need to rename variables
+// before using this tool so that your program is free from name conflicts
+// due to lowercase/uppercase renaming.
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+using namespace clang::tooling;
+using namespace llvm;
+
+namespace {
+class RenameCallback : public MatchFinder::MatchCallback {
+public:
+  RenameCallback(
+  std::map &FileToReplacements,
+  ArrayRef Paths)
+  : FileToReplacements(FileToReplacements) {
+for (StringRef S : Paths)
+  InputFiles.insert(canonicalizePath(S));
+  }
+
+  // This function is called for each AST pattern matche.
+  void run(const MatchFinder::MatchResult &Result) override {
+SourceManager &SM = *Result.SourceManager;
+
+if (auto *D = Result.Nodes.getNodeAs("VarDecl")) {
+  if (isa(D))
+return;
+  if (isGlobalConst(D))
+return;
+  convert(SM, D->getLocation(), D->getName());
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("ParmVarDecl")) {
+  if (auto *Fn =
+  dyn_cast_or_null(D->getParentFunctionOrMethod()))
+if (Fn->isImplicit())
+  return;
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("FieldDecl")) {
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("DeclRefExpr")) {
+  if (!isInGivenFiles(SM, D->getFoundDecl()->getLocation()))
+return;
+  if (isa(D->getDecl()) ||
+  isa(D->getDecl()))
+return;
+  if (auto *Decl = dyn_cast(D->getFoundDecl()))
+if (isGlobalConst(Decl))
+  return;
+  if (D->getDecl()->getName().empty())
+return;
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("MemberExpr")) {
+  if (!isInGivenFiles(SM, D->getFoundDecl()->getLocation()))
+return;
+  if (D->getMemberDecl()->getName().empty())
+return;
+  convert(SM, D->getMemberLoc(), D->getMemberDecl()->getName());
+  return;
+}
+
+if (auto *D =
+Result.Nodes.getNodeAs("CXXCtorInitializer")) {
+  if (!isInGivenFiles(SM, D->getMemberLocation()))
+return;
+  convert(SM, D->get

r365174 - Silence gcc warning "control reaches end of non-void function" [NFCI]

2019-07-04 Thread Mikael Holmen via cfe-commits
Author: uabelho
Date: Thu Jul  4 23:12:24 2019
New Revision: 365174

URL: http://llvm.org/viewvc/llvm-project?rev=365174&view=rev
Log:
Silence gcc warning "control reaches end of non-void function" [NFCI]

Without this fix gcc (7.4) complains with

 /data/repo/master/clang/lib/CodeGen/CGObjCMac.cpp: In member function 
'std::__cxx11::string 
{anonymous}::CGObjCCommonMac::GetSectionName(llvm::StringRef, llvm::StringRef)':
 /data/repo/master/clang/lib/CodeGen/CGObjCMac.cpp:4944:1: error: control 
reaches end of non-void function [-Werror=return-type]
  }
  ^

All values in the ObjectFormatType enum are currently handled in the switch
but gcc complains anyway.

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=365174&r1=365173&r2=365174&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Jul  4 23:12:24 2019
@@ -4941,6 +4941,8 @@ std::string CGObjCCommonMac::GetSectionN
 llvm::report_fatal_error(
 "Objective-C support is unimplemented for object file format.");
   }
+
+  llvm_unreachable("Unhandled llvm::Triple::ObjectFormatType enum");
 }
 
 /// EmitImageInfo - Emit the image info marker used to encode some module


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