[PATCH] D118698: [clangd][nfc] cleanup of remaining clang-tidy findings

2022-02-03 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f8da95e070e: [clangd][nfc] cleanup of remaining clang-tidy 
findings (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118698

Files:
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -42,7 +42,6 @@
 using ::testing::Pair;
 using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
-using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher withFix(::testing::Matcher FixMatcher) {
   return Field(&Diag::Fixes, ElementsAre(FixMatcher));
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -254,8 +254,9 @@
 if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
-  } else if (Node->Parent->ASTNode.get() ||
- Node->Parent->ASTNode.get()) {
+  }
+  if (Node->Parent->ASTNode.get() ||
+  Node->Parent->ASTNode.get()) {
 // Node is TypeLoc, but it's parent is either TypeLoc or
 // NestedNameSpecifier. In both cases, we want to go up, to find
 // the outermost TypeLoc.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1928,9 +1928,9 @@
   // FIXME: use HeuristicResolver to unwrap smart pointers?
 
   // Function type => return type.
-  if (auto FT = T->getAs())
+  if (auto *FT = T->getAs())
 return unwrapFindType(FT->getReturnType());
-  if (auto CRD = T->getAsCXXRecordDecl()) {
+  if (auto *CRD = T->getAsCXXRecordDecl()) {
 if (CRD->isLambda())
   return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType());
 // FIXME: more cases we'd prefer the return type of the call operator?
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -349,8 +349,7 @@
 if (auto Scalar = scalarValue(N, Desc)) {
   if (auto Bool = llvm::yaml::parseBool(**Scalar))
 return Located(*Bool, Scalar->Range);
-  else
-warning(Desc + " should be a boolean", N);
+  warning(Desc + " should be a boolean", N);
 }
 return llvm::None;
   }


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -42,7 +42,6 @@
 using ::testing::Pair;
 using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
-using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher withFix(::testing::Matcher FixMatcher) {
   return Field(&Diag::Fixes, ElementsAre(FixMatcher));
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -254,8 +254,9 @@
 if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
-  } else if (Node->Parent->ASTNode.get() ||
- Node->Parent->ASTNode.get()) {
+  }
+  if (Node->Parent->ASTNode.get() ||
+  Node->Parent->ASTNode.get()) {
 // Node is TypeLoc, but it's parent is either TypeLoc or
 // NestedNameSpecifier. In both cases, we want to go up, to find
 // the outermost TypeLoc.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1928,9 +1928,9 @@
   // FIXME: use HeuristicResolver to unwrap smart pointers?
 
   // Function type => return type.
-  if (auto FT = T->getAs())
+  if (auto *FT = T->getAs())
 return unwrapFindType(FT->getReturnType());
-  if (auto CRD = T->getAsCXXRecordDecl()) {
+  if (auto *CRD = T->getAsCXXRecordDecl()) {
 if (CRD->isLambda())
   return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType());
 // FIXME: more cases we'd prefer the return type of the call operator?
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===

[PATCH] D118698: [clangd][nfc] cleanup of remaining clang-tidy findings

2022-02-01 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
kuhnel added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
kuhnel requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

There were some left-overs (or new things) from the previous patches.

This will get us down to 0 open findings except:
clang-tidy is complaining in some files about
`warning: #includes are not sorted properly [llvm-include-order]`
however, clang-format does revert these changes.
It looks like clang-tidy and clang-format disagree there.

Not sure how we can fix that...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118698

Files:
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -42,7 +42,6 @@
 using ::testing::Pair;
 using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
-using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher withFix(::testing::Matcher FixMatcher) {
   return Field(&Diag::Fixes, ElementsAre(FixMatcher));
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -254,8 +254,9 @@
 if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
-  } else if (Node->Parent->ASTNode.get() ||
- Node->Parent->ASTNode.get()) {
+  }
+  if (Node->Parent->ASTNode.get() ||
+  Node->Parent->ASTNode.get()) {
 // Node is TypeLoc, but it's parent is either TypeLoc or
 // NestedNameSpecifier. In both cases, we want to go up, to find
 // the outermost TypeLoc.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1930,9 +1930,9 @@
   // FIXME: use HeuristicResolver to unwrap smart pointers?
 
   // Function type => return type.
-  if (auto FT = T->getAs())
+  if (auto *FT = T->getAs())
 return unwrapFindType(FT->getReturnType());
-  if (auto CRD = T->getAsCXXRecordDecl()) {
+  if (auto *CRD = T->getAsCXXRecordDecl()) {
 if (CRD->isLambda())
   return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType());
 // FIXME: more cases we'd prefer the return type of the call operator?
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -349,8 +349,7 @@
 if (auto Scalar = scalarValue(N, Desc)) {
   if (auto Bool = llvm::yaml::parseBool(**Scalar))
 return Located(*Bool, Scalar->Range);
-  else
-warning(Desc + " should be a boolean", N);
+  warning(Desc + " should be a boolean", N);
 }
 return llvm::None;
   }


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -42,7 +42,6 @@
 using ::testing::Pair;
 using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
-using testing::UnorderedElementsAreArray;
 
 ::testing::Matcher withFix(::testing::Matcher FixMatcher) {
   return Field(&Diag::Fixes, ElementsAre(FixMatcher));
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -254,8 +254,9 @@
 if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
-  } else if (Node->Parent->ASTNode.get() ||
- Node->Parent->ASTNode.get()) {
+  }
+  if (Node->Parent->ASTNode.get() ||
+  Node->Parent->ASTNode.get()) {
 // Node is TypeLoc, but it's parent is either TypeLoc or
 // NestedNameSpecifier. In both cases, we want to go up, to find
 // the outermost TypeLoc.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1930,9 +1930,9 @@
   // FIXME: use HeuristicResolver to unwrap smart pointers?
 
   // Function type => return type.
-  if (auto FT = T->getAs())
+  if (auto *FT = T->getAs())
 return unwrapFindType(F

[PATCH] D115634: [clangd] Cleanup of readability-identifier-naming

2022-02-01 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked 4 inline comments as done.
kuhnel added a comment.

Thx @sammccall for your patience with this cleanup.




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:103
 
-static clang::clangd::Key kFileBeingProcessed;
+static clang::clangd::Key KFileBeingProcessed;
 

sammccall wrote:
> I think this got reverted - should just be `FileBeingProcessed`
Right, sorry about the backsliding there. If I were ever to do such a cleanup 
again, I need to really split manual and automatic steps into separate commits 
and keep them in a separate branch before squashing them for `arc diff`.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1864
   }
-  QualType VisitCoyieldStmt(const CoyieldExpr *S) {
+  QualType visitCoyieldStmt(const CoyieldExpr *S) {
 return type(S->getOperand());

sammccall wrote:
> this was a bug! should be `VisitCoyieldExpr` (capital because it's a CRTP 
> override).
> 
> But this is is a functional bugfix, please either leave a fixme or change in 
> a separate patch
added FIXME, feel feel free to create a patch for it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115634

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


[PATCH] D115634: [clangd] Cleanup of readability-identifier-naming

2022-01-27 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked 6 inline comments as done.
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/fuzzer/FuzzerClangdMain.cpp:15
 
+// NOLINTNEXTLINE(readability-identifier-naming)
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);

sammccall wrote:
> This name is always exempt, and should rather be excluded by config: 
> https://clang.llvm.org/extra/clang-tidy/checks/readability-identifier-naming.html#cmdoption-arg-functionignoredregexp
I tried a couple of variations of the config in the global `.clang-tidy` file, 
however none of them actually ignored the function:

```yaml
  - key: readability-identifier-naming.FunctionIgnoredRegexp
value:   "LLVMFuzzerTest.*"
```

Any idea what I'm doing wrong?



Comment at: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp:39
 ::testing::Matcher
-RefsAre(std::vector<::testing::Matcher> Matchers) {
+refsAre(std::vector<::testing::Matcher> Matchers) {
   return ElementsAre(::testing::Pair(_, UnorderedElementsAreArray(Matchers)));

sammccall wrote:
> Note that `MATCHER_P(FileURI, F, "") { ... ]` above also defines a function 
> returning a `Matcher`.
> 
> I think it's OK for our functions to have different case than matcher 
> functions from the upstream gtest (different libraries have different 
> styles), but I don't think it's OK for matcher functions to have different 
> case depending on whether `MATCHER_P` was used or not.
> 
> And I agree that `//NOLINT` everywhere is not a good option.
> 
> So as far as I'm concerned:
> - OK: change these functions and also all the MATCHER, MATCHER_P etc 
> instances to lowerCamelCase
> - OK: ignore this style rule and check results for matcher names
> - Not OK: follow the rule for explicitly-defined function but ignore it for 
> `MATCHER_P`s
> - Not OK: ignore the rule and add // NOLINT to enough exceptions to silence 
> the checker
> - Bonus: teach the tidy check to flag violations introduced through macros 
> (probably with an allowlist of macro names)
> 
> (I'm not quite sure how our convention of using UpperCamelCase for matcher 
> factory functions got started, but I suspect it's from following upstream 
> recipes without thinking hard about whether the new symbol is a function or a 
> type).
My proposal here is to stick with the gtest naming convention for more 
consistency in the naming: Matchers start with upper case letters.

Thus I added //NOLINT to all matchers I encountered.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115634

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


[PATCH] D115634: [clangd] Cleanup of readability-identifier-naming

2022-01-27 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 403539.
kuhnel marked an inline comment as done.
kuhnel added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115634

Files:
  .clang-tidy
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
  clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IndexActionTests.cpp
  clang-tools-extra/clangd/unittests/JSONTransportTests.cpp
  clang-tools-extra/clangd/unittests/QualityTests.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/SymbolInfoTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
  clang-tools-extra/clangd/unittests/support/TraceTests.cpp

Index: clang-tools-extra/clangd/unittests/support/TraceTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/TraceTests.cpp
+++ clang-tools-extra/clangd/unittests/support/TraceTests.cpp
@@ -39,7 +39,7 @@
 
 // Checks that N is a Mapping (JS object) with the expected scalar properties.
 // The object must have all the Expected properties, but may have others.
-bool VerifyObject(llvm::yaml::Node &N,
+bool VerifyObject(llvm::yaml::Node &N, // NOLINT(readability-identifier-naming)
   std::map Expected) {
   auto *M = llvm::dyn_cast(&N);
   if (!M) {
Index: clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
+++ clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
@@ -29,7 +29,7 @@
   int Counter(0); /* GUARDED_BY(Mutex) */
   {
 AsyncTaskRunner Tasks;
-auto scheduleIncrements = [&]() {
+auto ScheduleIncrements = [&]() {
   for (int TaskI = 0; TaskI < TasksCnt; ++TaskI) {
 Tasks.runAsync("task", [&Counter, &Mutex, IncrementsPerTask]() {
   for (int Increment = 0; Increment < IncrementsPerTask; ++Increment) {
@@ -44,7 +44,7 @@
   // Make sure runAsync is not running tasks synchronously on the same
   // thread by locking the Mutex used for increments.
   std::lock_guard Lock(Mutex);
-  scheduleIncrements();
+  ScheduleIncrements();
 }
 
 Tasks.wait();
@@ -56,7 +56,7 @@
 {
   std::lock_guard Lock(Mutex);
   Counter = 0;
-  scheduleIncrements();
+  ScheduleIncrements();
 }
   }
   // Check that destructor has waited for tasks to finish.
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -60,6 +60,7 @@
 // Extracts ranges from an annotated example, and constructs a matcher for a
 // highlight set. Ranges should be named $read/$write as appropriate.
 Matcher &>
+// NOLINTNEXTLINE(readability-identifier-naming)
 HighlightsFrom(const Annotations &Test) {
   std::vector Expected;
   auto Add = [&](const Range &R, DocumentHighlightKind K) {
Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -39,11 +39,13 @@
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
 MATCHER_P(SelectionRangeIs, R, "") { return arg.selectionRange == R; }
 template 
+// NOLINTNEXTLINE(readability-identifier-naming)
 ::testing::Matcher Parents(ParentMatchers... ParentsM) {
   return Field(&TypeHierarchyItem::parents,
HasValue(UnorderedElementsAre(ParentsM...)));
 }
 template 
+// NOLINTNEXTLINE(readability-identifier-naming)
 ::testing::Matcher Children(ChildMatchers... ChildrenM) {
   return Field(&TypeHierarchyItem::children,
HasValue(Unordere

[PATCH] D115634: [clangd] Cleanup of readability-identifier-naming

2022-01-27 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 403538.
kuhnel added a comment.
Herald added a subscriber: aheejin.

Re-created the patch as there were too many changes in the repo.

Excluding gtest Matchers from naming checks as gtest convention does not match
LLVM convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115634

Files:
  .clang-tidy
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
  clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IndexActionTests.cpp
  clang-tools-extra/clangd/unittests/JSONTransportTests.cpp
  clang-tools-extra/clangd/unittests/QualityTests.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/SymbolInfoTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
  clang-tools-extra/clangd/unittests/support/TraceTests.cpp

Index: clang-tools-extra/clangd/unittests/support/TraceTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/TraceTests.cpp
+++ clang-tools-extra/clangd/unittests/support/TraceTests.cpp
@@ -39,7 +39,7 @@
 
 // Checks that N is a Mapping (JS object) with the expected scalar properties.
 // The object must have all the Expected properties, but may have others.
-bool VerifyObject(llvm::yaml::Node &N,
+bool VerifyObject(llvm::yaml::Node &N, // NOLINT(readability-identifier-naming)
   std::map Expected) {
   auto *M = llvm::dyn_cast(&N);
   if (!M) {
Index: clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
===
--- clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
+++ clang-tools-extra/clangd/unittests/support/ThreadingTests.cpp
@@ -29,7 +29,7 @@
   int Counter(0); /* GUARDED_BY(Mutex) */
   {
 AsyncTaskRunner Tasks;
-auto scheduleIncrements = [&]() {
+auto ScheduleIncrements = [&]() {
   for (int TaskI = 0; TaskI < TasksCnt; ++TaskI) {
 Tasks.runAsync("task", [&Counter, &Mutex, IncrementsPerTask]() {
   for (int Increment = 0; Increment < IncrementsPerTask; ++Increment) {
@@ -44,7 +44,7 @@
   // Make sure runAsync is not running tasks synchronously on the same
   // thread by locking the Mutex used for increments.
   std::lock_guard Lock(Mutex);
-  scheduleIncrements();
+  ScheduleIncrements();
 }
 
 Tasks.wait();
@@ -56,7 +56,7 @@
 {
   std::lock_guard Lock(Mutex);
   Counter = 0;
-  scheduleIncrements();
+  ScheduleIncrements();
 }
   }
   // Check that destructor has waited for tasks to finish.
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -60,6 +60,7 @@
 // Extracts ranges from an annotated example, and constructs a matcher for a
 // highlight set. Ranges should be named $read/$write as appropriate.
 Matcher &>
+// NOLINTNEXTLINE(readability-identifier-naming)
 HighlightsFrom(const Annotations &Test) {
   std::vector Expected;
   auto Add = [&](const Range &R, DocumentHighlightKind K) {
Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -39,11 +39,13 @@
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
 MATCHER_P(SelectionRangeIs, R, "") { return arg.selectionRange == R; }
 template 
+// NOLINTNEXTLINE(readability-identifier-naming)
 ::testing::Matcher Parents(ParentMatchers... ParentsM) {
   return Field(&TypeHierarchyItem::parents,
HasValue(UnorderedElementsAre(ParentsM...)));
 }
 template 
+// NOLINTNEXTLINE(readability-identifier-naming)
 ::test

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2022-01-25 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0e3c893aa09: [NFC][clangd] cleaning up llvm-qualified-auto 
(authored by kuhnel).

Changed prior to commit:
  https://reviews.llvm.org/D113898?vs=393894&id=402869#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace ns { class X { static void foo(); void bar(); }; }
 void ns::X::b^ar() {
   foo();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace ns

[PATCH] D117773: [clang-tidy] added JSON output to clang-tidy-diff.py

2022-01-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, xazax.hun.
kuhnel requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang-tools-extra.

This makes it easier to process the clang-tidy output in other tools.
For far it's only parsing the findings, not the output on stderr.

For testing you can use:

  bash
  ninja clangd
  COMMIT=4dedd82cc99341d757a9cc07a8b7b22c8bb61d19
  git diff $COMMIT~ $COMMIT | python3 
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py -p1 -json -checks="*"

This is part of the effort towards re-enabling clang-tidy in
pre-merge testing. With JSON output, we can deprecate some local
code in pre-merge testing.

https://github.com/google/llvm-premerge-checks/issues/367


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117773

Files:
  clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -35,6 +35,7 @@
 import tempfile
 import threading
 import traceback
+from typing import Optional
 
 try:
   import yaml
@@ -49,7 +50,7 @@
 import queue as queue
 
 
-def run_tidy(task_queue, lock, timeout):
+def run_tidy(task_queue, lock, timeout, result_queue: Optional[queue.Queue]):
   watchdog = None
   while True:
 command = task_queue.get()
@@ -65,8 +66,11 @@
   stdout, stderr = proc.communicate()
 
   with lock:
-sys.stdout.write(stdout.decode('utf-8') + '\n')
-sys.stdout.flush()
+if result_queue:
+  parse_clang_tidy_output(result_queue, stdout.decode('utf-8'))
+else:
+  sys.stdout.write(stdout.decode('utf-8') + '\n')
+  sys.stdout.flush()
 if stderr:
   sys.stderr.write(stderr.decode('utf-8') + '\n')
   sys.stderr.flush()
@@ -83,9 +87,9 @@
   task_queue.task_done()
 
 
-def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout, result_queue):
   for _ in range(max_tasks):
-t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout, result_queue))
 t.daemon = True
 t.start()
 
@@ -115,6 +119,18 @@
 open(mergefile, 'w').close()
 
 
+def parse_clang_tidy_output(result_queue: queue, clang_tidy_output: str):
+  """Parse the clang-tidy output and add them to the result queue."""
+  _regex_pattern = r"^(?P/[^:]+):\W*(?P\d+):\W*(?P\d+):\W*(?P.*)$"
+  for finding in re.finditer(_regex_pattern, clang_tidy_output, re.MULTILINE):
+result_queue.put({
+'path': finding['path'],
+'line': int(finding['line']),
+'character': int(finding['character']),
+'check': finding['check'],
+})
+
+
 def main():
   parser = argparse.ArgumentParser(description=
'Run clang-tidy against changed files, and '
@@ -160,6 +176,8 @@
   'command line.')
   parser.add_argument('-quiet', action='store_true', default=False,
   help='Run clang-tidy in quiet mode')
+  parser.add_argument('-json', action='store_true', dest='json_output',
+  help='Output clang-tidy results in JSON format.')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -214,8 +232,14 @@
   # A lock for console output.
   lock = threading.Lock()
 
+  # if we want JSON output: gather results
+  result_queue = None
+  if args.json_output:
+result_queue = queue.Queue()
+
   # Run a pool of clang-tidy workers.
-  start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout)
+  start_workers(max_task_count, run_tidy, task_queue,
+lock, args.timeout, result_queue)
 
   # Form the common args list.
   common_clang_tidy_args = []
@@ -227,7 +251,7 @@
 common_clang_tidy_args.append('-quiet')
   if args.build_path is not None:
 common_clang_tidy_args.append('-p=%s' % args.build_path)
-  if args.use_color:
+  if args.use_color and not args.json_output:
 common_clang_tidy_args.append('--use-color')
   for arg in args.extra_arg:
 common_clang_tidy_args.append('-extra-arg=%s' % arg)
@@ -268,6 +292,8 @@
   if tmpdir:
 shutil.rmtree(tmpdir)
 
-
+  if args.json_output:
+json_output = {'findings': list(result_queue.queue)} 
+json.dump(json_output, sys.stdout, indent=2)
 if __name__ == '__main__':
   main()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2022-01-18 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

TODO: check for remaining `const` then submit.




Comment at: clang-tools-extra/clangd/unittests/FileIndexTests.cpp:252
 TEST(FileIndexTest, TemplateParamsInLabel) {
-  auto Source = R"cpp(
+  const auto *Source = R"cpp(
 template 

remove const here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D115634: [clangd] Cleanup of readability-identifier-naming

2022-01-18 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Discussion in team sync, work for myself:

- most changes are in unittests --> propose something for the matchers
- cleaning up constants makes sense
- clean up this patch, then do another round of reviews


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115634

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


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-13 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked 3 inline comments as done.
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2550
   auto AST = TU.build();
-  for (auto Comment : {"doc1", "doc2", "doc3"}) {
+  for (const auto *Comment : {"doc1", "doc2", "doc3"}) {
 for (const auto &P : T.points(Comment)) {

while clang-tidy added a const here, I would keep it for consistency with the 
next line...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-13 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 393894.
kuhnel added a comment.

more reverts of consts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace ns { class X { static void foo(); void bar(); }; }
 void ns::X::b^ar() {
   foo();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace ns { class X { static void foo(); void bar(){
   foo();
 } }; }
@@ -654,7 +654,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplParamNames) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 struct Foo {
   struct Bar {
 template 

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-13 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 393892.
kuhnel added a comment.

fixed more const ClangdTests.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace ns { class X { static void foo(); void bar(); }; }
 void ns::X::b^ar() {
   foo();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace ns { class X { static void foo(); void bar(){
   foo();
 } }; }
@@ -654,7 +654,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTe

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-13 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 393890.
kuhnel added a comment.

reverted the `const` as advised in Sam's comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace ns { class X { static void foo(); void bar(); }; }
 void ns::X::b^ar() {
   foo();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace ns { class X { static void foo(); void bar(){
   foo();
 } }; }
@@ -654,7 +654,7 @@
 }
 
 TEST_F(DefineInlineT

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-13 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

In D113898#3167215 , @kbobyrev wrote:

> In D113898#3167050 , @kuhnel wrote:
>
>> Looking at the documentation, this looks like a bug in the clang-tidy check:
>> https://releases.llvm.org/13.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-qualified-auto.html
>>
>> The rule `llvm-qualified-auto` should not add a `const` qualifier.
>
> I don't see how that is a bug: the docs specially cover the `const auto *` 
> conversion in the first example by drawing the line between `observe()` 
> (non-mutating function) and `change()` (possibly mutating function).

Sorry I should have been more precise here: `AddConstToQualified` allows to 
configure if we want to have `const` added or not. The default for that rule is 
`true`. However the last sentence on that page says:

> Note in the LLVM alias, the default value is false.

So my understanding of this is: With the LLVM-rules we're using, `const` should 
not be added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-12-02 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Looking at the documentation, this looks like a bug in the clang-tidy check:
https://releases.llvm.org/13.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-qualified-auto.html

The rule `llvm-qualified-auto` should not add a `const` qualifier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D113896: [clangd] cleanup of header guard names

2021-12-02 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5bd643d31d11: [clangd] cleanup of header guard names 
(authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113896

Files:
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/ExpectedTypes.h
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/HeaderSourceSwitch.h
  clang-tools-extra/clangd/HeuristicResolver.h
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/InlayHints.h
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/URI.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h
  clang-tools-extra/clangd/index/BackgroundRebuild.h
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/IndexAction.h
  clang-tools-extra/clangd/index/ProjectAware.h
  clang-tools-extra/clangd/index/Serialization.h
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/SymbolLocation.h
  clang-tools-extra/clangd/index/SymbolOrigin.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/index/dex/Trigram.h
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/unittests/Annotations.h
  clang-tools-extra/clangd/unittests/LSPClient.h
  clang-tools-extra/clangd/unittests/Matchers.h
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TestFS.h
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/TestScheme.h
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestWorkspace.h
  clang-tools-extra/clangd/unittests/support/TestTracer.h
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
 
 #include "TestTU.h"
 #include "index/Index.h"
Index: clang-tools-extra/clangd/unittests/support/TestTracer.h
===
--- clang-tools-extra/clangd/unittests/support/TestTracer.h
+++ clang-tools-extra/clangd/unittests/support/TestTracer.h
@@ -10,8 +10,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
 
 #include "support/Trace.h"
 #include "llvm/ADT/StringMap.h"
Index: clang-tools-extra/clangd/unittests/TestWorkspace.h
===
--- clang-tools-extra/clangd/unittests/TestWorkspace.h
+++ clang-tools-extra/clangd/unittests/TestWorkspace.h
@@ -13,8 +13,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
 
 #include "TestFS.h"
 #include "TestTU.h"
@@ -56,4 +56,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -14,8 +14,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
@@ -104,4 +104,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#endif // LLVM_CLANG_TOO

[PATCH] D113896: [clangd] cleanup of header guard names

2021-12-02 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

@kadircet looks like clang-tidy does not detect missing comments in `#endif`. 
It does complain about missing comments for namespaces. E.g. in 
`Serialization.h` the `#endif` comment is missing, but without a finding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113896

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


[PATCH] D113896: [clangd] cleanup of header guard names

2021-12-02 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 391301.
kuhnel marked 4 inline comments as done.
kuhnel added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113896

Files:
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/ExpectedTypes.h
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/HeaderSourceSwitch.h
  clang-tools-extra/clangd/HeuristicResolver.h
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/InlayHints.h
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/URI.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h
  clang-tools-extra/clangd/index/BackgroundRebuild.h
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/IndexAction.h
  clang-tools-extra/clangd/index/ProjectAware.h
  clang-tools-extra/clangd/index/Serialization.h
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/SymbolLocation.h
  clang-tools-extra/clangd/index/SymbolOrigin.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/index/dex/Trigram.h
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/unittests/Annotations.h
  clang-tools-extra/clangd/unittests/LSPClient.h
  clang-tools-extra/clangd/unittests/Matchers.h
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TestFS.h
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/TestScheme.h
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestWorkspace.h
  clang-tools-extra/clangd/unittests/support/TestTracer.h
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
 
 #include "TestTU.h"
 #include "index/Index.h"
Index: clang-tools-extra/clangd/unittests/support/TestTracer.h
===
--- clang-tools-extra/clangd/unittests/support/TestTracer.h
+++ clang-tools-extra/clangd/unittests/support/TestTracer.h
@@ -10,8 +10,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
 
 #include "support/Trace.h"
 #include "llvm/ADT/StringMap.h"
Index: clang-tools-extra/clangd/unittests/TestWorkspace.h
===
--- clang-tools-extra/clangd/unittests/TestWorkspace.h
+++ clang-tools-extra/clangd/unittests/TestWorkspace.h
@@ -13,8 +13,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
 
 #include "TestFS.h"
 #include "TestTU.h"
@@ -56,4 +56,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -14,8 +14,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
@@ -104,4 +104,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
Index: clang-tools-extra/clangd/unittests/TestIndex.h
=

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-11-18 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

When trying to revert some of the changes, I just noticed there are a couple of 
`if (const auto* ...` in `CodeComplete.cpp` and `AST.cpp` (and maybe other 
files as well). So some folks seem to be using this right now. If we want to be 
consistent, we would have to remove these `const` as well.

I'm not sure what the right way forward would be.

@sammccall  WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D113899: [NFC][clangd] fix clang-tidy finding on isa_and_nonnull

2021-11-18 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7aa2ce0fab3c: [NFC][clangd] fix clang-tidy finding on 
isa_and_nonnull (authored by kuhnel).

Changed prior to commit:
  https://reviews.llvm.org/D113899?vs=387254&id=388127#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113899

Files:
  clang-tools-extra/clangd/Selection.cpp


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -500,7 +500,7 @@
   //  - those without source range information, we don't record those
   //  - those that can't be stored in DynTypedNode.
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (llvm::isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.
 // Base::TraverseDecl will suppress children, but not this node itself.
 if (X && X->isImplicit())


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -500,7 +500,7 @@
   //  - those without source range information, we don't record those
   //  - those that can't be stored in DynTypedNode.
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (llvm::isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.
 // Base::TraverseDecl will suppress children, but not this node itself.
 if (X && X->isImplicit())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113902: [NFC][clangd] exclude test data from clang-tidy

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel abandoned this revision.
kuhnel added a comment.

thx for the explanation, makes sense
--> abandoning this change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113902

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


[PATCH] D113892: [NFC][clangd] cleanup llvm-else-after-return findings

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec4a2c956591: [NFC][clangd] cleanup llvm-else-after-return 
findings (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113892

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/FuzzyMatch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/JSONTransport.cpp
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -223,8 +223,7 @@
   while (const auto *CS = llvm::dyn_cast(Last)) {
 if (CS->body_empty())
   return false;
-else
-  Last = CS->body_back();
+Last = CS->body_back();
   }
   return llvm::isa(Last);
 }
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -250,7 +250,8 @@
   for (; Node->Parent; Node = Node->Parent) {
 if (Node->ASTNode.get()) {
   continue;
-} else if (auto *T = Node->ASTNode.get()) {
+}
+if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
   } else if (Node->Parent->ASTNode.get() ||
Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -687,7 +687,8 @@
 llvm::Expected readIndexFile(llvm::StringRef Data) {
   if (Data.startswith("RIFF")) {
 return readRIFF(Data);
-  } else if (auto YAMLContents = readYAML(Data)) {
+  }
+  if (auto YAMLContents = readYAML(Data)) {
 return std::move(*YAMLContents);
   } else {
 return error("Not a RIFF file and failed to parse as YAML: {0}",
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -826,10 +826,9 @@
 log("Found definition heuristically using nearby identifier {0}",
 NearbyIdent->text(SM));
 return ASTResults;
-  } else {
-vlog("No definition found using nearby identifier {0} at {1}",
- Word->Text, Word->Location.printToString(SM));
   }
+  vlog("No definition found using nearby identifier {0} at {1}", Word->Text,
+   Word->Location.printToString(SM));
 }
 // No nearby word, or it didn't refer to anything either. Try the index.
 auto TextualResults =
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -1282,8 +1282,8 @@
 if (Done) {
   if (Requests.empty())
 return;
-  else // Even though Done is set, finish pending requests.
-break; // However, skip delays to shutdown fast.
+  // Even though Done is set, finish pending requests.
+  break; // However, skip delays to shutdown fast.
 }
 
 // Tracing: we have a next request, attribute this sleep to it.
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -346,7 +346,7 @@
 SM.getTopMacroCallerLoc(Batch.back().location());
 return testTokenRange(SM.getFileOffset(ArgStart),
   SM.getFileOffset(ArgEnd));
-  } else {
+  } else { // NOLINT(llvm-else-after-return)
 /* fall through and treat as part of the macro body */
   }
 }
@@ -357,8 +357,7 @@
 if (Expansion.first == SelFile)
   // FIXME: also check ( and ) for function-like macros?
   return testToken(Expansion.second);
-else
-  return NoTokens;
+return NoTokens;
   }
 
   // Is the closed token range [Begin, End] selected?
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -695,7 +695,8 @@
   if (ArgsArray->size() > 1) {
 P.field("arguments

[PATCH] D113896: [clangd] cleanup of header guard names

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/PathMapping.h:3
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHMAPPING_H
+
 //===--- PathMapping.h - apply path mappings to LSP messages -===//

Looks like the include guards were missing here. I suppose this is something we 
want to add.



Comment at: 
clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/foo.h:1
-#ifndef FOO_H
-#define FOO_H
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANGD_TEST_INPUTS_BACKGROUND_INDEX_SUB_DIR_FOO_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANGD_TEST_INPUTS_BACKGROUND_INDEX_SUB_DIR_FOO_H

sammccall wrote:
> Please don't modify tests, they don't need to follow LLVM style and should be 
> as simple as possible
I was iterating over all .cpp and .h files, so the test data ended up in the 
changes as well.

I suppose the only way to avoid this is to use the `run-clang-tidy.py` wraper 
script instead



Comment at: clang-tools-extra/clangd/unittests/LSPClient.h:2
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_LSPCLIENT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_LSPCLIENT_H
+

Same here. I suppose we want header guards in this one.



Comment at: clang-tools-extra/clangd/unittests/TestScheme.h:1
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTSCHEME_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTSCHEME_H

sammccall wrote:
> What's up with this change?
> If this file is empty it should just be deleted instead
Deleting the file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113896

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


[PATCH] D113896: [NFC][clangd] cleanup of header guard names

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 387929.
kuhnel marked 3 inline comments as done.
kuhnel added a comment.

addresed Sam's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113896

Files:
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/ExpectedTypes.h
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/HeaderSourceSwitch.h
  clang-tools-extra/clangd/HeuristicResolver.h
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/InlayHints.h
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/URI.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h
  clang-tools-extra/clangd/index/BackgroundRebuild.h
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/IndexAction.h
  clang-tools-extra/clangd/index/ProjectAware.h
  clang-tools-extra/clangd/index/Serialization.h
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/SymbolLocation.h
  clang-tools-extra/clangd/index/SymbolOrigin.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/index/dex/Trigram.h
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/unittests/Annotations.h
  clang-tools-extra/clangd/unittests/LSPClient.h
  clang-tools-extra/clangd/unittests/Matchers.h
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TestFS.h
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/TestScheme.h
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestWorkspace.h
  clang-tools-extra/clangd/unittests/support/TestTracer.h
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
 
 #include "TestTU.h"
 #include "index/Index.h"
Index: clang-tools-extra/clangd/unittests/support/TestTracer.h
===
--- clang-tools-extra/clangd/unittests/support/TestTracer.h
+++ clang-tools-extra/clangd/unittests/support/TestTracer.h
@@ -10,8 +10,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
 
 #include "support/Trace.h"
 #include "llvm/ADT/StringMap.h"
Index: clang-tools-extra/clangd/unittests/TestWorkspace.h
===
--- clang-tools-extra/clangd/unittests/TestWorkspace.h
+++ clang-tools-extra/clangd/unittests/TestWorkspace.h
@@ -13,8 +13,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
 
 #include "TestFS.h"
 #include "TestTU.h"
@@ -56,4 +56,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTWORKSPACE_H
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -14,8 +14,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
@@ -104,4 +104,4 @@
 } // namespace clangd
 } // namespace clang
 
-#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTTU_H
Index: clang-tools-extra/clangd/unittests/TestIndex.h
===

[PATCH] D113899: [NFC][clangd] fix clang-tidy finding on isa_and_nonnull

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/Selection.cpp:504
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.

kadircet wrote:
> while here `llvm::isa_and_nonnull` we try to qualify symbols from llvm 
> namespace.
Sorry, I'm not getting what you wanted to say. 

You want me to add a `llvm::`?
Or is it about a `operator bool()`(however I didn't find one for `Decl` )?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113899

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


[PATCH] D113892: [NFC][clangd] cleanup llvm-else-after-return findings

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 387918.
kuhnel marked 4 inline comments as done.
kuhnel added a comment.

addressed Sam's comments

Sorry for the continued mess with automatic code formatting. Somehow VSCode 
forgot my settings :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113892

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/FuzzyMatch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/JSONTransport.cpp
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -223,8 +223,7 @@
   while (const auto *CS = llvm::dyn_cast(Last)) {
 if (CS->body_empty())
   return false;
-else
-  Last = CS->body_back();
+Last = CS->body_back();
   }
   return llvm::isa(Last);
 }
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -250,7 +250,8 @@
   for (; Node->Parent; Node = Node->Parent) {
 if (Node->ASTNode.get()) {
   continue;
-} else if (auto *T = Node->ASTNode.get()) {
+}
+if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
   } else if (Node->Parent->ASTNode.get() ||
Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -687,7 +687,8 @@
 llvm::Expected readIndexFile(llvm::StringRef Data) {
   if (Data.startswith("RIFF")) {
 return readRIFF(Data);
-  } else if (auto YAMLContents = readYAML(Data)) {
+  }
+  if (auto YAMLContents = readYAML(Data)) {
 return std::move(*YAMLContents);
   } else {
 return error("Not a RIFF file and failed to parse as YAML: {0}",
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -826,10 +826,9 @@
 log("Found definition heuristically using nearby identifier {0}",
 NearbyIdent->text(SM));
 return ASTResults;
-  } else {
-vlog("No definition found using nearby identifier {0} at {1}",
- Word->Text, Word->Location.printToString(SM));
   }
+  vlog("No definition found using nearby identifier {0} at {1}", Word->Text,
+   Word->Location.printToString(SM));
 }
 // No nearby word, or it didn't refer to anything either. Try the index.
 auto TextualResults =
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -1282,8 +1282,8 @@
 if (Done) {
   if (Requests.empty())
 return;
-  else // Even though Done is set, finish pending requests.
-break; // However, skip delays to shutdown fast.
+  // Even though Done is set, finish pending requests.
+  break; // However, skip delays to shutdown fast.
 }
 
 // Tracing: we have a next request, attribute this sleep to it.
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -346,7 +346,7 @@
 SM.getTopMacroCallerLoc(Batch.back().location());
 return testTokenRange(SM.getFileOffset(ArgStart),
   SM.getFileOffset(ArgEnd));
-  } else {
+  } else { // NOLINT(llvm-else-after-return)
 /* fall through and treat as part of the macro body */
   }
 }
@@ -357,8 +357,7 @@
 if (Expansion.first == SelFile)
   // FIXME: also check ( and ) for function-like macros?
   return testToken(Expansion.second);
-else
-  return NoTokens;
+return NoTokens;
   }
 
   // Is the closed token range [Begin, End] selected?
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -695,7 +695,8 @@
  

[PATCH] D113902: [NFC][clangd] exclude test data from clang-tidy

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

In D113902#3131707 , @sammccall wrote:

> Hmm, clang-tidy should only be running on entries in compile_commands.json. 
> are these files listed somehow?

No, they are not.

The question is: 
Do the tools our contributors use care about this? This is not the default 
behavior of clang-tidy, it's rather implemented in a LLVM-specific wrapper 
script. So do we require our contributors to use that script to check their 
code?

I was playing with the VS Code extension 
 to see 
the findings right in the IDE and that calls clang-tidy directly. So it ignores 
compile_commands.json


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113902

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


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-11-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Based on Sam's comments and our offline discussion, I would propose:

1. abandon this patch
2. start a discussion on the mailing list to disable this check for all of the 
llvm monorepo.

Other thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

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


[PATCH] D113889: [NFC] disabling clang-tidy check readability-identifier-naming in Protocol.h

2021-11-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

I just checked with my local clangd and it does not crash on this file...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113889

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


[PATCH] D113889: [NFC] disabling clang-tidy check readability-identifier-naming in Protocol.h

2021-11-16 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75a078455fc7: [NFC] disabling clang-tidy check 
readability-identifier-naming in Protocol.h (authored by kuhnel).

Changed prior to commit:
  https://reviews.llvm.org/D113889?vs=387239&id=387634#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113889

Files:
  clang-tools-extra/clangd/Protocol.h


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -36,6 +36,11 @@
 #include 
 #include 
 
+// This file is using the LSP syntax for identifier names which is different
+// from the LLVM coding standard. To avoid the clang-tidy warnings, we're
+// disabling one check here.
+// NOLINTBEGIN(readability-identifier-naming)
+
 namespace clang {
 namespace clangd {
 
@@ -1794,4 +1799,6 @@
 };
 } // namespace llvm
 
+// NOLINTEND(readability-identifier-naming)
+
 #endif


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -36,6 +36,11 @@
 #include 
 #include 
 
+// This file is using the LSP syntax for identifier names which is different
+// from the LLVM coding standard. To avoid the clang-tidy warnings, we're
+// disabling one check here.
+// NOLINTBEGIN(readability-identifier-naming)
+
 namespace clang {
 namespace clangd {
 
@@ -1794,4 +1799,6 @@
 };
 } // namespace llvm
 
+// NOLINTEND(readability-identifier-naming)
+
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113895: [NFC][clangd] fix llvm-namespace-comment finding

2021-11-16 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG274f12a44c60: [NFC][clangd] fix llvm-namespace-comment 
finding (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113895

Files:
  clang-tools-extra/clangd/xpc/XPCTransport.cpp


Index: clang-tools-extra/clangd/xpc/XPCTransport.cpp
===
--- clang-tools-extra/clangd/xpc/XPCTransport.cpp
+++ clang-tools-extra/clangd/xpc/XPCTransport.cpp
@@ -47,7 +47,7 @@
 // C "closure" for XPCTransport::loop() method
 namespace xpcClosure {
 void connection_handler(xpc_connection_t clientConnection);
-}
+} // namespace xpcClosure
 
 class XPCTransport : public Transport {
 public:


Index: clang-tools-extra/clangd/xpc/XPCTransport.cpp
===
--- clang-tools-extra/clangd/xpc/XPCTransport.cpp
+++ clang-tools-extra/clangd/xpc/XPCTransport.cpp
@@ -47,7 +47,7 @@
 // C "closure" for XPCTransport::loop() method
 namespace xpcClosure {
 void connection_handler(xpc_connection_t clientConnection);
-}
+} // namespace xpcClosure
 
 class XPCTransport : public Transport {
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113891: [NFC][clangd] cleaning up unused "using"

2021-11-16 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd2da1a2f400a: [NFC][clangd] cleaning up unused 
"using" (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113891

Files:
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp
  clang-tools-extra/clangd/unittests/RIFFTests.cpp


Index: clang-tools-extra/clangd/unittests/RIFFTests.cpp
===
--- clang-tools-extra/clangd/unittests/RIFFTests.cpp
+++ clang-tools-extra/clangd/unittests/RIFFTests.cpp
@@ -13,7 +13,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-using ::testing::ElementsAre;
 
 TEST(RIFFTest, File) {
   riff::File File{riff::fourCC("test"),
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -22,7 +22,6 @@
 
 using ::testing::_;
 using ::testing::AllOf;
-using ::testing::AnyOf;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 using ::testing::Pair;
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -33,7 +33,6 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
-using ::testing::UnorderedElementsAreArray;
 
 class HeadersTest : public ::testing::Test {
 public:
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -40,7 +40,6 @@
 using ::testing::HasSubstr;
 using ::testing::IsEmpty;
 using ::testing::Not;
-using ::testing::StartsWith;
 using ::testing::UnorderedElementsAre;
 
 TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -54,10 +54,8 @@
 namespace {
 
 using ::testing::AllOf;
-using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
-using ::testing::Gt;
 using ::testing::IsEmpty;
 using ::testing::Pair;
 using ::testing::SizeIs;
Index: clang-tools-extra/clangd/index/YAMLSerialization.cpp
===
--- clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -73,7 +73,6 @@
 using clang::index::SymbolInfo;
 using clang::index::SymbolKind;
 using clang::index::SymbolLanguage;
-using clang::index::SymbolRole;
 using clang::tooling::CompileCommand;
 
 // Helper to (de)serialize the SymbolID. We serialize it as a hex string.


Index: clang-tools-extra/clangd/unittests/RIFFTests.cpp
===
--- clang-tools-extra/clangd/unittests/RIFFTests.cpp
+++ clang-tools-extra/clangd/unittests/RIFFTests.cpp
@@ -13,7 +13,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-using ::testing::ElementsAre;
 
 TEST(RIFFTest, File) {
   riff::File File{riff::fourCC("test"),
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -22,7 +22,6 @@
 
 using ::testing::_;
 using ::testing::AllOf;
-using ::testing::AnyOf;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 using ::testing::Pair;
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -33,7 +33,6 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
-using ::testing::UnorderedElementsAreArray;
 
 class HeadersTest : public ::testing::Test {
 public:
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -40,7 +40,6 @@
 using ::testi

[PATCH] D113892: [NFC][clangd] cleanup llvm-else-after-return findings

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman, 
javed.absar.
kuhnel added subscribers: sammccall, hokein, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Cleanup of clang-tidy findings: removing "else" after a return statement
to improve readability of the code.

This patch was created by applying the clang-tidy fixes automatically.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113892

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/FuzzyMatch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/JSONTransport.cpp
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -223,8 +223,7 @@
   while (const auto *CS = llvm::dyn_cast(Last)) {
 if (CS->body_empty())
   return false;
-else
-  Last = CS->body_back();
+Last = CS->body_back();
   }
   return llvm::isa(Last);
 }
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -250,7 +250,8 @@
   for (; Node->Parent; Node = Node->Parent) {
 if (Node->ASTNode.get()) {
   continue;
-} else if (auto *T = Node->ASTNode.get()) {
+}
+if (auto *T = Node->ASTNode.get()) {
   if (T->getAs()) {
 break;
   } else if (Node->Parent->ASTNode.get() ||
Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -687,7 +687,8 @@
 llvm::Expected readIndexFile(llvm::StringRef Data) {
   if (Data.startswith("RIFF")) {
 return readRIFF(Data);
-  } else if (auto YAMLContents = readYAML(Data)) {
+  }
+  if (auto YAMLContents = readYAML(Data)) {
 return std::move(*YAMLContents);
   } else {
 return error("Not a RIFF file and failed to parse as YAML: {0}",
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -401,8 +401,8 @@
 }
   }
   // Special case: void foo() ^override: jump to the overridden method.
-if (NodeKind.isSame(ASTNodeKind::getFromNodeKind()) ||
-NodeKind.isSame(ASTNodeKind::getFromNodeKind())) {
+  if (NodeKind.isSame(ASTNodeKind::getFromNodeKind()) ||
+  NodeKind.isSame(ASTNodeKind::getFromNodeKind())) {
 // We may be overridding multiple methods - offer them all.
 for (const NamedDecl *ND : CMD->overridden_methods())
   AddResultDecl(ND);
@@ -826,10 +826,9 @@
 log("Found definition heuristically using nearby identifier {0}",
 NearbyIdent->text(SM));
 return ASTResults;
-  } else {
-vlog("No definition found using nearby identifier {0} at {1}",
- Word->Text, Word->Location.printToString(SM));
   }
+  vlog("No definition found using nearby identifier {0} at {1}", Word->Text,
+   Word->Location.printToString(SM));
 }
 // No nearby word, or it didn't refer to anything either. Try the index.
 auto TextualResults =
@@ -1430,28 +1429,27 @@
 // Add decl/def of overridding methods.
 if (Index && Results.References.size() <= Limit &&
 !OverriddenBy.Subjects.empty())
-  Index->relations(
-  OverriddenBy, [&](const SymbolID &Subject, const Symbol &Object) {
-const auto LSPLocDecl =
-toLSPLocation(Object.CanonicalDeclaration, *MainFilePath);
-const auto LSPLocDef =
-toLSPLocation(Object.Definition, *MainFilePath);
-if (LSPLocDecl && LSPLocDecl != LSPLocDef) {
-  ReferencesResult::Reference Result;
-  Result.Loc = std::move(*LSPLocDecl);
-  Result.Attributes =
-  ReferencesResult::Declaration | ReferencesResult::Override;
-  Results.References.push_back(std::move(Result));
-}
-if (LSPLocDef) {
-  ReferencesResult::Reference Result;
-  Result.Loc = std::move(*LSPLo

[PATCH] D113895: [NFC][clangd] fix llvm-namespace-comment finding

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixing the clang-tidy finding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113895

Files:
  clang-tools-extra/clangd/xpc/XPCTransport.cpp


Index: clang-tools-extra/clangd/xpc/XPCTransport.cpp
===
--- clang-tools-extra/clangd/xpc/XPCTransport.cpp
+++ clang-tools-extra/clangd/xpc/XPCTransport.cpp
@@ -47,7 +47,7 @@
 // C "closure" for XPCTransport::loop() method
 namespace xpcClosure {
 void connection_handler(xpc_connection_t clientConnection);
-}
+} // namespace xpcClosure
 
 class XPCTransport : public Transport {
 public:


Index: clang-tools-extra/clangd/xpc/XPCTransport.cpp
===
--- clang-tools-extra/clangd/xpc/XPCTransport.cpp
+++ clang-tools-extra/clangd/xpc/XPCTransport.cpp
@@ -47,7 +47,7 @@
 // C "closure" for XPCTransport::loop() method
 namespace xpcClosure {
 void connection_handler(xpc_connection_t clientConnection);
-}
+} // namespace xpcClosure
 
 class XPCTransport : public Transport {
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113899: [NFC][clangd] fix clang-tidy finding on isa_and_nonnull

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman.
kuhnel added subscribers: sammccall, kbobyrev, adamcz.
kadircet added inline comments.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.



Comment at: clang-tools-extra/clangd/Selection.cpp:504
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.

while here `llvm::isa_and_nonnull` we try to qualify symbols from llvm 
namespace.


This is a cleanup of the only llvm-prefer-isa-or-dyn-cast-in-conditionals 
finding in the clangd code base. This patch was created by automatically 
applying the fixes from clang-tidy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113899

Files:
  clang-tools-extra/clangd/Selection.cpp


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -501,7 +501,7 @@
   //  - those without source range information, we don't record those
   //  - those that can't be stored in DynTypedNode.
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.
 // Base::TraverseDecl will suppress children, but not this node itself.
 if (X && X->isImplicit())


Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -501,7 +501,7 @@
   //  - those without source range information, we don't record those
   //  - those that can't be stored in DynTypedNode.
   bool TraverseDecl(Decl *X) {
-if (X && isa(X))
+if (isa_and_nonnull(X))
   return Base::TraverseDecl(X); // Already pushed by constructor.
 // Base::TraverseDecl will suppress children, but not this node itself.
 if (X && X->isImplicit())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113902: [NFC][clangd] exclude test data from clang-tidy

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
kuhnel added subscribers: sammccall, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov, aheejin.
Herald added a project: clang-tools-extra.

Adding .clang-tidy files to exclude test data from clang-tidy checks. Otherwise 
these create false positives.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113902

Files:
  clang-tools-extra/clangd/test/Inputs/.clang-tidy
  clang-tools-extra/clangd/test/index-serialization/Inputs/.clang-tidy
  clang-tools-extra/clangd/test/remote-index/Inputs/.clang-tidy


Index: clang-tools-extra/clangd/test/remote-index/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/remote-index/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: "-misc-definitions-in-headers"
Index: clang-tools-extra/clangd/test/index-serialization/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/index-serialization/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: "-clang-diagnostic-non-virtual-dtor,-readability-identifier-naming"
Index: clang-tools-extra/clangd/test/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: 
"-misc-definitions-in-headers,-llvm-header-guard,-clang-diagnostic-unused-variable"


Index: clang-tools-extra/clangd/test/remote-index/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/remote-index/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: "-misc-definitions-in-headers"
Index: clang-tools-extra/clangd/test/index-serialization/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/index-serialization/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: "-clang-diagnostic-non-virtual-dtor,-readability-identifier-naming"
Index: clang-tools-extra/clangd/test/Inputs/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/clangd/test/Inputs/.clang-tidy
@@ -0,0 +1,3 @@
+# disable the check on the test input data
+InheritParentConfig: true
+Checks: "-misc-definitions-in-headers,-llvm-header-guard,-clang-diagnostic-unused-variable"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman, 
javed.absar.
kuhnel added subscribers: sammccall, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is a cleanup of all llvm-qualified-auto findings.
This patch was created by automatically applying the fixes from
clang-tidy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  const auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  const auto *Test = R"cpp(
 namespace ns { class X { static void foo

[PATCH] D113896: [NFC][clangd] cleanup of header guard names

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, wenlei, usaxena95, kadircet, arphaman.
kuhnel added subscribers: sammccall, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Renaming header guards to match the LLVM convention.
This patch was created by automatically applying the fixes from
clang-tidy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113896

Files:
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/ExpectedTypes.h
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/HeaderSourceSwitch.h
  clang-tools-extra/clangd/HeuristicResolver.h
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/InlayHints.h
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/URI.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h
  clang-tools-extra/clangd/index/BackgroundRebuild.h
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/IndexAction.h
  clang-tools-extra/clangd/index/ProjectAware.h
  clang-tools-extra/clangd/index/Serialization.h
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/SymbolLocation.h
  clang-tools-extra/clangd/index/SymbolOrigin.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/clangd/index/dex/Trigram.h
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
  clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/foo.h
  clang-tools-extra/clangd/test/Inputs/path-mappings/server/foo.h
  clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h
  clang-tools-extra/clangd/test/remote-index/Inputs/Header.h
  clang-tools-extra/clangd/unittests/Annotations.h
  clang-tools-extra/clangd/unittests/LSPClient.h
  clang-tools-extra/clangd/unittests/Matchers.h
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TestFS.h
  clang-tools-extra/clangd/unittests/TestIndex.h
  clang-tools-extra/clangd/unittests/TestScheme.h
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestWorkspace.h
  clang-tools-extra/clangd/unittests/decision_forest_model/CategoricalFeature.h
  clang-tools-extra/clangd/unittests/support/TestTracer.h
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H
 
 #include "TestTU.h"
 #include "index/Index.h"
Index: clang-tools-extra/clangd/unittests/support/TestTracer.h
===
--- clang-tools-extra/clangd/unittests/support/TestTracer.h
+++ clang-tools-extra/clangd/unittests/support/TestTracer.h
@@ -10,8 +10,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
-#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
 
 #include "support/Trace.h"
 #include "llvm/ADT/StringMap.h"
Index: clang-tools-extra/clangd/unittests/decision_forest_model/CategoricalFeature.h
===
--- clang-tools-extra/clangd/unittests/decision_forest_model/CategoricalFeature.h
+++ clang-tools-extra/clangd/unittests/decision_forest_model/CategoricalFeature.h
@@ -1,5 +1,10 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_DECISION_FOREST_MODEL_CATEGORICALFEATURE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_DECISION_FOREST_MODEL_CATEGORICALFEATURE_H
+
 namespace ns1 {
 namespace ns2 {
 enum TestEnum { A, B, C, D };
 } // namespace ns2
 } // namespace ns1
+
+#endif
Index: clang-tools-extra/clangd/unittests/TestWorkspace.h
===
--- clang-tools-extra/clangd/unittests/TestWorkspace.h
+++ clang-tools-extra/clangd/unittests/TestWorkspace.h
@@ -13,8 +13,8 @@
 //
 //===-===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_UN

[PATCH] D113891: [NFC][clangd] cleaning up unused "using"

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman.
kuhnel added subscribers: hokein, sammccall, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Cleaning up unused "using" declarations.
This patch was generated from automatically applyning clang-tidy fixes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113891

Files:
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp
  clang-tools-extra/clangd/unittests/RIFFTests.cpp


Index: clang-tools-extra/clangd/unittests/RIFFTests.cpp
===
--- clang-tools-extra/clangd/unittests/RIFFTests.cpp
+++ clang-tools-extra/clangd/unittests/RIFFTests.cpp
@@ -13,7 +13,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-using ::testing::ElementsAre;
 
 TEST(RIFFTest, File) {
   riff::File File{riff::fourCC("test"),
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -22,7 +22,6 @@
 
 using ::testing::_;
 using ::testing::AllOf;
-using ::testing::AnyOf;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 using ::testing::Pair;
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -33,7 +33,6 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
-using ::testing::UnorderedElementsAreArray;
 
 class HeadersTest : public ::testing::Test {
 public:
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -40,7 +40,6 @@
 using ::testing::HasSubstr;
 using ::testing::IsEmpty;
 using ::testing::Not;
-using ::testing::StartsWith;
 using ::testing::UnorderedElementsAre;
 
 TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -54,10 +54,8 @@
 namespace {
 
 using ::testing::AllOf;
-using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
-using ::testing::Gt;
 using ::testing::IsEmpty;
 using ::testing::Pair;
 using ::testing::SizeIs;
Index: clang-tools-extra/clangd/index/YAMLSerialization.cpp
===
--- clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -73,7 +73,6 @@
 using clang::index::SymbolInfo;
 using clang::index::SymbolKind;
 using clang::index::SymbolLanguage;
-using clang::index::SymbolRole;
 using clang::tooling::CompileCommand;
 
 // Helper to (de)serialize the SymbolID. We serialize it as a hex string.


Index: clang-tools-extra/clangd/unittests/RIFFTests.cpp
===
--- clang-tools-extra/clangd/unittests/RIFFTests.cpp
+++ clang-tools-extra/clangd/unittests/RIFFTests.cpp
@@ -13,7 +13,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-using ::testing::ElementsAre;
 
 TEST(RIFFTest, File) {
   riff::File File{riff::fourCC("test"),
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -22,7 +22,6 @@
 
 using ::testing::_;
 using ::testing::AllOf;
-using ::testing::AnyOf;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 using ::testing::Pair;
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -33,7 +33,6 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
-using ::testing::UnorderedElementsAreArray;
 
 class HeadersTest : public ::testing::Test {
 public:
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
=

[PATCH] D113889: [NFC] disabling clang-tidy check readability-identifier-naming in Protocol.h

2021-11-15 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman.
kuhnel added subscribers: sammccall, hokein, adamcz, kbobyrev.
kuhnel published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The file follows the LSP syntax, so we're intentially deviating
from the LLVM coding standard.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113889

Files:
  clang-tools-extra/clangd/Protocol.h


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -36,6 +36,11 @@
 #include 
 #include 
 
+/* This file is using the LSP syntax for identifier names which is different
+ from the LLVM coding standard. To avoid the clang-tidy warnings, we're
+ disabling one check here.*/
+// NOLINTBEGIN(readability-identifier-naming)
+
 namespace clang {
 namespace clangd {
 
@@ -1794,4 +1799,6 @@
 };
 } // namespace llvm
 
+// NOLINTEND(readability-identifier-naming)
+
 #endif


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -36,6 +36,11 @@
 #include 
 #include 
 
+/* This file is using the LSP syntax for identifier names which is different
+ from the LLVM coding standard. To avoid the clang-tidy warnings, we're
+ disabling one check here.*/
+// NOLINTBEGIN(readability-identifier-naming)
+
 namespace clang {
 namespace clangd {
 
@@ -1794,4 +1799,6 @@
 };
 } // namespace llvm
 
+// NOLINTEND(readability-identifier-naming)
+
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-09-22 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

> Out of interest, did you see 
> https://llvm.org/docs/ProgrammersManual.html#error-handling ? If not (and if 
> you find it helpful) then maybe we need to make that document more 
> discoverable. If that document is not helpful then we should improve it.

No I wasn't aware of the documentation page and just took a quick look. This 
looks quite useful. I wish I had known about that part when trying to use 
Expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 367787.
kuhnel added a comment.

fixing windows build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/FS.cpp
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,61 @@
+//===-- StdLibIndexTests.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 "FuzzyMatch.h"
+#include "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  auto UmbrellaHeader =
+  generateUmbrellaHeaders(StandardLibrarVariant::CXX14).str();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index =
+  indexUmbrellaHeaders(HeaderMock, FS, StandardLibrarVariant::CXX14);
+  ASSERT_TRUE(Index != nullptr);
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+  EXPECT_THAT(match(*Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,55 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "FS.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library.
+// FIXME: add heuristic to detect this version somehow (magically).
+enum class StandardLibrarVariant { CXX14 = 0 };
+
+/// Generate a index of the standard library index for a given variant of
+/// the standard library. This index 

[PATCH] D108119: Wiring of standard library indexing into clangd.

2021-08-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 367738.
kuhnel added a comment.

addressed some review comments

question of integration with main functionality still open.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108119

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


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -24,6 +24,7 @@
 #include "index/Background.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
@@ -167,7 +168,11 @@
 FeatureModuleSet *FeatureModules = nullptr;
 
 explicit operator TUScheduler::Options() const;
+
+// Automatically index the standard library - experimental feature
+bool IndexStandardLibrary = false;
   };
+
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.
   static Options optsForTest();
@@ -403,6 +408,8 @@
   std::unique_ptr BackgroundIdx;
   // Storage for merged views of the various indexes.
   std::vector> MergedIdx;
+  // If present, the index of the standard library.
+  std::unique_ptr StandardLibraryIdx;
 
   // When set, provides clang-tidy options for a specific file.
   TidyProviderRef ClangTidyProvider;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -27,6 +27,7 @@
 #include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/Merge.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
@@ -175,6 +176,14 @@
   this->Index = Idx;
 }
   };
+  if (Opts.IndexStandardLibrary) {
+StandardLibraryIdx = indexStandardLibrary(TFS);
+if (!StandardLibraryIdx) {
+  elog("Unable to build standard library index. Not using it.");
+} else {
+  AddIndex(StandardLibraryIdx.get());
+}
+  }
   if (Opts.StaticIndex)
 AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -24,6 +24,7 @@
 #include "index/Background.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
@@ -167,7 +168,11 @@
 Feature

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 367737.
kuhnel marked an inline comment as done.
kuhnel added a comment.

addressed code review comments

also fixed use-after-free


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/FS.cpp
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "FuzzyMatch.h"
+#include "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  auto UmbrellaHeader = generateUmbrellaHeaders(StandardLibrarVariant::CXX14);
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index =
+  indexUmbrellaHeaders(HeaderMock, FS, StandardLibrarVariant::CXX14);
+  ASSERT_TRUE(Index != nullptr);
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+  EXPECT_THAT(match(*Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,55 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "FS.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library.
+// FIXME: add heuristic to detect this version somehow (magically).
+enum class StandardLibrarVariant { CXX14 = 0 };
+
+/// Generate a index of the standard library in

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked an inline comment as done.
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp:51
+  Req.AnyScope = true;
+  EXPECT_THAT(match(*Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),

nridge wrote:
> kuhnel wrote:
> > @sammccall I seem to be running into a use-after-free problem here. 
> > Debugging the whole thing shows that `Index` is pointing to an invalid 
> > address. So the problem is somewhere between returning the `unique_ptr` 
> > from `indexUmbrellaHeaders(...)` and assigning it to the `Index` variable.
> > 
> > Can you please take a look and give me a hint how to fix this?
> I think your issue may be that `Dex` doesn't actually take ownership of the 
> slabs that get passed to it; the slabs [need to outlive 
> it](https://searchfox.org/llvm/rev/cab7c52acdf508f73186dfe49b8cb012bb9129b2/clang-tools-extra/clangd/index/dex/Dex.h#39).
> 
> `Dex` has another constructor which allows it to also take ownership, and a 
> [Dex::build()](https://searchfox.org/llvm/rev/cab7c52acdf508f73186dfe49b8cb012bb9129b2/clang-tools-extra/clangd/index/dex/Dex.cpp#26)
>  helper function to call it -- you probably want to be using that.
Awesome, thx @nridge ! That fixed the use-after-free!
I was searching in the wrong place the whole time...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-19 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/index/StdLib.cpp:72
+  Inputs.TFS = &TFS;
+  // TODO: can we get a real compile command from somewhere?
+  Inputs.CompileCommand.Directory = virtualRoot().str();

nridge wrote:
> sammccall wrote:
> > I'm not sure what this means, I don't think there's anything better to do 
> > here.
> One could imagine picking a source file from the project's CDB, and using its 
> flags to parse the standard library.
> 
> That could be relevant for macros that affect the way standard library 
> headers are parsed (like `_GLIBCXX_DEBUG` perhaps?)
Yes, my question was: can we get the real compile command form the file in 
which we're querying the standard library index and then extract the (relevant) 
compiler argument from that.

That might also help in guessing the current language variant.



Comment at: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp:51
+  Req.AnyScope = true;
+  EXPECT_THAT(match(*Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),

@sammccall I seem to be running into a use-after-free problem here. Debugging 
the whole thing shows that `Index` is pointing to an invalid address. So the 
problem is somewhere between returning the `unique_ptr` from 
`indexUmbrellaHeaders(...)` and assigning it to the `Index` variable.

Can you please take a look and give me a hint how to fix this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-19 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 367523.
kuhnel marked 18 inline comments as done.
kuhnel added a comment.

addressed review comments, has use-after-free problem


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/FS.cpp
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "FuzzyMatch.h"
+#include "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  auto UmbrellaHeader = generateUmbrellaHeaders(StandardLibrarVariant::CXX14);
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index =
+  indexUmbrellaHeaders(HeaderMock, FS, StandardLibrarVariant::CXX14);
+  ASSERT_TRUE(Index != nullptr);
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+  EXPECT_THAT(match(*Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,55 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "FS.h"
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library.
+// FIXME: add heuristic to detect this version somehow (magically).
+enum class StandardLibrarVariant { CXX14 = 0 };
+
+/// Generate a index of the standard library index

[PATCH] D108119: Wiring of standard library indexing into clangd.

2021-08-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:180
+  if (Opts.IndexStandardLibrary) {
+auto SLIndex = indexStandardLibrary(TFS);
+if (!SLIndex || !SLIndex->get()) {

I'm not sure if returning a Expected makes sense here. I suppose logging 
could be done from StandardLibraryIndex just as well.




Comment at: clang-tools-extra/clangd/ClangdServer.cpp:184
+}
+AddIndex(SLIndex->get());
+  }

sammccall wrote:
> this pointer will dangle after the `if` block finishes (the local `auto` owns 
> the index)
Ah yes, you're right. The other indexes are kept in member variables...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108119

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


[PATCH] D108119: Wiring of standard library indexing into clangd.

2021-08-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 366856.
kuhnel marked an inline comment as done.
kuhnel added a comment.

fixed lifecycle of StdLibIndex variable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108119

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


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -24,6 +24,7 @@
 #include "index/Background.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
@@ -167,7 +168,11 @@
 FeatureModuleSet *FeatureModules = nullptr;
 
 explicit operator TUScheduler::Options() const;
+
+// Automatically index the standard library - experimental feature
+bool IndexStandardLibrary = false;
   };
+
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.
   static Options optsForTest();
@@ -403,6 +408,8 @@
   std::unique_ptr BackgroundIdx;
   // Storage for merged views of the various indexes.
   std::vector> MergedIdx;
+  // If present, the index of the standard library.
+  std::unique_ptr StandardLibraryIdx;
 
   // When set, provides clang-tidy options for a specific file.
   TidyProviderRef ClangTidyProvider;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -27,6 +27,7 @@
 #include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/Merge.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
@@ -175,6 +176,16 @@
   this->Index = Idx;
 }
   };
+  if (Opts.IndexStandardLibrary) {
+auto SLIndex = indexStandardLibrary(TFS);
+if (!SLIndex) {
+  elog("Unable to build standard library index. Not using it.");
+  elog(toString(SLIndex.takeError()).c_str());
+} else {
+  StandardLibraryIdx = std::move(SLIndex.get());
+  AddIndex(StandardLibraryIdx.get());
+}
+  }
   if (Opts.StaticIndex)
 AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -24,6 +24,7 @@
 #include "index/Background.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor

[PATCH] D108119: wired up standard library indexing

2021-08-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
kuhnel added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
kuhnel requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Only plumbing code to enable standard library indexing
to enable end-to-end testing.
No changes to stdlib indexing behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108119

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


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -167,7 +167,11 @@
 FeatureModuleSet *FeatureModules = nullptr;
 
 explicit operator TUScheduler::Options() const;
+
+// Automatically index the standard library - experimental feature
+bool IndexStandardLibrary = false;
   };
+
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.
   static Options optsForTest();
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -27,6 +27,7 @@
 #include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/Merge.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
@@ -175,6 +176,13 @@
   this->Index = Idx;
 }
   };
+  if (Opts.IndexStandardLibrary) {
+auto SLIndex = indexStandardLibrary(TFS);
+if (!SLIndex || !SLIndex->get()) {
+  log("Unable to build standard library index. Not using it.");
+}
+AddIndex(SLIndex->get());
+  }
   if (Opts.StaticIndex)
 AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
 init(true),
 };
 
+opt IndexStandardLibrary{
+"index-standard-library",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."
+ "WARNING: This option is experimental only, and will be removed "
+ "eventually. Don't rely on it"),
+init(false),
+Hidden,
+};
+
 std::function getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
 return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
 if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -167,7 +167,11 @@
 FeatureModuleSet *FeatureModules = nullptr;
 
 explicit operator TUScheduler::Options() const;
+
+// Automatically index the standard library - experimental feature
+bool IndexStandardLibrary = false;
   };
+
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.
   static Options optsForTest();
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -27,6 +27,7 @@
 #include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 365415.
kuhnel added a comment.

fixed a couple of bugs

- wrong usage of llvm::unique
- wrong usage of static pointer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  auto UmbrellaHeader = SLI.generateIncludeHeader();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = SLI.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded());
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+
+  EXPECT_THAT(match(**Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,70 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library. Right now hardcoded to one verison.
+// FIXME: add feature to detect this version somehow (magically).
+enum StandardLibraryVersion { cxx14 = 0 };
+
+// external interface for getting a standard library index.
+Expected>
+indexStandard

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 365370.
kuhnel added a comment.

tried to fix Windows build failure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,60 @@
+//===-- StdLibIndexTests.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 "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  auto UmbrellaHeader = SLI.generateIncludeHeader();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = SLI.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded());
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+
+  EXPECT_THAT(match(**Index, Req),
+  UnorderedElementsAre(llvm::StringRef("myfunc"),
+   llvm::StringRef("otherfunc")));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,70 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library. Right now hardcoded to one verison.
+// FIXME: add feature to detect this version somehow (magically).
+enum StandardLibraryVersion { cxx14 = 0 };
+
+// external interface for getting a standard library index.
+Expected>
+indexStandardLibrary(const ThreadsafeFS &TFS,
+ 

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-09 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

> Main points in the implementation are:
>
> - simplify the exposed interface

Good point, I added a new function `indexStandardLibrary()` as external 
interface.

> - i don't think we need to mess with VFS at all actually

Yes, removed that.

> - we should think a little about which index data we actually want to keep/use

I removed Refs, Relations and Graph as per your comment. However I have to 
admit, I don't know what they are and how they are used.
What's a good place to look at so that I learn what they do?

> Next design questions seem to be about lifetime/triggering:
>
> - how many configurations of stdlib index to have
> - when do we build the indexes, and who owns them
> - what logic governs whether/which stdlib index is triggered, and where do we 
> put it

While you're out, I'll try to set up something so that I can do some manual 
tests with a real standard library.




Comment at: clang-tools-extra/clangd/index/StdLib.cpp:98
+  auto Buffer = FS->getBufferForFile(StdLibHeaderFileName);
+  if (!Buffer)
+return error("Could not read file from InMemoryFileSystem");

sammccall wrote:
> CreateMemBuffer instead to avoid expressing this impossible error condition?
Not sure what you mean with CreateMemBuffer.
I replaced the `if` with an `assert` as this should not fail.



Comment at: clang-tools-extra/clangd/index/StdLib.cpp:101
+  auto Clang = prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
+   std::move(*Buffer), FS, IgnoreDiags);
+  if (!Clang)

sammccall wrote:
> hang on, if we're providing the overridden buffer to prepareCompilerInstance 
> (like we do for edited files in clangd that may or may not be saved on disk 
> yet) then why do we need the VFS at all?
We don't need the VFS at all, you're right. Handing over a buffer is good 
enough.



Comment at: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp:47
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);

sammccall wrote:
> I'm not sure we're testing what we want to be testing here.
> 
> In real life, the symbols are not going to be in the entrypoint, but a file 
> included from it.
> And clangd's indexer *does* treat the main file differently from others.
> 
> It's pretty awkward to actually fix but maybe worth a comment.
So you would prefer that we change `HeaderMock` to only contain `#include` and 
then create the mock headers as virtual files in the MockFS?



Comment at: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp:56
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;

sammccall wrote:
> AnyScope and Limit are not needed
`AnyScope` is actually needed, otherwise the result is empty.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-08-09 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 365181.
kuhnel marked 29 inline comments as done.
kuhnel edited the summary of this revision.
kuhnel added a comment.
Herald added a subscriber: mgrang.

addressed code review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/FS.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,58 @@
+//===-- StdLibIndexTests.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 "TestFS.h"
+#include "TestIndex.h"
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateUmbrellaHeader) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  auto UmbrellaHeader = SLI.generateIncludeHeader();
+
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+  EXPECT_THAT(UmbrellaHeader, HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  MockFS FS;
+  StandardLibraryIndex SLI(FS, StandardLibraryVersion::cxx14);
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = SLI.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded());
+
+  FuzzyFindRequest Req;
+  Req.AnyScope = true;
+
+  EXPECT_THAT(match(**Index, Req), UnorderedElementsAre("myfunc", "otherfunc"));
+}
+
+// TODO: add tests for indexStandardLibrary()
+// TODO: test with different library versions
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -79,6 +79,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,70 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+// Clangd indexer for the C++ standard library.
+//
+// The index only contains symbols that are part of the translation unit. So
+// if your translation unit does not yet #include , you do not get
+// auto completion for std::string. However we expect that many users would
+// like to use the the standard library anyway, so we could index that by
+// default an offer e.g. code completion without requiring #includes.
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include "clang/AST/Expr.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Enumeration of supported Standard Library versions.
+// FIXME: support muiltiple languages (e.g. C and C++) and versions (e.g. 11,
+// 14, 17) of the standard library. Right now hardcoded to one verison.
+// FIXME: add feature to detect this version somehow (magically).
+enum StandardLibraryVersion { cxx14 = 0 };
+
+// external interface for getting a standard library index.
+Expected>
+indexStandardLibrary(const Threa

[PATCH] D105014: added some example code for llvm::Expected

2021-07-01 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd8f979fe48c: added some example code for 
llvm::Expected (authored by kuhnel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces ge

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355510.
kuhnel added a comment.

now fixing arc's way of git commits :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() me

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355508.
kuhnel added a comment.

fixed typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355507.
kuhnel marked 4 inline comments as done.
kuhnel added a comment.

updated code examples based on Sam's review

Oh my, this is really simple if you know how it's supposed 
to work. However my intuition is completely off in trying to
understand the error handling. I hope the examples help
others avoid the pain.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about successor failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about successor failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: llvm/include/llvm/Support/Error.h:464
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }

sammccall wrote:
> this won't compile, you need std::move(E)
sorry, I was too lazy to run this through the compiler. Now it compiles and 
runs...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355485.
kuhnel marked 2 inline comments as done.
kuhnel added a comment.

fixed compilation issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Suppo

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355481.
kuhnel added a comment.

also added example code for EXPECT_THAT_EXPECTED.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/i

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355478.
kuhnel added a comment.

using EXPECT_THAT_EXPECTED


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,66 @@
+//===-- StdLibIndexTests.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 "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded())
+  << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesystem with the file to be indexed */
+  llvm::IntrusiveRefCntPtr
+  buildFilesystem(std::string HeaderSources);
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
\ No newline at end of file

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355472.
kuhnel marked an inline comment as done.
kuhnel added a comment.

argh, again fixed autoformatter :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked 4 inline comments as done.
kuhnel added inline comments.



Comment at: llvm/include/llvm/Support/Error.h:462
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}

sammccall wrote:
> This seems too intrusive/unusual to put inline to me.
> And the main thing that is non-obvious is *why* you have to structure your 
> assertions in an unusual way, and that's not explained here.
> 
> Consider instead just briefly referencing the EXPECT_THAT_EXPECTED etc macros 
> in llvm/Testing/Support/Error.h which are designed to simplify this a bit.
Makes sense.

However  EXPECT_THAT_EXPECTED could also use some better documentation :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355471.
kuhnel marked 2 inline comments as done.
kuhnel added a comment.

fixed variable name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +493,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(Err && "Cannot create Expected from Error success value.");
@@ -764,7 +796,7 @@
 ///   Bar &X = cantFail(foo(false));
 ///   @endcode
 template 
-T& cantFail(Expected ValOrErr, const char *Msg = nullptr) {
+T &cantFail(Expected ValOrErr, const char *Msg = nullptr) {
   if (ValOrErr)
 return *ValOrErr;
   else {
@@ -785,8 +817,8 @@
 /// ErrorInfo types.
 template 
 class ErrorHandlerTraits
-: public ErrorHandl

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355470.
kuhnel added a comment.

addressed Sam's review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(Result.takeError()) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +493,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(Err && "Cannot create Expected from Error success value.");
@@ -764,7 +796,7 @@
 ///   Bar &X = cantFail(foo(false));
 ///   @endcode
 template 
-T& cantFail(Expected ValOrErr, const char *Msg = nullptr) {
+T &cantFail(Expected ValOrErr, const char *Msg = nullptr) {
   if (ValOrErr)
 return *ValOrErr;
   else {
@@ -785,8 +817,8 @@
 /// ErrorInfo types.
 template 
 class ErrorHandlerTraits
-: public ErrorHandlerTraits::ty

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355466.
kuhnel added a comment.

forgot header comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,63 @@
+//===-- StdLibIndexTests.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 "index/StdLib.h"
+#include "support/Logger.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT((bool)Index, IsTrue()) << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesystem with the file to be indexed */
+  llvm::IntrusiveRefCntPtr
+  buildFilesystem(std::string HeaderSources);
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
\ No newline at end of file
Index: clang-tools-extra/clangd/index/StdLib.cpp
=

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman, mgorny.
kuhnel requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is only the indexing part, it is NOT wired up to the
rest of ClandgdServer.

This is a step towards an implementation for
https://github.com/clangd/clangd/issues/618

Note: I'll pick up work on this in August, feel free to ignore this patch until 
then.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,63 @@
+//===-- StdLibIndexTests.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 "index/StdLib.h"
+#include "support/Logger.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT((bool)Index, IsTrue()) << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesyst

[PATCH] D105014: added some example code for llvm::Expected

2021-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 354855.
kuhnel added a comment.

undo of auto formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,49 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return error("B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (!Result) {
+///   auto Error = Result.takeError();
+///   // handle the error case here
+/// } else {
+///   // handle good case here
+/// }
+///
+///   @endcode
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}
+///   TEST(MyTests, ExpectedDemo) {
+/// auto Passed = myDivide(10, 5);
+/// // check this call has passed, this also prints the error message
+/// // if the function returns an Error
+/// ASSERT_TRUE((bool)Passed) << llvm::toString(Passed.takeError());
+/// // checked the returned value
+/// ASSERT_EQ(2, *Passed);
+///
+/// auto Failed = myDivide(1, 0);
+/// ASSERT_FALSE((bool)Failed);
+/// // make sure Failed.takeError() does not get remove by the optimizer
+/// std::cout << "Expected failure: " << 
llvm::toString(Failed.takeError());
+///   }
+///   @endcode
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,49 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return error("B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (!Result) {
+///   auto Error = Result.takeError();
+///   // handle the error case here
+/// } else {
+///   // handle good case here
+/// }
+///
+///   @endcode
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}
+///   TEST(MyTests, ExpectedDemo) {
+/// auto Passed = myDivide(10, 5);
+/// // check this call has passed, this also prints the error message
+/// // if the function returns an Error
+/// ASSERT_TRUE((bool)Passed) << llvm::toString(Passed.takeError());
+/// // checked the returned value
+/// ASSERT_EQ(2, *Passed);
+///
+/// auto Failed = myDivide(1, 0);
+/// ASSERT_FALSE((bool)Failed);
+/// // make sure Failed.takeError() does not get remove by the optimizer
+/// std::cout << "Expected failure: " << llvm::toString(Failed.takeError());
+///   }
+///   @endcode
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Argh, the auto formatter seems to have done some magic. I guess I should revert 
these?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 354849.
kuhnel added a comment.

removed stray file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,49 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return error("B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (!Result) {
+///   auto Error = Result.takeError();
+///   // handle the error case here
+/// } else {
+///   // handle good case here
+/// }
+///
+///   @endcode
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}
+///   TEST(MyTests, ExpectedDemo) {
+/// auto Passed = myDivide(10, 5);
+/// // check this call has passed, this also prints the error message
+/// // if the function returns an Error
+/// ASSERT_TRUE((bool)Passed) << llvm::toString(Passed.takeError());
+/// // checked the returned value
+/// ASSERT_EQ(2, *Passed);
+///
+/// auto Failed = myDivide(1, 0);
+/// ASSERT_FALSE((bool)Failed);
+/// // make sure Failed.takeError() does not get remove by the optimizer
+/// std::cout << "Expected failure: " << llvm::toString(Failed.takeError());
+///   }
+///   @endcode
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +502,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(Err && "Cannot create Expected from Error success value.");
@@ -764,7 +805,7 @@
 ///   Bar &X = cantFail(foo(false));
 ///   @endcode
 template 
-T& cantFail(Expected ValOrErr, const char *Msg = nullptr) {
+T &cantFail(Expected ValOrErr, const char *Msg = nullptr) {
   if (ValOrErr)
 return *ValOrErr;
   else {
@@ -7

[PATCH] D105014: added some example code for llvm::Expected

2021-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
kuhnel added a reviewer: sammccall.
Herald added subscribers: dexonsmith, usaxena95, kadircet, arphaman.
kuhnel requested review of this revision.
Herald added projects: LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits.

Since I had some fun understanding how to properly use llvm::Expected I 
added some code examples that I would have liked to see when learning to use it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105014

Files:
  clang-tools-extra/clangd/index/StdLib.cpp
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,49 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return error("B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (!Result) {
+///   auto Error = Result.takeError();
+///   // handle the error case here
+/// } else {
+///   // handle good case here
+/// }
+///
+///   @endcode
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}
+///   TEST(MyTests, ExpectedDemo) {
+/// auto Passed = myDivide(10, 5);
+/// // check this call has passed, this also prints the error message
+/// // if the function returns an Error
+/// ASSERT_TRUE((bool)Passed) << llvm::toString(Passed.takeError());
+/// // checked the returned value
+/// ASSERT_EQ(2, *Passed);
+///
+/// auto Failed = myDivide(1, 0);
+/// ASSERT_FALSE((bool)Failed);
+/// // make sure Failed.takeError() does not get remove by the optimizer
+/// std::cout << "Expected failure: " << llvm::toString(Failed.takeError());
+///   }
+///   @endcode
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +502,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(E

[PATCH] D94293: [clangd] automatically index STL

2021-01-22 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel abandoned this revision.
kuhnel added a comment.

thx for the review and feedback!

I guess I'll re-design the feature and add a new indexing layer instead. 
However that might take a while, so I'll abandon this revision and start a new 
one later on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94293

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


[PATCH] D94293: [clangd] automatically index STL

2021-01-08 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Yes, I was looking for feedback on this one as I wasn't happy with my design.




Comment at: clang-tools-extra/clangd/index/Background.cpp:449
+  // TODO(kuhnel): is the a better place to store this file?
+  // TODO(kuhnel): do we need a file at all, can we just pass a string to the
+  //   indexer?

kadircet wrote:
> In theory BackgroundIndex only reads headers from the FS, so we can provide 
> an in-memory buffer as the main file itself. `prepareCompilerInstance` in 
> `Compiler.h` (and used by `BackgroundIndex::index` does that exactly).
> 
> It might be better to just have a separate endpoint in BackgroundIndex (as 
> `indexSTLHeaders`) that is invoked once at construction time that enqueues 
> indexing of this phantom file.
> 
> WDYT?
Agree to both. I'll take a look.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:527
 
+opt IndexSTL{
+"index-stl",

kadircet wrote:
> do we really need to hide this behind a flag ? it sounds like a quite useful 
> feature to me with minimal risk of regressions and unlikely to make anyone 
> upset. in the end we are not doing anything heuristically and just throwing 
> clang on some STL headers, that'll probably be included within the TUs 
> eventually.
> 
> there's always the risk of crashing while parsing some STL headers, but i 
> don't think it is any different than user just including the header manually.
> 
> the biggest problem i can see is people using custom STL headers, but 
> hopefully compile flags interpolation logic should be able to infer the 
> relevant location for those. and in the cases it fails we either index the 
> default STL and suggest people some symbols their implementation might lack, 
> or fail to find STL at all and print some logs for the missing includes.
Back when I was developing embedded software, we couldn't use the STL for 
various reasons (object size, no exceptions, no dynamic memory, ...) and had 
our own, proprietary base library. In such a scenario it would be annoying if 
clangd would be proposing things I could not use in the project. 

So we should have a way for users to disable this. I'm fine if we switch it on 
by default and offer a `--disable-stl-index` flag instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94293

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


[PATCH] D94293: [clangd] automatically index STL

2021-01-08 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

@sammccall here the first implementation we talked about yesterday. This works 
well on my testing poject that has a compile_commands.json. It does not work 
without one.

Also I'm not really happy with the design as I haven't really found a good 
place to store the generated header file.

Should we look into implementing a separate Index to only handle the STL?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94293

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


[PATCH] D94293: [clangd] automatically index STL

2021-01-08 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
kuhnel requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94293

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -524,6 +524,15 @@
 std::function getMemoryCleanupFunction() { return nullptr; }
 #endif
 
+opt IndexSTL{
+"index-stl",
+cat(Features),
+desc("Background index should always include the STL headers even if \n"
+ "not used at the moment. This will enable code completion and \n"
+ "include fixer."),
+init(true),
+};
+
 #if CLANGD_ENABLE_REMOTE
 opt RemoteIndexAddress{
 "remote-index-address",
@@ -897,6 +906,7 @@
 
   // Shall we allow to customize the file limit?
   Opts.Rename.AllowCrossFile = CrossFileRename;
+  Opts.IndexSTL = IndexSTL;
 
   if (CheckFile.getNumOccurrences()) {
 llvm::SmallString<256> Path;
Index: clang-tools-extra/clangd/index/Background.h
===
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -141,6 +141,7 @@
 std::function ContextProvider = nullptr;
 // Whether to collect references to main-file-only symbols.
 bool CollectMainFileRefs = false;
+bool IndexSTL = false;
   };
 
   /// Creates a new background index and starts its threads.
@@ -155,6 +156,8 @@
   // available sometime later.
   void enqueue(const std::vector &ChangedFiles) {
 Queue.push(changedFilesTask(ChangedFiles));
+// TODO(kuhnel): Only index if enqueueing C++ file.
+indexSTLHeaders(ChangedFiles);
   }
 
   /// Boosts priority of indexing related to Path.
@@ -176,6 +179,8 @@
 
   void profile(MemoryTree &MT) const;
 
+  void indexSTLHeaders(const std::vector &ChangedFiles);
+
 private:
   /// Represents the state of a single file when indexing was performed.
   struct ShardVersion {
@@ -220,6 +225,8 @@
   BackgroundQueue Queue;
   AsyncTaskRunner ThreadPool;
   GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged;
+  // Whether the STL header files need to be indexed
+  bool NeedToIndexSTLHeaders = true;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -103,7 +104,8 @@
   CommandsChanged(
   CDB.watch([&](const std::vector &ChangedFiles) {
 enqueue(ChangedFiles);
-  })) {
+  })),
+  NeedToIndexSTLHeaders(Opts.IndexSTL) {
   assert(Opts.ThreadPoolSize > 0 && "Thread pool size can't be zero.");
   assert(this->IndexStorageFactory && "Storage factory can not be null!");
   for (unsigned I = 0; I < Opts.ThreadPoolSize; ++I) {
@@ -420,5 +422,56 @@
   // We don't want to mix memory used by index and symbols, so call base class.
   MT.child("index").addUsage(SwapIndex::estimateMemoryUsage());
 }
+
+void BackgroundIndex::indexSTLHeaders(
+const std::vector &ChangedFiles) {
+  // Only index if we need to.
+  if (!NeedToIndexSTLHeaders)
+return;
+
+  vlog("Trying to find place for STL header include.");
+  std::string SourceRoot;
+  for (auto ChangedFile : ChangedFiles) {
+if (CDB.getProjectInfo(ChangedFile)) {
+  SourceRoot = CDB.getProjectInfo(ChangedFile)->SourceRoot;
+  break;
+}
+  }
+  // fallback if we can't find a Compilations Database
+  if (SourceRoot.empty()) {
+if (ChangedFiles.empty()) {
+  vlog("Could not find place for STL header include.");
+  return;
+}
+SourceRoot = llvm::sys::path::parent_path(ChangedFiles[0]).str();
+  }
+  // TODO(kuhnel): is the a better place to store this file?
+  // TODO(kuhnel): do we need a file at all, can we just pass a string to the
+  //   indexer?
+  const Path STLHeaderPath = SourceRoot + "/.stl_header.h";
+  vlog("Indexing STL headers from {0}", STLHeaderPath);
+  std::ofstream STLIndexFile;
+  std::set Headers;
+
+// gather all the known STL headers, without duplicates
+#define SYMBOL(Name, NameSpace, Header) Headers.insert(#Header);
+#include "StdSymbolMap.inc"
+#undef SYMBOL
+
+  // TODO(kuhnel): figure out if there are other ways to write to files in llvm.
+  STLIndexFile.open(STLHeaderPath);
+  STLIndexFile << "/* This is a temporary file created by c

[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-12 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

@phosek sorry for the late reply, the builds on master are still green, so your 
changes are working on Windows as well.

Thank you for the extra work!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-07 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

> Looking at the error, it seems like you have a 32-bit version of zlib 
> installed and in your search path on a 64-bit version of Windows. I'm not 
> quite sure how to handle that in CMake.

For mlir-windows buildbot:
I have no clue on what is installed there.

For pre-merge testing:
I guess zlib is part of GNUWin32 package being installed. This is the 
recommended setup for Visual Studio 
. The pre-merge builds are running 
in a docker container on Windows 
,
 so you can check what software is being installed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-07 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

In D79219#2202048 , @phosek wrote:

> How can I test this change on pre-merge bots? I haven't seen any builds 
> posted on this change before.

You can just look at the mlir-windows buildbot, this also showed the failing 
build: http://lab.llvm.org:8011/builders/mlir-windows?numbuilds=200
However it's lagging behind quite a bit.

Pre-merge testing is using a different infrastructure and is not sending 
notifications on failing master build. We're still trying to figure out how to 
deal with a broken master branch properly without building every revision...
Right now it's building master every 4 hours using the same setup used for 
pre-merge testing: https://buildkite.com/llvm-project/llvm-master-build/builds


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-07 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

This patch broke the Windows compilation on buildbot 
 and pre-merge 
testing . So 
I'll revert it to get pre-merge testing back online. Otherwise this will cause 
false-positives for pre-merge testing.

The error message:

  FAILED: bin/llvm-profdata.exe 
  cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe 
--intdir=tools\llvm-profdata\CMakeFiles\llvm-profdata.dir --rc="C:\Program 
Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\rc.exe" --mt="C:\Program Files 
(x86)\Windows Kits\10\bin\10.0.18362.0\x64\mt.exe" --manifests  -- 
C:\BuildTools\VC\Tools\MSVC\14.26.28801\bin\Hostx64\x64\link.exe /nologo 
tools\llvm-profdata\CMakeFiles\llvm-profdata.dir\llvm-profdata.cpp.obj 
tools\llvm-profdata\CMakeFiles\llvm-profdata.dir\__\__\resources\windows_version_resource.rc.res
  /out:bin\llvm-profdata.exe /implib:lib\llvm-profdata.lib 
/pdb:bin\llvm-profdata.pdb /version:0.0  /machine:x64 /STACK:1000 
/INCREMENTAL:NO /subsystem:console  lib\LLVMCore.lib lib\LLVMProfileData.lib 
lib\LLVMSupport.lib lib\LLVMCore.lib lib\LLVMBinaryFormat.lib 
lib\LLVMRemarks.lib lib\LLVMBitstreamReader.lib lib\LLVMSupport.lib psapi.lib 
shell32.lib ole32.lib uuid.lib advapi32.lib C:\GnuWin\lib\zlib.lib delayimp.lib 
-delayload:shell32.dll -delayload:ole32.dll lib\LLVMDemangle.lib kernel32.lib 
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
comdlg32.lib advapi32.lib && cd ."
  LINK: command 
"C:\BuildTools\VC\Tools\MSVC\14.26.28801\bin\Hostx64\x64\link.exe /nologo 
tools\llvm-profdata\CMakeFiles\llvm-profdata.dir\llvm-profdata.cpp.obj 
tools\llvm-profdata\CMakeFiles\llvm-profdata.dir\__\__\resources\windows_version_resource.rc.res
 /out:bin\llvm-profdata.exe /implib:lib\llvm-profdata.lib 
/pdb:bin\llvm-profdata.pdb /version:0.0 /machine:x64 /STACK:1000 
/INCREMENTAL:NO /subsystem:console lib\LLVMCore.lib lib\LLVMProfileData.lib 
lib\LLVMSupport.lib lib\LLVMCore.lib lib\LLVMBinaryFormat.lib 
lib\LLVMRemarks.lib lib\LLVMBitstreamReader.lib lib\LLVMSupport.lib psapi.lib 
shell32.lib ole32.lib uuid.lib advapi32.lib C:\GnuWin\lib\zlib.lib delayimp.lib 
-delayload:shell32.dll -delayload:ole32.dll lib\LLVMDemangle.lib kernel32.lib 
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
comdlg32.lib advapi32.lib /MANIFEST 
/MANIFESTFILE:bin\llvm-profdata.exe.manifest" failed (exit code 1120) with the 
following output:
  LLVMSupport.lib(Compression.cpp.obj) : error LNK2019: unresolved external 
symbol compress2 referenced in function "class llvm::Error __cdecl 
llvm::zlib::compress(class llvm::StringRef,class llvm::SmallVectorImpl 
&,int)" 
(?compress@zlib@llvm@@YA?AVError@2@VStringRef@2@AEAV?$SmallVectorImpl@D@2@H@Z)
  LLVMSupport.lib(Compression.cpp.obj) : error LNK2019: unresolved external 
symbol compressBound referenced in function "class llvm::Error __cdecl 
llvm::zlib::compress(class llvm::StringRef,class llvm::SmallVectorImpl 
&,int)" 
(?compress@zlib@llvm@@YA?AVError@2@VStringRef@2@AEAV?$SmallVectorImpl@D@2@H@Z)
  LLVMSupport.lib(Compression.cpp.obj) : error LNK2019: unresolved external 
symbol uncompress referenced in function "class llvm::Error __cdecl 
llvm::zlib::uncompress(class llvm::StringRef,class llvm::SmallVectorImpl 
&,unsigned __int64)" 
(?uncompress@zlib@llvm@@YA?AVError@2@VStringRef@2@AEAV?$SmallVectorImpl@D@2@_K@Z)
Hint on symbols that are defined and could potentially match:
  "class llvm::Error __cdecl llvm::zlib::uncompress(class 
llvm::StringRef,class llvm::SmallVectorImpl &,unsigned __int64)" 
(?uncompress@zlib@llvm@@YA?AVError@2@VStringRef@2@AEAV?$SmallVectorImpl@D@2@_K@Z)
  "class llvm::Error __cdecl llvm::zlib::uncompress(class 
llvm::StringRef,char *,unsigned __int64 &)" 
(?uncompress@zlib@llvm@@YA?AVError@2@VStringRef@2@PEADAEA_K@Z)
  LLVMSupport.lib(Compression.cpp.obj) : error LNK2019: unresolved external 
symbol crc32 referenced in function "unsigned int __cdecl 
llvm::zlib::crc32(class llvm::StringRef)" (?crc32@zlib@llvm@@YAIVStringRef@2@@Z)
Hint on symbols that are defined and could potentially match:
  "unsigned int __cdecl llvm::zlib::crc32(class llvm::StringRef)" 
(?crc32@zlib@llvm@@YAIVStringRef@2@@Z)
  C:\GnuWin\lib\zlib.lib : warning LNK4272: library machine type 'x86' 
conflicts with target machine type 'x64'
  bin\llvm-profdata.exe : fatal error LNK1120: 4 unresolved externals


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D81737: docker images for mlir-nvidia

2020-06-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 270984.
kuhnel marked 3 inline comments as done.
kuhnel added a comment.
Herald added subscribers: cfe-commits, martong.
Herald added a project: clang.

improved tagging of images


Repository:
  rZORG LLVM Github Zorg

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

https://reviews.llvm.org/D81737

Files:
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp


Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -273,7 +273,7 @@
   resolveDependencies();
   resolveDependencies();
 
-#ifndef NDEBUG // avoid -Wunused warnings in release build.
+#ifndef NDEBUG
   for (auto &DepPair : Dependencies) {
 for (auto &WeakDepPair : WeakDependencies) {
   // Some assertions to enforce that strong dependencies are relations in
@@ -285,9 +285,7 @@
  "A strong dependency mustn't have weak dependencies!");
   assert(WeakDepPair.second != DepPair.second &&
  "A strong dependency mustn't be a weak dependency as well!");
-  (void)WeakDepPair;
 }
-(void)DepPair;
   }
 #endif
 


Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -273,7 +273,7 @@
   resolveDependencies();
   resolveDependencies();
 
-#ifndef NDEBUG // avoid -Wunused warnings in release build.
+#ifndef NDEBUG
   for (auto &DepPair : Dependencies) {
 for (auto &WeakDepPair : WeakDependencies) {
   // Some assertions to enforce that strong dependencies are relations in
@@ -285,9 +285,7 @@
  "A strong dependency mustn't have weak dependencies!");
   assert(WeakDepPair.second != DepPair.second &&
  "A strong dependency mustn't be a weak dependency as well!");
-  (void)WeakDepPair;
 }
-(void)DepPair;
   }
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81737: docker images for mlir-nvidia

2020-06-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 270985.
kuhnel added a comment.

fixed last patch


Repository:
  rZORG LLVM Github Zorg

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

https://reviews.llvm.org/D81737

Files:
  buildbot/google/README.md
  buildbot/google/docker/README.md
  buildbot/google/docker/build_deploy.sh
  buildbot/google/docker/build_run.sh
  buildbot/google/docker/buildbot-mlir-nvidia/Dockerfile
  buildbot/google/docker/buildbot-mlir-nvidia/VERSION
  buildbot/google/docker/buildbot-mlir-nvidia/run.sh

Index: buildbot/google/docker/buildbot-mlir-nvidia/run.sh
===
--- /dev/null
+++ buildbot/google/docker/buildbot-mlir-nvidia/run.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+#===-- run.sh -===//
+# 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 script will start the buildbot worker
+#===--===//
+
+set -eu
+
+# Read the worker password from a mounted file.
+WORKER_PASSWORD=$(cat /secrets/token)
+
+# generate the host information of this worker
+( 
+  uname -a ; \
+  cat /proc/cpuinfo | grep "model name" | head -n1 | cut -d " " -f 3- ;\
+  echo "number of cores: $(nproc)" ;\
+  nvidia-smi -L | cut -d "(" -f 1 ;\
+  lsb_release -d | cut -f 2- ; \
+  clang --version | head -n1 ; \
+  ld.lld-8 --version ; \
+  cmake --version | head -n1 
+) > ${WORKER_NAME}/info/host 
+
+# FIXME(kuhnel):
+# It looks like GKE sometimes deploys the container before the NVIDIA drivers 
+# are loaded on the host. In this case the GPU is not available during the 
+# entire lifecycle of the container. Not sure how to fix this properly. 
+# Maybe the above entry is enough as it depends on a working `nvidia-smi`. 
+# If not a workaround might be to check for the graphics card in this script and 
+# exit immediately if it's not available.
+
+# create the folder structure
+buildslave create-slave --keepalive=200 "${WORKER_NAME}" \
+  lab.llvm.org:9994 "${WORKER_NAME}" "${WORKER_PASSWORD}"
+
+# start the daemon, this command return immetiately
+buildslave start "${WORKER_NAME}"
+
+# To keep the container running and produce log outputs: dump the worker
+# log to stdout
+tail -f ${WORKER_NAME}/twistd.log
Index: buildbot/google/docker/buildbot-mlir-nvidia/VERSION
===
--- /dev/null
+++ buildbot/google/docker/buildbot-mlir-nvidia/VERSION
@@ -0,0 +1 @@
+1
\ No newline at end of file
Index: buildbot/google/docker/buildbot-mlir-nvidia/Dockerfile
===
--- /dev/null
+++ buildbot/google/docker/buildbot-mlir-nvidia/Dockerfile
@@ -0,0 +1,57 @@
+#===-- Dockerfile ===//
+# 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
+#
+#===--===//
+# Docker image used for the mlir-nvidia builder
+#===--===//
+
+# Use the image from NVIDIA as base
+FROM nvidia/cuda:10.2-base-ubuntu18.04
+
+
+# install build tools
+RUN apt-get update; \
+apt-get install -y software-properties-common apt-transport-https ca-certificates \
+  clang-8 lld-8 ninja-build git wget gnupg ccache \
+  python python-pip python-psutil ;\
+update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 100 ;\
+update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 100 ;\
+update-alternatives --install /usr/bin/lld lld /usr/bin/lld-8 100
+
+# install cuda
+# avoid popups for keyboard configurations
+RUN DEBIAN_FRONTEND=noninteractive apt-get install -y cuda
+
+# Ubuntu ships with old cmake version, install the latest one
+# from https://apt.kitware.com/
+RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
+   gpg --dearmor - | \
+   tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null ;\
+apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' ;\
+apt-get update ;\
+apt-get install -y cmake
+
+# install (old) build bot version
+# this version of build bot requires python2!
+RUN pip install buildbot-slave==0.8.11
+
+# Volume to mount secrets into the container
+VOLUME /secrets
+
+# create user account, some test fail if run as root
+RUN useradd buildbot --create-home
+WORKDIR /home/buildbot
+USER buildbot
+
+# copy startup script
+COPY run.sh /home/buildbot/
+
+ENV WORKER_NAME="mlir-n

[PATCH] D81737: docker images for mlir-nvidia

2020-06-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: buildbot/google/docker/build_deploy.sh:36
+
+docker build -t ${IMAGE_NAME}:latest -t ${IMAGE_NAME}:${VERSION} .
+

tra wrote:
> What if I happen to run it in a tree I haven't updated for a while? We 
> probably don't want accidentally overwriting the currently used images with 
> an out-of-date version. Should we check if the image with particular version 
> already exists and inform the user that they are about to overwrite it?
> 
For that we do need to check the remote repository. So I'll keep that code.

It's surprisingly hard to come up with a solid way to tag images :)


Repository:
  rZORG LLVM Github Zorg

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

https://reviews.llvm.org/D81737



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


[PATCH] D72715: [clang][CodeComplete] Propogate printing policy to FunctionDecl

2020-01-20 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

thx for the feedback, I created an issue for this: 
https://github.com/google/llvm-premerge-checks/issues/98


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72715



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


[PATCH] D70357: [clangd] Untangle Hover from XRefs, move into own file.

2019-11-18 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

I had a look at the build problems:
https://github.com/google/llvm-premerge-checks/issues/56


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70357



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


[PATCH] D68937: [clangd] Add parameter renaming to define-inline code action

2019-10-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Build failed as patch failed to apply:

  00:00:06.098 Checking patch clang-tools-extra/trunk/clangd/FindTarget.h...
  00:00:06.100 error: clang-tools-extra/trunk/clangd/FindTarget.h: does not 
exist in index
  00:00:06.100 Checking patch clang-tools-extra/trunk/clangd/FindTarget.cpp...
  00:00:06.100 error: clang-tools-extra/trunk/clangd/FindTarget.cpp: does not 
exist in index
  00:00:06.101 
  00:00:06.101  Patch Failed! 
  00:00:06.101 Usage Exception: Unable to apply patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68937



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


[PATCH] D69033: [clangd] Improve symbol qualification in DefineInline code action

2019-10-16 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

Build failed during patching:

  00:03:00.433 [Phabricator] $ arc patch --diff 225207 --nocommit --nobranch 
--conduit-uri=https://reviews.llvm.org 
  00:03:01.736  INFO  Base commit is not in local repository; trying to fetch.
  00:03:02.694 
  00:03:02.694 
  00:03:02.695 This diff is against commit 
48ec5c8b81c23061eac4fe6f3a14e2e876b8d265, but
  00:03:02.695 the commit is nowhere in the working copy. Try to apply it 
against the
  00:03:02.695 current working copy state? 
(fdccf28697e5debe861247d218cbbecf9fd4323e)
  00:03:02.695 [Y/n]  Exception 
  00:03:02.695 The program is attempting to read user input, but stdin is being 
piped from some other source (not a TTY).
  00:03:02.695 (Run with `--trace` for a full exception trace.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69033



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


[PATCH] D68630: [clangd] Disable expand auto on decltype(auto)

2019-10-08 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

as the automatic build report did not work:

  Failing Tests (1):
  LLVM :: tools/llvm-ar/mri-utf8.test

http://results.llvm-merge-guard.org/Phabricator-23/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68630



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


[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-11 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 209234.
kuhnel marked 3 inline comments as done.
kuhnel added a comment.

  pair programming with Sam, fixed final issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeducedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeducedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -126,6 +127,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  ASSERT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -509,6 +523,140 @@
   )cpp");
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduce type for 'auto' type");
+
+  // undefined functions should not be replaced
+  Input = R"cpp(
+a^uto x = doesnt_exist();
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not de

[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 208923.
kuhnel marked 13 inline comments as done.
kuhnel added a comment.

fixed parts of the 3rd round of review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeducedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeducedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -126,6 +127,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -509,6 +523,132 @@
   )cpp");
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduce type for 'auto' type");
+
+  // undefined functions should not be replaced
+  Input = R"cpp(
+a^uto x = doesnt_exist();
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not d

[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-09 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 208706.
kuhnel added a comment.

fixed typo on "Deducted"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeducedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeducedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -19,6 +20,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+//#include "refactor/tweaks/ExpandAutoType.cpp"
 
 using llvm::Failed;
 using llvm::Succeeded;
@@ -126,6 +128,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -509,6 +524,132 @@
   )cpp");
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduce type for 'auto' type");
+
+  // undefined functions should not be replac

[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-09 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:172
 
+namespace {
+/// Computes the deduced type at a given location by visiting the relevant

sammccall wrote:
> It looks like this has been moved from somewhere (at least code looks 
> familiar) but isn't deleted anywhere. (The code in XRefs is touched but 
> doesn't seem to use this). Is there a reason we can't reuse one copy?
> 
> 
Ah interesting. It got messed up during rebase and someone implemented a 
similar function in XRefs.cpp in the mean time. So I'll just move over to their 
implementation. And remove the changes to AST...



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:32
+  CachedLocation = findAutoType(Node);
+  return CachedLocation != llvm::None;
+}

sammccall wrote:
> && `!CachedLocation->getTypePtr()->getDeducedType()->isNull()`?
> 
> to avoid triggering in e.g. dependent code like
> ```
> template  void f() {
> auto X = T::foo();
> }
> ```
I added the new testcase and if fails with and without the added condition.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:39
+  llvm::Optional DeductedType =
+  getDeducedType(Inputs.AST, CachedLocation->getBeginLoc());
+

sammccall wrote:
> is this ever not just `CachedLocation->getTypePtr()->getDeducedType()`?
There is some difference, because quite a few tests fail, wenn I use your call. 
--> Staying with current implementation



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:47
+  // if it's a lambda expression, return an error message
+  if (isa(*DeductedType) and
+  dyn_cast(*DeductedType)->getDecl()->isLambda()) {

sammccall wrote:
> again, this is actually a cheap test (if we don't need to use the deduced 
> type visitor), we can lift it into prepare
Then I would have to move the call to `getDeducedType(...)` also to 
`prepare`



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:53
+
+  SourceRange OriginalRange(CachedLocation->getBeginLoc(),
+CachedLocation->getEndLoc());

sammccall wrote:
> nit: this is just CachedLocation->getSourceRange()
correct.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:68
+const llvm::Optional
+ExpandAutoType::findAutoType(const SelectionTree::Node* StartNode) {
+  auto Node = StartNode;

sammccall wrote:
> I'm confused about this - how can the user select the child of an AutoTypeLoc 
> rather than the AutoTypeLoc itself? i.e. do we need the loop?
At first I understood that we would have to walk the AST, but it seems we don't 
have to...



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:76
+std::string
+ExpandAutoType::shortenNamespace(const llvm::StringRef &OriginalName,
+ const llvm::StringRef &CurrentNamespace) {

sammccall wrote:
> sammccall wrote:
> > This is nice. We might want to move it to SourceCode.h, somewhere near 
> > SplitQualifiedName. Then we'd generally unit test all the cases in 
> > SourceCodeTests, and we only have to smoke test the shortening here.
> > 
> > One limitation is that it only handles shortening the qualifier on the name 
> > itself, but not other parts of a printed type. e.g. `namespace ns { struct 
> > S(); auto* x = new std::vector(); }` will expand to 
> > `std::vector`, not `std::vector`. To fully solve this we may want 
> > to modify PrintingPolicy at some point, though we could probably get a long 
> > way by searching for chunks of text inside printed types that look like 
> > qualified names.
> > 
> > I think it might more clearly communicate the limitations if this function 
> > operated on the scope part only, e.g. `printScope("clang::clangd::", 
> > "clang::") --> "clangd::"`.
> > 
> > In the general case, `CurrentNamespace` should be a vector, because there 
> > can be others (introduced by using-declarations). Fine to leave this as a 
> > fixme if it's hard to do here, though.
> StringRefs are passed by value. They're just shorthand for a char* + length.
1) added documentation on that.

2) In general it would be nicer to do these operations on a some model and not 
on bare strings. We could probably recursively search for more namespaces 
inside angle brackets <>...



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:221
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";

sammccall wrote:
> can you add testcases for:
>  - unknown types in a template `template  void x() { auto y = 
> T::z(); }`
>  - broken code `auto x = doesnt_exist();`
>  - lambda `auto x = []{};`
>  - inline/anon namespace: `inline namespace x { namespace { struct S; } } 
> auto y = S();` should insert

[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-09 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 208705.
kuhnel marked 22 inline comments as done.
kuhnel added a comment.

Allrighty then, next update:

- moved 2 helper funtions to `AST.cpp`
- added `ASTTests.cpp`
- added more tests
- removed a lot of redundant code
- implemented corner case for not replacing function pointers
- removed unwanted header file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeductedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeductedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeductedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -19,6 +20,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+//#include "refactor/tweaks/ExpandAutoType.cpp"
 
 using llvm::Failed;
 using llvm::Succeeded;
@@ -126,6 +128,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -509,6 +524,132 @@
   )cpp");
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types 

[PATCH] D62855: Implementation of auto type expansion.

2019-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 207039.
kuhnel marked an inline comment as done.
kuhnel added a comment.

  fixed merge error around hasDeducedType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.h
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeductedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeductedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeductedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -19,6 +20,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include "refactor/tweaks/ExpandAutoType.h"
 
 using llvm::Failed;
 using llvm::Succeeded;
@@ -126,6 +128,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -278,6 +293,164 @@
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduct type for 'auto' type");
+
+  // undefined functions should not be replaced
+  Input = R"cpp(
+a^uto x =

[PATCH] D62855: Implementation of auto type expansion.

2019-06-28 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 207037.
kuhnel marked 10 inline comments as done.
kuhnel added a comment.

  fixed code review comments from sam


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.h
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeductedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeductedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeductedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -19,6 +20,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include "refactor/tweaks/ExpandAutoType.h"
 
 using llvm::Failed;
 using llvm::Succeeded;
@@ -126,6 +128,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -278,6 +293,164 @@
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduct type for 'auto' type");
+
+  // undefined functions should not be replaced
+  Input = R"cpp(
+a^uto x = do

[PATCH] D62855: Implementation of auto type expansion.

2019-06-04 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
kuhnel added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.h
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1971,6 +1971,28 @@
   }
 }
 
+TEST(GetDeductedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeductedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeductedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -19,6 +19,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include "refactor/tweaks/ExpandAutoType.h"
 
 using llvm::Failed;
 using llvm::HasValue;
@@ -217,6 +218,111 @@
   checkTransform(ID, Input, Output);
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+}
+
+TEST(ExpandAutoType, GetNamespaceString) {
+  struct EATWrapper : ExpandAutoType {
+// to access the protected method
+using ExpandAutoType::getNamespaceString;
+  };
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  Annotations Code("namespace firstns{namespace secondns{ au^to i = 0;} }");
+  TU.Code = Code.code();
+  ParsedAST AST = TU.build();
+  ASSERT_TRUE(AST.getDiagnostics().empty());
+  auto Tree = SelectionTree(AST.getASTContext(), 
+*positionToOffset(Code.code(), Code.point()));
+  ASSERT_EQ("firstns::secondns", EATWrapper::getNamespaceString(Tree.commonAncestor()));
+}
+
+TEST(ExpandAutoType, ShortenNamespace) {
+  struct EATWrapper : ExpandAutoType {
+// to access the protected method
+using ExpandAutoType::shortenNamespace;
+  };
+
+  ASSERT_EQ("TestClass", 
+  EATWrapper::shortenNamespace("TestClass", ""));
+  
+  ASSERT_EQ("TestClass", 
+  EATWrapper::shortenNamespace("testnamespace::TestClass", "testnamespace"));
+  
+  ASSERT_EQ("namespace1::TestClass",
+  EATWrapper::shortenNamespace("namespace1::TestClass", "namespace2"));
+  
+  ASSERT_EQ("TestClass",
+  EATWrapper::shortenNamespace("testns1::testns2::TestClass", "testns1::testns2"));
+  
+  ASSERT_EQ(
+  "testns2::TestClass",
+  EATWrapper::shortenNamespace("testns1::testns2::TestClass", "testns1"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
+
In

[PATCH] D60826: Clarify -Winfinite-recursion message

2019-04-17 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
kuhnel added a reviewer: meikeb.
Herald added a project: clang.

Test review from the tutorial


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60826

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/SemaCXX/warn-infinite-recursion.cpp

Index: clang/test/SemaCXX/warn-infinite-recursion.cpp
===
--- clang/test/SemaCXX/warn-infinite-recursion.cpp
+++ clang/test/SemaCXX/warn-infinite-recursion.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -Winfinite-recursion
 
-void a() {  // expected-warning{{call itself}}
+void a() {  // expected-warning{{to understand recursion}}
   a();
 }
 
-void b(int x) {  // expected-warning{{call itself}}
+void b(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 b(x);
   else
@@ -16,7 +16,7 @@
 c(5);
 }
 
-void d(int x) {  // expected-warning{{call itself}}
+void d(int x) {  // expected-warning{{to understand recursion}}
   if (x)
 ++x;
   return d(x);
@@ -29,7 +29,7 @@
 void e() { f(); }
 void f() { e(); }
 
-void g() {  // expected-warning{{call itself}}
+void g() {  // expected-warning{{to understand recursion}}
   while (true)
 g();
 
@@ -42,14 +42,14 @@
   }
 }
 
-void i(int x) {  // expected-warning{{call itself}}
+void i(int x) {  // expected-warning{{to understand recursion}}
   while (x < 5) {
 --x;
   }
   i(0);
 }
 
-int j() {  // expected-warning{{call itself}}
+int j() {  // expected-warning{{to understand recursion}}
   return 5 + j();
 }
 
@@ -80,11 +80,11 @@
   void b();
 };
 
-void S::a() {  // expected-warning{{call itself}}
+void S::a() {  // expected-warning{{to understand recursion}}
   return a();
 }
 
-void S::b() {  // expected-warning{{call itself}}
+void S::b() {  // expected-warning{{to understand recursion}}
   int i = 0;
   do {
 ++i;
@@ -95,8 +95,8 @@
 template
 struct T {
   member m;
-  void a() { return a(); }  // expected-warning{{call itself}}
-  static void b() { return b(); }  // expected-warning{{call itself}}
+  void a() { return a(); }  // expected-warning{{to understand recursion}}
+  static void b() { return b(); }  // expected-warning{{to understand recursion}}
 };
 
 void test_T() {
@@ -107,13 +107,13 @@
 
 class U {
   U* u;
-  void Fun() {  // expected-warning{{call itself}}
+  void Fun() {  // expected-warning{{to understand recursion}}
 u->Fun();
   }
 };
 
 // No warnings on templated functions
-// sum<0>() is instantiated, does recursively call itself, but never runs.
+// sum<0>() is instantiated, does recursively to understand recursion, but never runs.
 template 
 int sum() {
   return value + sum();
@@ -157,7 +157,7 @@
   return 0;
 return Wrapper::run();
   }
-  static int run2() {  // expected-warning{{call itself}}
+  static int run2() {  // expected-warning{{to understand recursion}}
 return run2();
   }
 };
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -61,7 +61,7 @@
   "remove call to max function and unsigned zero argument">;
 
 def warn_infinite_recursive_function : Warning<
-  "all paths through this function will call itself">,
+  "in order to understand recursion, you must first understand recursion">,
   InGroup, DefaultIgnore;
 
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits