[clang-tools-extra] r339116 - [clangd] Share getSymbolID implementation.

2018-08-07 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Aug  7 01:57:52 2018
New Revision: 339116

URL: http://llvm.org/viewvc/llvm-project?rev=339116&view=rev
Log:
[clangd] Share getSymbolID implementation.

Summary: And remove all duplicated implementation.

Reviewers: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/clangd/AST.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp

Modified: clang-tools-extra/trunk/clangd/AST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=339116&r1=339115&r2=339116&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.cpp (original)
+++ clang-tools-extra/trunk/clangd/AST.cpp Tue Aug  7 01:57:52 2018
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Index/USRGeneration.h"
 
 namespace clang {
 namespace clangd {
@@ -53,5 +54,12 @@ std::string printQualifiedName(const Nam
   return QName;
 }
 
+llvm::Optional getSymbolID(const Decl *D) {
+  llvm::SmallString<128> USR;
+  if (index::generateUSRForDecl(D, USR))
+return None;
+  return SymbolID(USR);
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/AST.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=339116&r1=339115&r2=339116&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.h (original)
+++ clang-tools-extra/trunk/clangd/AST.h Tue Aug  7 01:57:52 2018
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/Basic/SourceLocation.h"
+#include "index/Index.h"
 
 namespace clang {
 class SourceManager;
@@ -33,6 +34,9 @@ SourceLocation findNameLoc(const clang::
 /// like inline namespaces.
 std::string printQualifiedName(const NamedDecl &ND);
 
+/// Gets the symbol ID for a declaration, if possible.
+llvm::Optional getSymbolID(const Decl *D);
+
 } // namespace clangd
 } // namespace clang
 

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=339116&r1=339115&r2=339116&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Aug  7 01:57:52 2018
@@ -396,10 +396,7 @@ llvm::Optional getSymbolID(con
   switch (R.Kind) {
   case CodeCompletionResult::RK_Declaration:
   case CodeCompletionResult::RK_Pattern: {
-llvm::SmallString<128> USR;
-if (/*Ignore=*/clang::index::generateUSRForDecl(R.Declaration, USR))
-  return None;
-return SymbolID(USR);
+return clang::clangd::getSymbolID(R.Declaration);
   }
   case CodeCompletionResult::RK_Macro:
 // FIXME: Macros do have USRs, but the CCR doesn't contain enough info.

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=339116&r1=339115&r2=339116&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Aug  7 01:57:52 2018
@@ -202,15 +202,6 @@ makeLocation(ParsedAST &AST, const Sourc
   return L;
 }
 
-// Get the symbol ID for a declaration, if possible.
-llvm::Optional getSymbolID(const Decl *D) {
-  llvm::SmallString<128> USR;
-  if (index::generateUSRForDecl(D, USR)) {
-return None;
-  }
-  return SymbolID(USR);
-}
-
 } // namespace
 
 std::vector findDefinitions(ParsedAST &AST, Position Pos,

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=339116&r1=339115&r2=339116&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Aug  7 
01:57:52 2018
@@ -320,21 +320,20 @@ bool SymbolCollector::handleDeclOccurenc
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
 
-  llvm::SmallString<128> USR;
-  if (index::generateUSRForDecl(ND, USR))
+  auto ID = getSymbolID(ND);
+  if (!ID)
 return true;
-  SymbolID ID(USR);
 
   const NamedDecl &OriginalDecl = *cast(ASTNode.OrigD);
-  const Symbol *BasicSymbol = Symbols.find(ID);
+  const Symbol *BasicSymbol = Symbols.find(*ID);
   if (!BasicSymbol) // Regardless of role, ND is the canonical declaration.
-BasicSymbol = addDeclaration(*ND, std::move(ID

[clang-tools-extra] r339415 - [clang-tidy] Omit cases where loop variable is not used in loop body in

2018-08-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 10 01:25:51 2018
New Revision: 339415

URL: http://llvm.org/viewvc/llvm-project?rev=339415&view=rev
Log:
[clang-tidy] Omit cases where loop variable is not used in loop body in
performance-for-range-copy check.

Summary:
The upstream change r336737 make the check too smart to fix the case
where loop variable could be used as `const auto&`.

But for the case below, changing to `const auto _` will introduce
an unused complier warning.

```
for (auto _ : state) {
  // no references for _.
}
```

This patch omit this case, and it is safe to do it as the case is very rare.

Reviewers: ilya-biryukov, alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/performance-for-range-copy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp?rev=339415&r1=339414&r2=339415&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/ForRangeCopyCheck.cpp Fri 
Aug 10 01:25:51 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "ForRangeCopyCheck.h"
+#include "../utils/DeclRefExprUtils.h"
 #include "../utils/ExprMutationAnalyzer.h"
 #include "../utils/FixItHintUtils.h"
 #include "../utils/TypeTraits.h"
@@ -79,15 +80,27 @@ bool ForRangeCopyCheck::handleCopyIsOnly
   utils::type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
   if (LoopVar.getType().isConstQualified() || !Expensive || !*Expensive)
 return false;
-  if (utils::ExprMutationAnalyzer(ForRange.getBody(), &Context)
-  .isMutated(&LoopVar))
-return false;
-  diag(LoopVar.getLocation(),
-   "loop variable is copied but only used as const reference; consider "
-   "making it a const reference")
-  << utils::fixit::changeVarDeclToConst(LoopVar)
-  << utils::fixit::changeVarDeclToReference(LoopVar, Context);
-  return true;
+  // We omit the case where the loop variable is not used in the loop body. 
E.g.
+  //
+  // for (auto _ : benchmark_state) {
+  // }
+  //
+  // Because the fix (changing to `const auto &`) will introduce an unused
+  // compiler warning which can't be suppressed.
+  // Since this case is very rare, it is safe to ignore it.
+  if (!utils::ExprMutationAnalyzer(ForRange.getBody(), &Context)
+  .isMutated(&LoopVar) &&
+  !utils::decl_ref_expr::allDeclRefExprs(LoopVar, *ForRange.getBody(),
+ Context)
+   .empty()) {
+diag(LoopVar.getLocation(),
+ "loop variable is copied but only used as const reference; consider "
+ "making it a const reference")
+<< utils::fixit::changeVarDeclToConst(LoopVar)
+<< utils::fixit::changeVarDeclToReference(LoopVar, Context);
+return true;
+  }
+  return false;
 }
 
 } // namespace performance

Modified: clang-tools-extra/trunk/test/clang-tidy/performance-for-range-copy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-for-range-copy.cpp?rev=339415&r1=339414&r2=339415&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/performance-for-range-copy.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/performance-for-range-copy.cpp Fri 
Aug 10 01:25:51 2018
@@ -260,3 +260,8 @@ void PositiveConstNonMemberOperatorInvok
 bool result = ConstOperatorInvokee != Mutable();
   }
 }
+
+void IgnoreLoopVariableNotUsedInLoopBody() {
+  for (auto _ : View>()) {
+  }
+}


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


[clang-tools-extra] r339416 - [clangd] Fix a "-Wdangling-else" compiler warning in the test.

2018-08-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 10 01:34:16 2018
New Revision: 339416

URL: http://llvm.org/viewvc/llvm-project?rev=339416&view=rev
Log:
[clangd] Fix a "-Wdangling-else" compiler warning in the test.

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

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=339416&r1=339415&r2=339416&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Aug 10 
01:34:16 2018
@@ -1393,8 +1393,9 @@ TEST(CompletionTest, FixItForArrowToDot)
   ReplacementEdit.newText = ".";
   for (const auto &C : Results.Completions) {
 EXPECT_TRUE(C.FixIts.size() == 1u || C.Name == "AuxFunction");
-if (!C.FixIts.empty())
+if (!C.FixIts.empty()) {
   EXPECT_THAT(C.FixIts, ElementsAre(ReplacementEdit));
+}
   }
 }
 


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


r339558 - Revert "Allow relockable scopes with thread safety attributes."

2018-08-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Aug 13 05:50:30 2018
New Revision: 339558

URL: http://llvm.org/viewvc/llvm-project?rev=339558&view=rev
Log:
Revert "Allow relockable scopes with thread safety attributes."

This reverts commit r339456.

The change introduces a new crash, see

class SCOPED_LOCKABLE FileLock {
 public:
  explicit FileLock()
  EXCLUSIVE_LOCK_FUNCTION(file_);
  ~FileLock() UNLOCK_FUNCTION(file_);
  void Lock() EXCLUSIVE_LOCK_FUNCTION(file_);
  Mutex file_;
};

void relockShared2() {
  FileLock file_lock;
  file_lock.Lock();
}

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=339558&r1=339557&r2=339558&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Mon Aug 13 05:50:30 2018
@@ -86,8 +86,8 @@ static void warnInvalidLock(ThreadSafety
 
 namespace {
 
-/// A set of CapabilityExpr objects, which are compiled from thread safety
-/// attributes on a function.
+/// A set of CapabilityInfo objects, which are compiled from the
+/// requires attributes on a function.
 class CapExprSet : public SmallVector {
 public:
   /// Push M onto list, but discard duplicates.
@@ -944,23 +944,6 @@ public:
 if (FullyRemove)
   FSet.removeLock(FactMan, Cp);
   }
-
-  void Relock(FactSet &FSet, FactManager &FactMan, LockKind LK,
-  SourceLocation RelockLoc, ThreadSafetyHandler &Handler,
-  StringRef DiagKind) const {
-for (const auto *UnderlyingMutex : UnderlyingMutexes) {
-  CapabilityExpr UnderCp(UnderlyingMutex, false);
-
-  // We're relocking the underlying mutexes. Warn on double locking.
-  if (FSet.findLock(FactMan, UnderCp))
-Handler.handleDoubleLock(DiagKind, UnderCp.toString(), RelockLoc);
-  else {
-FSet.removeLock(FactMan, !UnderCp);
-FSet.addLock(FactMan, llvm::make_unique(UnderCp, LK,
-   RelockLoc));
-  }
-}
-  }
 };
 
 /// Class which implements the core thread safety analysis routines.
@@ -991,9 +974,6 @@ public:
   void removeLock(FactSet &FSet, const CapabilityExpr &CapE,
   SourceLocation UnlockLoc, bool FullyRemove, LockKind Kind,
   StringRef DiagKind);
-  void relockScopedLock(FactSet &FSet, const CapabilityExpr &CapE,
-SourceLocation RelockLoc, LockKind Kind,
-StringRef DiagKind);
 
   template 
   void getMutexIDs(CapExprSet &Mtxs, AttrType *Attr, Expr *Exp,
@@ -1305,27 +1285,6 @@ void ThreadSafetyAnalyzer::removeLock(Fa
  DiagKind);
 }
 
-void ThreadSafetyAnalyzer::relockScopedLock(FactSet &FSet,
-const CapabilityExpr &Cp,
-SourceLocation RelockLoc,
-LockKind Kind, StringRef DiagKind) 
{
-  if (Cp.shouldIgnore())
-return;
-
-  const FactEntry *LDat = FSet.findLock(FactMan, Cp);
-  if (!LDat) {
-// FIXME: It's possible to manually destruct the scope and then relock it.
-// Should that be a separate warning? For now we pretend nothing happened.
-// It's undefined behavior, so not related to thread safety.
-return;
-  }
-
-  // We should only land here if Cp is a scoped capability, so if we have any
-  // fact, it must be a ScopedLockableFactEntry.
-  const auto *SLDat = static_cast(LDat);
-  SLDat->Relock(FSet, FactMan, Kind, RelockLoc, Handler, DiagKind);
-}
-
 /// Extract the list of mutexIDs from the attribute on an expression,
 /// and push them onto Mtxs, discarding any duplicates.
 template 
@@ -1767,19 +1726,14 @@ void BuildLockset::handleCall(Expr *Exp,
   StringRef CapDiagKind = "mutex";
 
   // Figure out if we're constructing an object of scoped lockable class
-  bool isScopedConstructor = false, isScopedMemberCall = false;
+  bool isScopedVar = false;
   if (VD) {
 if (const auto *CD = dyn_cast(D)) {
   const CXXRecordDecl* PD = CD->getParent();
   if (PD && PD->hasAttr())
-isScopedConstructor = true;
+isScopedVar = true;
 }
   }
-  if (const auto *MCD = dyn_cast(Exp)) {
-const CXXRecordDecl *PD = MCD->getRecordDecl();
-if (PD && PD->hasAttr())
-  isScopedMemberCall = true;
-  }
 
   for(const Attr *At : D->attrs()) {
 switch (At->getKind()) {
@@ -1859,7 +1813,7 @@ void BuildLockset::handleCall(Expr *Exp,
  POK_FunctionCall, ClassifyDiagnostic(A),
  Exp->getExprLoc());
   // use for adopting a lock
-  if (isScopedConstructor) {
+  if (isScopedVar) {
 Analyzer->getMutexIDs(A->isShared() ? ScopedSharedReqs

[clang-tools-extra] r340001 - [clangd] Always use the latest preamble

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 01:15:22 2018
New Revision: 340001

URL: http://llvm.org/viewvc/llvm-project?rev=340001&view=rev
Log:
[clangd] Always use the latest preamble

Summary:
Fix an inconsistent behavior of using `LastBuiltPreamble`/`NewPreamble`
in TUScheduler (see the test for details), AST should always use
NewPreamble. This patch makes LastBuiltPreamble always point to
NewPreamble.

Preamble rarely fails to build, even there are errors in headers, so we
assume it would not cause performace issue for code completion.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=340001&r1=34&r2=340001&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Fri Aug 17 01:15:22 2018
@@ -370,8 +370,7 @@ void ASTWorker::update(
 bool CanReuseAST = InputsAreTheSame && (OldPreamble == NewPreamble);
 {
   std::lock_guard Lock(Mutex);
-  if (NewPreamble)
-LastBuiltPreamble = NewPreamble;
+  LastBuiltPreamble = NewPreamble;
 }
 // Before doing the expensive AST reparse, we want to release our reference
 // to the old preamble, so it can be freed if there are no other references

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=340001&r1=34&r2=340001&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Aug 17 01:15:22 
2018
@@ -1021,6 +1021,51 @@ TEST(GoToInclude, All) {
   EXPECT_THAT(*Locations, IsEmpty());
 }
 
+TEST(GoToDefinition, WithPreamble) {
+  // Test stragety: AST should always use the latest preamble instead of last
+  // good preamble.
+  MockFSProvider FS;
+  IgnoreDiagnostics DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  auto FooCppUri = URIForFile{FooCpp};
+  // The trigger locations must be the same.
+  Annotations FooWithHeader(R"cpp(#include "fo^o.h")cpp");
+  Annotations FooWithoutHeader(R"cpp(double[[fo^o]]();)cpp");
+
+  FS.Files[FooCpp] = FooWithHeader.code();
+
+  auto FooH = testPath("foo.h");
+  auto FooHUri = URIForFile{FooH};
+  Annotations FooHeader(R"cpp([[]])cpp");
+  FS.Files[FooH] = FooHeader.code();
+
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // GoToDefinition goes to a #include file: the result comes from the 
preamble.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithHeader.point())),
+  ElementsAre(Location{FooHUri, FooHeader.range()}));
+
+  // Only preamble is built, and no AST is built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  // We build AST here, and it should use the latest preamble rather than the
+  // stale one.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+
+  // Reset test environment.
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // Both preamble and AST are built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  // Use the AST being built in above request.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


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


r340029 - [Preamble] Empty preamble is not an error.

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 07:25:10 2018
New Revision: 340029

URL: http://llvm.org/viewvc/llvm-project?rev=340029&view=rev
Log:
[Preamble] Empty preamble is not an error.

Summary:
Empty preamble is valid for source file which doesn't have any
preprocessor and #includes.

This patch makes clang treat an empty preamble as a normal preamble.

Check: ninja check-clang

A testcase is added in https://reviews.llvm.org/D50627.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original)
+++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Fri Aug 17 07:25:10 
2018
@@ -286,8 +286,7 @@ public:
 };
 
 enum class BuildPreambleError {
-  PreambleIsEmpty = 1,
-  CouldntCreateTempFile,
+  CouldntCreateTempFile = 1,
   CouldntCreateTargetInfo,
   BeginSourceFileFailed,
   CouldntEmitPCH

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Aug 17 07:25:10 2018
@@ -1363,7 +1363,6 @@ ASTUnit::getMainBufferWithPrecompiledPre
 } else {
   switch (static_cast(NewPreamble.getError().value())) 
{
   case BuildPreambleError::CouldntCreateTempFile:
-  case BuildPreambleError::PreambleIsEmpty:
 // Try again next time.
 PreambleRebuildCounter = 1;
 return nullptr;

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Fri Aug 17 07:25:10 2018
@@ -237,9 +237,6 @@ llvm::ErrorOr Preco
 PreambleCallbacks &Callbacks) {
   assert(VFS && "VFS is null");
 
-  if (!Bounds.Size)
-return BuildPreambleError::PreambleIsEmpty;
-
   auto PreambleInvocation = std::make_shared(Invocation);
   FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
   PreprocessorOptions &PreprocessorOpts =
@@ -423,9 +420,6 @@ bool PrecompiledPreamble::CanReuse(const
   PreprocessorOptions &PreprocessorOpts =
   PreambleInvocation->getPreprocessorOpts();
 
-  if (!Bounds.Size)
-return false;
-
   // We've previously computed a preamble. Check whether we have the same
   // preamble now that we did before, and that there's enough space in
   // the main-file buffer within the precompiled preamble to fit the
@@ -758,8 +752,6 @@ const char *BuildPreambleErrorCategory::
 
 std::string BuildPreambleErrorCategory::message(int condition) const {
   switch (static_cast(condition)) {
-  case BuildPreambleError::PreambleIsEmpty:
-return "Preamble is empty";
   case BuildPreambleError::CouldntCreateTempFile:
 return "Could not create temporary file for PCH";
   case BuildPreambleError::CouldntCreateTargetInfo:


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


[clang-tools-extra] r340035 - [clangd] Add a testcase for empty preamble.

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 07:55:57 2018
New Revision: 340035

URL: http://llvm.org/viewvc/llvm-project?rev=340035&view=rev
Log:
[clangd] Add a testcase for empty preamble.

Summary: This is a patch of add a testcase for https://reviews.llvm.org/D50628.

Reviewers: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits

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

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

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=340035&r1=340034&r2=340035&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Fri Aug 17 
07:55:57 2018
@@ -308,6 +308,51 @@ TEST_F(TUSchedulerTests, EvictedAST) {
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few preamble reads at
   // the same time. All reads should get the same non-null preamble.


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


[clang-tools-extra] r340038 - [clang-tidy] Abseil: integral division of Duration check

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 08:19:19 2018
New Revision: 340038

URL: http://llvm.org/viewvc/llvm-project?rev=340038&view=rev
Log:
[clang-tidy] Abseil: integral division of Duration check

This check is an abseil specific test that tests to ensure users utilize abseil 
specific floating point division when trying to divide with abseil duration 
types.

Patch by Deanna Garcia!

Added:
clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.h
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-division.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340038&r1=340037&r2=340038&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Fri Aug 17 
08:19:19 2018
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "DurationDivisionCheck.h"
 #include "StringFindStartswithCheck.h"
 
 namespace clang {
@@ -19,6 +20,8 @@ namespace abseil {
 class AbseilModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"abseil-duration-division");
 CheckFactories.registerCheck(
 "abseil-string-find-startswith");
   }

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340038&r1=340037&r2=340038&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Fri Aug 17 
08:19:19 2018
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
+  DurationDivisionCheck.cpp
   StringFindStartswithCheck.cpp
 
   LINK_LIBS

Added: clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.cpp?rev=340038&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationDivisionCheck.cpp Fri Aug 
17 08:19:19 2018
@@ -0,0 +1,59 @@
+//===--- DurationDivisionCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DurationDivisionCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+using namespace clang::ast_matchers;
+
+void DurationDivisionCheck::registerMatchers(MatchFinder *finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  const auto DurationExpr =
+  expr(hasType(cxxRecordDecl(hasName("::absl::Duration";
+  finder->addMatcher(
+  implicitCastExpr(
+  hasSourceExpression(ignoringParenCasts(
+  cxxOperatorCallExpr(hasOverloadedOperatorName("/"),
+  hasArgument(0, DurationExpr),
+  hasArgument(1, DurationExpr))
+  .bind("OpCall"))),
+  hasImplicitDestinationType(qualType(unless(isInteger(,
+  unless(hasParent(cxxStaticCastExpr())),
+  unless(hasParent(cStyleCastExpr())),
+  unless(isInTemplateInstantiation())),
+  this);
+}
+
+void DurationDivisionCheck::check(const MatchFinder::MatchResult &result) {
+  const auto *OpCall = result.Nodes.getNodeAs("OpCall");
+  diag(OpCall->getOperatorLoc(),
+   "operator/ on absl::Duration objects performs integer division; "
+   "did you mean to use FDivDuration()?")
+  << FixItHint::CreateInsertion(OpCall->getBeginLoc(),
+"absl::FDivDuration(")
+  << FixItHint::CreateReplacement(
+ SourceRange(OpCall->getOperatorLoc(), OpCall->getOperatorLoc()),
+ ", ")
+  << FixItHint::CreateInsertion(
+ Lexer::getLocForEndOfToken(
+ result.Sour

[clang-tools-extra] r340075 - [clang-tidy] Add missing check documentation.

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 12:50:22 2018
New Revision: 340075

URL: http://llvm.org/viewvc/llvm-project?rev=340075&view=rev
Log:
[clang-tidy] Add missing check documentation.

Added:
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-division.rst

Added: 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-division.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-division.rst?rev=340075&view=auto
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-division.rst 
(added)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-division.rst 
Fri Aug 17 12:50:22 2018
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - abseil-duration-division
+
+abseil-duration-division
+
+
+``absl::Duration`` arithmetic works like it does with integers. That means that
+division of two ``absl::Duration`` objects returns an ``int64`` with any 
fractional
+component truncated toward 0. See `this link 
`_
 for more information on arithmetic with ``absl::Duration``.
+
+For example:
+
+.. code-block:: c++
+
+ absl::Duration d = absl::Seconds(3.5);
+ int64 sec1 = d / absl::Seconds(1); // Truncates toward 0.
+ int64 sec2 = absl::ToInt64Seconds(d);  // Equivalent to division.
+ assert(sec1 == 3 && sec2 == 3);
+
+ double dsec = d / absl::Seconds(1);  // WRONG: Still truncates toward 0.
+ assert(dsec == 3.0);
+
+If you want floating-point division, you should use either the
+``absl::FDivDuration()`` function, or one of the unit conversion functions such
+as ``absl::ToDoubleSeconds()``. For example:
+
+.. code-block:: c++
+
+ absl::Duration d = absl::Seconds(3.5);
+ double dsec1 = absl::FDivDuration(d, absl::Seconds(1));  // GOOD: No 
truncation.
+ double dsec2 = absl::ToDoubleSeconds(d); // GOOD: No 
truncation.
+ assert(dsec1 == 3.5 && dsec2 == 3.5);
+
+
+This check looks for uses of ``absl::Duration`` division that is done in a
+floating-point context, and recommends the use of a function that returns a
+floating-point value.


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


[clang-tools-extra] r340156 - [clangd] Add missing lock in the lookup.

2018-08-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Aug 20 02:07:59 2018
New Revision: 340156

URL: http://llvm.org/viewvc/llvm-project?rev=340156&view=rev
Log:
[clangd] Add missing lock in the lookup.

Reviewers: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/index/MemIndex.cpp

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=340156&r1=340155&r2=340156&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Mon Aug 20 02:07:59 2018
@@ -64,6 +64,7 @@ bool MemIndex::fuzzyFind(
 
 void MemIndex::lookup(const LookupRequest &Req,
   llvm::function_ref Callback) const 
{
+  std::lock_guard Lock(Mutex);
   for (const auto &ID : Req.IDs) {
 auto I = Index.find(ID);
 if (I != Index.end())


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


[clang-tools-extra] r340161 - [clangd] Simplify the code using UniqueStringSaver, NFC.

2018-08-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Aug 20 02:47:12 2018
New Revision: 340161

URL: http://llvm.org/viewvc/llvm-project?rev=340161&view=rev
Log:
[clangd] Simplify the code using UniqueStringSaver, NFC.

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

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=340161&r1=340160&r2=340161&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Mon Aug 20 02:47:12 2018
@@ -77,16 +77,10 @@ SymbolSlab::const_iterator SymbolSlab::f
 }
 
 // Copy the underlying data of the symbol into the owned arena.
-static void own(Symbol &S, DenseSet &Strings,
+static void own(Symbol &S, llvm::UniqueStringSaver &Strings,
 BumpPtrAllocator &Arena) {
   // Intern replaces V with a reference to the same string owned by the arena.
-  auto Intern = [&](StringRef &V) {
-auto R = Strings.insert(V);
-if (R.second) { // New entry added to the table, copy the string.
-  *R.first = V.copy(Arena);
-}
-V = *R.first;
-  };
+  auto Intern = [&](StringRef &V) { V = Strings.save(V); };
 
   // We need to copy every StringRef field onto the arena.
   Intern(S.Name);
@@ -114,10 +108,10 @@ void SymbolSlab::Builder::insert(const S
   auto R = SymbolIndex.try_emplace(S.ID, Symbols.size());
   if (R.second) {
 Symbols.push_back(S);
-own(Symbols.back(), Strings, Arena);
+own(Symbols.back(), UniqueStrings, Arena);
   } else {
 auto &Copy = Symbols[R.first->second] = S;
-own(Copy, Strings, Arena);
+own(Copy, UniqueStrings, Arena);
   }
 }
 
@@ -128,7 +122,7 @@ SymbolSlab SymbolSlab::Builder::build()
 [](const Symbol &L, const Symbol &R) { return L.ID < R.ID; });
   // We may have unused strings from overwritten symbols. Build a new arena.
   BumpPtrAllocator NewArena;
-  DenseSet Strings;
+  llvm::UniqueStringSaver Strings(NewArena);
   for (auto &S : Symbols)
 own(S, Strings, NewArena);
   return SymbolSlab(std::move(NewArena), std::move(Symbols));

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=340161&r1=340160&r2=340161&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Aug 20 02:47:12 2018
@@ -17,6 +17,7 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 #include 
 
@@ -257,6 +258,8 @@ public:
   // The frozen SymbolSlab will use less memory.
   class Builder {
   public:
+Builder() : UniqueStrings(Arena) {}
+
 // Adds a symbol, overwriting any existing one with the same ID.
 // This is a deep copy: underlying strings will be owned by the slab.
 void insert(const Symbol &S);
@@ -273,7 +276,7 @@ public:
   private:
 llvm::BumpPtrAllocator Arena;
 // Intern table for strings. Contents are on the arena.
-llvm::DenseSet Strings;
+llvm::UniqueStringSaver UniqueStrings;
 std::vector Symbols;
 // Values are indices into Symbols vector.
 llvm::DenseMap SymbolIndex;


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


r340403 - [Preamble] Fix an undefined behavior when checking an empty preamble can be reused.

2018-08-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Aug 22 05:34:04 2018
New Revision: 340403

URL: http://llvm.org/viewvc/llvm-project?rev=340403&view=rev
Log:
[Preamble] Fix an undefined behavior when checking an empty preamble can be 
reused.

Summary: Passing nullptr to memcmp is UB.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=340403&r1=340402&r2=340403&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed Aug 22 05:34:04 2018
@@ -426,8 +426,8 @@ bool PrecompiledPreamble::CanReuse(const
   // new main file.
   if (PreambleBytes.size() != Bounds.Size ||
   PreambleEndsAtStartOfLine != Bounds.PreambleEndsAtStartOfLine ||
-  memcmp(PreambleBytes.data(), MainFileBuffer->getBufferStart(),
- Bounds.Size) != 0)
+  !std::equal(PreambleBytes.begin(), PreambleBytes.end(),
+  MainFileBuffer->getBuffer().begin()))
 return false;
   // The preamble has not changed. We may be able to re-use the precompiled
   // preamble.


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


[clang-tools-extra] r340411 - [clang-tidy] Abseil: faster strsplit delimiter check

2018-08-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Aug 22 06:58:25 2018
New Revision: 340411

URL: http://llvm.org/viewvc/llvm-project?rev=340411&view=rev
Log:
[clang-tidy] Abseil: faster strsplit delimiter check

This check is an abseil specific check that checks for code using single 
character string literals as delimiters and transforms the code into characters.

The check was developed internally and has been running at google, this is just
a move to open source the check. It was originally written by @sbenza.

Patch by Deanna Garcia!

Added:
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340411&r1=340410&r2=340411&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Wed Aug 22 
06:58:25 2018
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DurationDivisionCheck.h"
+#include "FasterStrsplitDelimiterCheck.h"
 #include "StringFindStartswithCheck.h"
 
 namespace clang {
@@ -22,6 +23,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "abseil-duration-division");
+CheckFactories.registerCheck(
+"abseil-faster-strsplit-delimiter");
 CheckFactories.registerCheck(
 "abseil-string-find-startswith");
   }

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340411&r1=340410&r2=340411&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Wed Aug 22 
06:58:25 2018
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
   DurationDivisionCheck.cpp
+  FasterStrsplitDelimiterCheck.cpp
   StringFindStartswithCheck.cpp
 
   LINK_LIBS

Added: 
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp?rev=340411&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
Wed Aug 22 06:58:25 2018
@@ -0,0 +1,131 @@
+//===--- FasterStrsplitDelimiterCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FasterStrsplitDelimiterCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+namespace {
+
+AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
+
+::internal::Matcher
+constructExprWithArg(llvm::StringRef ClassName,
+ const ::internal::Matcher &Arg) {
+  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
+ hasArgument(0, ignoringParenCasts(Arg)));
+
+  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
+}
+
+::internal::Matcher
+copyConstructExprWithArg(llvm::StringRef ClassName,
+ const ::internal::Matcher &Arg) {
+  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
+}
+
+llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
+  std::string Result;
+  {
+llvm::raw_string_ostream Stream(Result);
+Literal->outputString(Stream);
+  }
+
+  // Special case: If the string contains a single quote, we just need to 
return
+  // a character of the single quote. This is a special case because we need to
+  // escape it in the character literal.
+  if (Result == R"("'")"

[clang-tools-extra] r340412 - [clang-tidy] Add Abseil prefix to documentation

2018-08-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Aug 22 07:03:30 2018
New Revision: 340412

URL: http://llvm.org/viewvc/llvm-project?rev=340412&view=rev
Log:
[clang-tidy] Add Abseil prefix to documentation

Summary: Adds the Abseil prefix to the list of prefixes in the documentation

Patch by Deanna Garcia!

Reviewers: aaron.ballman, hokein

Reviewed By: hokein

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=340412&r1=340411&r2=340412&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Wed Aug 22 07:03:30 2018
@@ -55,6 +55,7 @@ There are currently the following groups
 == 
=
 Name prefixDescription
 == 
=
+``abseil-``Checks related to Abseil library.
 ``android-``   Checks related to Android.
 ``boost-`` Checks related to Boost library.
 ``bugprone-``  Checks that target bugprone code constructs.


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


r315286 - Fix small nits in clang-refactor doc.

2017-10-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct 10 02:00:56 2017
New Revision: 315286

URL: http://llvm.org/viewvc/llvm-project?rev=315286&view=rev
Log:
Fix small nits in clang-refactor doc.

Modified:
cfe/trunk/docs/RefactoringEngine.rst

Modified: cfe/trunk/docs/RefactoringEngine.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/RefactoringEngine.rst?rev=315286&r1=315285&r2=315286&view=diff
==
--- cfe/trunk/docs/RefactoringEngine.rst (original)
+++ cfe/trunk/docs/RefactoringEngine.rst Tue Oct 10 02:00:56 2017
@@ -41,7 +41,7 @@ outline of a ``local-rename`` action:
   public:
 StringRef getCommand() const override { return "local-rename"; }
 
-   StringRef getDescription() const override {
+StringRef getDescription() const override {
   return "Finds and renames symbols in code with no indexer support";
 }
 
@@ -143,7 +143,7 @@ list of action rules using the following
   Rules.push_back(
 createRefactoringActionRule(
   SourceRangeSelectionRequirement())
-  )
+  );
 
 The ``createRefactoringActionRule`` function takes in a list of refactoring
 action rule requirement values. These values describe the initiation


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


r315290 - [clang-refactor] Fix clang-tidy misc-move-const-arg warning.

2017-10-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct 10 02:48:38 2017
New Revision: 315290

URL: http://llvm.org/viewvc/llvm-project?rev=315290&view=rev
Log:
[clang-refactor] Fix clang-tidy misc-move-const-arg warning.

NFC

Modified:
cfe/trunk/tools/clang-refactor/ClangRefactor.cpp

Modified: cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-refactor/ClangRefactor.cpp?rev=315290&r1=315289&r2=315290&view=diff
==
--- cfe/trunk/tools/clang-refactor/ClangRefactor.cpp (original)
+++ cfe/trunk/tools/clang-refactor/ClangRefactor.cpp Tue Oct 10 02:48:38 2017
@@ -226,12 +226,12 @@ public:
   ActionWrapper(TUCallbackType Callback) : Callback(Callback) {}
 
   std::unique_ptr newASTConsumer() {
-return llvm::make_unique(std::move(Callback));
+return llvm::make_unique(Callback);
   }
 };
 
 ClangTool Tool(DB, Sources);
-ActionWrapper ToolAction(std::move(Callback));
+ActionWrapper ToolAction(Callback);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&ToolAction);
 return Tool.run(Factory.get());


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


r315452 - [clang-rename] Don't add prefix qualifiers to the declaration and definition of the renamed symbol.

2017-10-11 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 11 04:15:48 2017
New Revision: 315452

URL: http://llvm.org/viewvc/llvm-project?rev=315452&view=rev
Log:
[clang-rename] Don't add prefix qualifiers to the declaration and definition of 
the renamed symbol.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits, arphaman

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

Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/RenameClassTest.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=315452&r1=315451&r2=315452&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Wed Oct 11 
04:15:48 2017
@@ -160,13 +160,14 @@ public:
 const Decl *Context;
 // The nested name being replaced (can be nullptr).
 const NestedNameSpecifier *Specifier;
+// Determine whether the prefix qualifiers of the NewName should be 
ignored.
+// Normally, we set it to true for the symbol declaration and definition to
+// avoid adding prefix qualifiers.
+// For example, if it is true and NewName is "a::b::foo", then the symbol
+// occurrence which the RenameInfo points to will be renamed to "foo".
+bool IgnorePrefixQualifers;
   };
 
-  // FIXME: Currently, prefix qualifiers will be added to the renamed symbol
-  // definition (e.g. "class Foo {};" => "class b::Bar {};" when renaming
-  // "a::Foo" to "b::Bar").
-  // For renaming declarations/definitions, prefix qualifiers should be 
filtered
-  // out.
   bool VisitNamedDecl(const NamedDecl *Decl) {
 // UsingDecl has been handled in other place.
 if (llvm::isa(Decl))
@@ -180,8 +181,12 @@ public:
   return true;
 
 if (isInUSRSet(Decl)) {
-  RenameInfo Info = {Decl->getLocation(), Decl->getLocation(), nullptr,
- nullptr, nullptr};
+  RenameInfo Info = {Decl->getLocation(),
+ Decl->getLocation(),
+ /*FromDecl=*/nullptr,
+ /*Context=*/nullptr,
+ /*Specifier=*/nullptr,
+ /*IgnorePrefixQualifers=*/true};
   RenameInfos.push_back(Info);
 }
 return true;
@@ -191,8 +196,11 @@ public:
 const NamedDecl *Decl = Expr->getFoundDecl();
 if (isInUSRSet(Decl)) {
   RenameInfo Info = {Expr->getSourceRange().getBegin(),
- Expr->getSourceRange().getEnd(), Decl,
- getClosestAncestorDecl(*Expr), Expr->getQualifier()};
+ Expr->getSourceRange().getEnd(),
+ Decl,
+ getClosestAncestorDecl(*Expr),
+ Expr->getQualifier(),
+ /*IgnorePrefixQualifers=*/false};
   RenameInfos.push_back(Info);
 }
 
@@ -220,8 +228,10 @@ public:
   if (isInUSRSet(TargetDecl)) {
 RenameInfo Info = {NestedLoc.getBeginLoc(),
EndLocationForType(NestedLoc.getTypeLoc()),
-   TargetDecl, getClosestAncestorDecl(NestedLoc),
-   NestedLoc.getNestedNameSpecifier()->getPrefix()};
+   TargetDecl,
+   getClosestAncestorDecl(NestedLoc),
+   NestedLoc.getNestedNameSpecifier()->getPrefix(),
+   /*IgnorePrefixQualifers=*/false};
 RenameInfos.push_back(Info);
   }
 }
@@ -265,9 +275,12 @@ public:
 if (!ParentTypeLoc.isNull() &&
 isInUSRSet(getSupportedDeclFromTypeLoc(ParentTypeLoc)))
   return true;
-RenameInfo Info = {StartLocationForType(Loc), EndLocationForType(Loc),
-   TargetDecl, getClosestAncestorDecl(Loc),
-   GetNestedNameForType(Loc)};
+RenameInfo Info = {StartLocationForType(Loc),
+   EndLocationForType(Loc),
+   TargetDecl,
+   getClosestAncestorDecl(Loc),
+   GetNestedNameForType(Loc),
+   /*IgnorePrefixQualifers=*/false};
 RenameInfos.push_back(Info);
 return true;
   }
@@ -293,11 +306,13 @@ public:
 llvm::isa(ParentTypeLoc.getType()))
   TargetLoc = ParentTypeLoc;
 RenameInfo Info = {
-StartLocationForType(TargetLoc), EndLocationForType(TargetLoc),
+StartLocationForType(TargetLoc),
+EndLocationForType(TargetLoc),
 TemplateSpecType->getTemplateName().getAsTemplateDecl(),
 getClosestAncestorDecl(
 ast_type_traits::DynTypedNode::create(TargetLoc)),
-GetNestedNameForTy

r315459 - [clang-rename] Add more unittest.

2017-10-11 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 11 07:00:42 2017
New Revision: 315459

URL: http://llvm.org/viewvc/llvm-project?rev=315459&view=rev
Log:
[clang-rename] Add more unittest.

Modified:
cfe/trunk/unittests/Rename/RenameClassTest.cpp

Modified: cfe/trunk/unittests/Rename/RenameClassTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameClassTest.cpp?rev=315459&r1=315458&r2=315459&view=diff
==
--- cfe/trunk/unittests/Rename/RenameClassTest.cpp (original)
+++ cfe/trunk/unittests/Rename/RenameClassTest.cpp Wed Oct 11 07:00:42 2017
@@ -674,6 +674,124 @@ TEST_F(ClangRenameTest, ReferencesInLamb
   CompareSnippets(Expected, After);
 }
 
+TEST_F(ClangRenameTest, DontChangeIfSameName) {
+  std::string Before = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(foo::Old * x) {
+foo::Old::foo() ;
+  }
+  using foo::Old;)";
+  std::string Expected = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(foo::Old * x) {
+foo::Old::foo() ;
+  }
+  using foo::Old;)";
+  std::string After = runClangRenameOnCode(Before, "foo::Old", "foo::Old");
+  CompareSnippets(Expected, After);
+}
+
+TEST_F(ClangRenameTest, ChangeIfNewNameWithLeadingDotDot) {
+  std::string Before = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(foo::Old * x) {
+foo::Old::foo() ;
+  }
+  using foo::Old;)";
+  std::string Expected = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(::foo::Old * x) {
+::foo::Old::foo() ;
+  }
+  using ::foo::Old;)";
+  std::string After = runClangRenameOnCode(Before, "foo::Old", "::foo::Old");
+  CompareSnippets(Expected, After);
+}
+
+TEST_F(ClangRenameTest, ChangeIfSameNameWithLeadingDotDot) {
+  std::string Before = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(foo::Old * x) {
+foo::Old::foo() ;
+  }
+  using foo::Old;)";
+  std::string Expected = R"(
+  namespace foo {
+  class Old {
+   public:
+ static void foo() {}
+  };
+  }
+
+  void f(::foo::Old * x) {
+::foo::Old::foo() ;
+  }
+  using ::foo::Old;)";
+  std::string After = runClangRenameOnCode(Before, "::foo::Old", "::foo::Old");
+  CompareSnippets(Expected, After);
+}
+
+TEST_F(RenameClassTest, UsingAlias) {
+  std::string Before = R"(
+  namespace a { struct A {}; }
+
+  namespace foo {
+  using Alias = a::A;
+  Alias a;
+  })";
+  std::string Expected = R"(
+  namespace a { struct B {}; }
+
+  namespace foo {
+  using Alias = b::B;
+  Alias a;
+  })";
+  std::string After = runClangRenameOnCode(Before, "a::A", "b::B");
+  CompareSnippets(Expected, After);
+}
+
+TEST_F(ClangRenameTest, NestedTemplates) {
+  std::string Before = R"(
+  namespace a { template  struct A {}; }
+  a::A> foo;)";
+  std::string Expected = R"(
+  namespace a { template  struct B {}; }
+  b::B> foo;)";
+  std::string After = runClangRenameOnCode(Before, "a::A", "b::B");
+  CompareSnippets(Expected, After);
+}
+
+
 } // anonymous namespace
 } // namespace test
 } // namespace clang_rename


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


r315688 - Remove an unused variable.

2017-10-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 13 08:34:03 2017
New Revision: 315688

URL: http://llvm.org/viewvc/llvm-project?rev=315688&view=rev
Log:
Remove an unused variable.

Fix -Wunused-but-set-variable warning.

Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=315688&r1=315687&r2=315688&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Oct 13 08:34:03 2017
@@ -7079,7 +7079,6 @@ static void processTypeAttrs(TypeProcess
   // type, but others can be present in the type specifiers even though they
   // apply to the decl.  Here we apply type attributes and ignore the rest.
 
-  bool hasOpenCLAddressSpace = false;
   while (attrs) {
 AttributeList &attr = *attrs;
 attrs = attr.getNext(); // reset to the next here due to early loop 
continue
@@ -7142,7 +7141,6 @@ static void processTypeAttrs(TypeProcess
 case AttributeList::AT_AddressSpace:
   HandleAddressSpaceTypeAttribute(type, attr, state.getSema());
   attr.setUsedAsTypeAttr();
-  hasOpenCLAddressSpace = true;
   break;
 OBJC_POINTER_TYPE_ATTRS_CASELIST:
   if (!handleObjCPointerTypeAttr(state, attr, type))


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


r315689 - Fix an unused-variable warning.

2017-10-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 13 08:37:53 2017
New Revision: 315689

URL: http://llvm.org/viewvc/llvm-project?rev=315689&view=rev
Log:
Fix an unused-variable warning.

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

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=315689&r1=315688&r2=315689&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Oct 13 08:37:53 2017
@@ -1516,7 +1516,7 @@ namespace {
   llvm::Value *LoadThisForDtorDelete(CodeGenFunction &CGF,
  const CXXDestructorDecl *DD) {
 if (Expr *ThisArg = DD->getOperatorDeleteThisArg())
-  return CGF.EmitScalarExpr(DD->getOperatorDeleteThisArg());
+  return CGF.EmitScalarExpr(ThisArg);
 return CGF.LoadCXXThis();
   }
 


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


r315898 - [clang-rename] Add function unit tests.

2017-10-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 16 03:37:42 2017
New Revision: 315898

URL: http://llvm.org/viewvc/llvm-project?rev=315898&view=rev
Log:
[clang-rename] Add function unit tests.

Summary:
Also contain a fix:

* Fix a false positive of renaming a using shadow function declaration.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt
cfe/trunk/unittests/Rename/RenameClassTest.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=315898&r1=315897&r2=315898&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Mon Oct 16 
03:37:42 2017
@@ -194,6 +194,12 @@ public:
 
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
 const NamedDecl *Decl = Expr->getFoundDecl();
+// Get the underlying declaration of the shadow declaration introduced by a
+// using declaration.
+if (auto* UsingShadow = llvm::dyn_cast(Decl)) {
+  Decl = UsingShadow->getTargetDecl();
+}
+
 if (isInUSRSet(Decl)) {
   RenameInfo Info = {Expr->getSourceRange().getBegin(),
  Expr->getSourceRange().getEnd(),
@@ -452,6 +458,23 @@ createRenameAtomicChanges(llvm::ArrayRef
   RenameInfo.FromDecl,
   NewName.startswith("::") ? NewName.str()
: ("::" + NewName).str());
+} else {
+  // This fixes the case where type `T` is a parameter inside a 
function
+  // type (e.g. `std::function`) and the DeclContext of `T`
+  // becomes the translation unit. As a workaround, we simply use
+  // fully-qualified name here for all references whose `DeclContext` 
is
+  // the translation unit and ignore the possible existence of
+  // using-decls (in the global scope) that can shorten the replaced
+  // name.
+  llvm::StringRef ActualName = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  SourceRange(RenameInfo.Begin, RenameInfo.End)),
+  SM, TranslationUnitDecl->getASTContext().getLangOpts());
+  // Add the leading "::" back if the name written in the code contains
+  // it.
+  if (ActualName.startswith("::") && !NewName.startswith("::")) {
+ReplacedName = "::" + NewName.str();
+  }
 }
   }
   // If the NewName contains leading "::", add it back.

Modified: cfe/trunk/unittests/Rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/CMakeLists.txt?rev=315898&r1=315897&r2=315898&view=diff
==
--- cfe/trunk/unittests/Rename/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Rename/CMakeLists.txt Mon Oct 16 03:37:42 2017
@@ -7,6 +7,7 @@ include_directories(${CLANG_SOURCE_DIR})
 
 add_clang_unittest(ClangRenameTests
   RenameClassTest.cpp
+  RenameFunctionTest.cpp
   )
 
 target_link_libraries(ClangRenameTests

Modified: cfe/trunk/unittests/Rename/RenameClassTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameClassTest.cpp?rev=315898&r1=315897&r2=315898&view=diff
==
--- cfe/trunk/unittests/Rename/RenameClassTest.cpp (original)
+++ cfe/trunk/unittests/Rename/RenameClassTest.cpp Mon Oct 16 03:37:42 2017
@@ -51,6 +51,7 @@ INSTANTIATE_TEST_CASE_P(
 testing::ValuesIn(std::vector({
 // basic classes
 {"a::Foo f;", "b::Bar f;", "", ""},
+{"::a::Foo f;", "::b::Bar f;", "", ""},
 {"void f(a::Foo f) {}", "void f(b::Bar f) {}", "", ""},
 {"void f(a::Foo *f) {}", "void f(b::Bar *f) {}", "", ""},
 {"a::Foo f() { return a::Foo(); }", "b::Bar f() { return b::Bar(); }",

Added: cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameFunctionTest.cpp?rev=315898&view=auto
==
--- cfe/trunk/unittests/Rename/RenameFunctionTest.cpp (added)
+++ cfe/trunk/unittests/Rename/RenameFunctionTest.cpp Mon Oct 16 03:37:42 2017
@@ -0,0 +1,555 @@
+//===-- RenameFunctionTest.cpp - unit tests for renaming functions 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===

r315999 - [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct 17 07:14:41 2017
New Revision: 315999

URL: http://llvm.org/viewvc/llvm-project?rev=315999&view=rev
Log:
[clang-rename] Rename enum.

Summary:
* Add unit tests for renaming enum.
* Support unscoped enum constants in expressions.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/Rename/RenameEnumTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=315999&r1=315998&r2=315999&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Tue Oct 17 
07:14:41 2017
@@ -196,13 +196,46 @@ public:
 const NamedDecl *Decl = Expr->getFoundDecl();
 // Get the underlying declaration of the shadow declaration introduced by a
 // using declaration.
-if (auto* UsingShadow = llvm::dyn_cast(Decl)) {
+if (auto *UsingShadow = llvm::dyn_cast(Decl)) {
   Decl = UsingShadow->getTargetDecl();
 }
 
+auto BeginLoc = Expr->getLocStart();
+auto EndLoc = Expr->getLocEnd();
+// In case of renaming an enum declaration, we have to explicitly handle
+// unscoped enum constants referenced in expressions (e.g.
+// "auto r = ns1::ns2::Green" where Green is an enum constant of an 
unscoped
+// enum decl "ns1::ns2::Color") as these enum constants cannot be caught by
+// TypeLoc.
+if (const auto *T = llvm::dyn_cast(Decl)) {
+  // FIXME: Handle the enum constant without prefix qualifiers (`a = 
Green`)
+  // when renaming an unscoped enum declaration with a new namespace.
+  if (!Expr->hasQualifier())
+return true;
+
+  if (const auto *ED =
+  llvm::dyn_cast_or_null(getClosestAncestorDecl(*T))) {
+if (ED->isScoped())
+  return true;
+Decl = ED;
+  }
+  // The current fix would qualify "ns1::ns2::Green" as
+  // "ns1::ns2::Color::Green".
+  //
+  // Get the EndLoc of the replacement by moving 1 character backward (
+  // to exclude the last '::').
+  //
+  //ns1::ns2::Green;
+  //^  ^^
+  // BeginLoc  |EndLoc of the qualifier
+  //   new EndLoc
+  EndLoc = Expr->getQualifierLoc().getEndLoc().getLocWithOffset(-1);
+  assert(EndLoc.isValid() &&
+ "The enum constant should have prefix qualifers.");
+}
 if (isInUSRSet(Decl)) {
-  RenameInfo Info = {Expr->getSourceRange().getBegin(),
- Expr->getSourceRange().getEnd(),
+  RenameInfo Info = {BeginLoc,
+ EndLoc,
  Decl,
  getClosestAncestorDecl(*Expr),
  Expr->getQualifier(),
@@ -364,10 +397,13 @@ private:
   // Get the supported declaration from a given typeLoc. If the declaration 
type
   // is not supported, returns nullptr.
   //
-  // FIXME: support more types, e.g. enum, type alias.
+  // FIXME: support more types, e.g. type alias.
   const NamedDecl *getSupportedDeclFromTypeLoc(TypeLoc Loc) {
 if (const auto *RD = Loc.getType()->getAsCXXRecordDecl())
   return RD;
+if (const auto *ED =
+llvm::dyn_cast_or_null(Loc.getType()->getAsTagDecl()))
+  return ED;
 return nullptr;
   }
 

Modified: cfe/trunk/unittests/Rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/CMakeLists.txt?rev=315999&r1=315998&r2=315999&view=diff
==
--- cfe/trunk/unittests/Rename/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Rename/CMakeLists.txt Tue Oct 17 07:14:41 2017
@@ -7,6 +7,7 @@ include_directories(${CLANG_SOURCE_DIR})
 
 add_clang_unittest(ClangRenameTests
   RenameClassTest.cpp
+  RenameEnumTest.cpp
   RenameFunctionTest.cpp
   )
 

Added: cfe/trunk/unittests/Rename/RenameEnumTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameEnumTest.cpp?rev=315999&view=auto
==
--- cfe/trunk/unittests/Rename/RenameEnumTest.cpp (added)
+++ cfe/trunk/unittests/Rename/RenameEnumTest.cpp Tue Oct 17 07:14:41 2017
@@ -0,0 +1,189 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+

[clang-tools-extra] r316066 - New -assume-filename=param to check_clang_tidy.py (like clang-format)

2017-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 18 00:48:40 2017
New Revision: 316066

URL: http://llvm.org/viewvc/llvm-project?rev=316066&view=rev
Log:
New -assume-filename=param to check_clang_tidy.py (like clang-format)

Summary:
Currently, check_clang_tidy.py includes logic to select default
clang flags based on the extension of the source filename passed
as the first argument.

Since the source filename might be a temporary or test file with an
arbitrary extension unrelated to the file type, this adds the ability
to override the logic the same way `clang-format`'s -assume-filename=
parameter does.

I included a test with a nonstandard file extension. I confirmed
when I modified the warning message that the new test failed,
and that it passed again when I restored the warning message.

Ran tests with:

% cmake -G Ninja /path/to/llvm
% ninja check-clang-tools

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: alexfh

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

Added:
clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test
Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=316066&r1=316065&r2=316066&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Wed Oct 18 
00:48:40 2017
@@ -17,6 +17,7 @@ This script runs clang-tidy in fix mode
 
 Usage:
   check_clang_tidy.py [-resource-dir ] \
+[-assume-filename ] \
\
 -- [optional clang-tidy arguments]
 
@@ -38,6 +39,7 @@ def write_file(file_name, text):
 def main():
   parser = argparse.ArgumentParser()
   parser.add_argument('-resource-dir')
+  parser.add_argument('-assume-filename')
   parser.add_argument('input_file_name')
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
@@ -45,14 +47,17 @@ def main():
   args, extra_args = parser.parse_known_args()
 
   resource_dir = args.resource_dir
+  assume_file_name = args.assume_filename
   input_file_name = args.input_file_name
   check_name = args.check_name
   temp_file_name = args.temp_file_name
 
+  file_name_with_extension = assume_file_name or input_file_name
+
   extension = '.cpp'
-  if (input_file_name.endswith('.c')):
+  if (file_name_with_extension.endswith('.c')):
 extension = '.c'
-  if (input_file_name.endswith('.hpp')):
+  if (file_name_with_extension.endswith('.hpp')):
 extension = '.hpp'
   temp_file_name = temp_file_name + extension
 

Added: clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test?rev=316066&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test 
(added)
+++ clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test Wed 
Oct 18 00:48:40 2017
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -assume-filename=const-cast.cpp %s 
cppcoreguidelines-pro-type-const-cast %t
+
+const int *i;
+int *j;
+void f() { j = const_cast(i); }
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use const_cast 
[cppcoreguidelines-pro-type-const-cast]


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


r316074 - [clang-rename] Rename alias.

2017-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 18 05:10:11 2017
New Revision: 316074

URL: http://llvm.org/viewvc/llvm-project?rev=316074&view=rev
Log:
[clang-rename] Rename alias.

Summary:
* Support rename alias.
* Add unittests for renaming alias.
* Don't generate fixes for the SourceLocations that are invalid or in temporary
  buffer, otherwise crash would be happened when generating AtomicChanges.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/Rename/RenameAliasTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=316074&r1=316073&r2=316074&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Wed Oct 18 
05:10:11 2017
@@ -39,6 +39,17 @@ namespace tooling {
 
 namespace {
 
+// Returns true if the given Loc is valid for edit. We don't edit the
+// SourceLocations that are valid or in temporary buffer.
+bool IsValidEditLoc(const clang::SourceManager& SM, clang::SourceLocation Loc) 
{
+  if (Loc.isInvalid())
+return false;
+  const clang::FullSourceLoc FullLoc(Loc, SM);
+  std::pair FileIdAndOffset =
+  FullLoc.getSpellingLoc().getDecomposedLoc();
+  return SM.getFileEntryForID(FileIdAndOffset.first) != nullptr;
+}
+
 // \brief This visitor recursively searches for all instances of a USR in a
 // translation unit and stores them for later usage.
 class USRLocFindingASTVisitor
@@ -181,13 +192,22 @@ public:
   return true;
 
 if (isInUSRSet(Decl)) {
-  RenameInfo Info = {Decl->getLocation(),
- Decl->getLocation(),
- /*FromDecl=*/nullptr,
- /*Context=*/nullptr,
- /*Specifier=*/nullptr,
- /*IgnorePrefixQualifers=*/true};
-  RenameInfos.push_back(Info);
+  // For the case of renaming an alias template, we actually rename the
+  // underlying alias declaration of the template.
+  if (const auto* TAT = dyn_cast(Decl))
+Decl = TAT->getTemplatedDecl();
+
+  auto StartLoc = Decl->getLocation();
+  auto EndLoc = StartLoc;
+  if (IsValidEditLoc(Context.getSourceManager(), StartLoc)) {
+RenameInfo Info = {StartLoc,
+   EndLoc,
+   /*FromDecl=*/nullptr,
+   /*Context=*/nullptr,
+   /*Specifier=*/nullptr,
+   /*IgnorePrefixQualifers=*/true};
+RenameInfos.push_back(Info);
+  }
 }
 return true;
   }
@@ -200,7 +220,7 @@ public:
   Decl = UsingShadow->getTargetDecl();
 }
 
-auto BeginLoc = Expr->getLocStart();
+auto StartLoc = Expr->getLocStart();
 auto EndLoc = Expr->getLocEnd();
 // In case of renaming an enum declaration, we have to explicitly handle
 // unscoped enum constants referenced in expressions (e.g.
@@ -233,8 +253,9 @@ public:
   assert(EndLoc.isValid() &&
  "The enum constant should have prefix qualifers.");
 }
-if (isInUSRSet(Decl)) {
-  RenameInfo Info = {BeginLoc,
+if (isInUSRSet(Decl) &&
+IsValidEditLoc(Context.getSourceManager(), StartLoc)) {
+  RenameInfo Info = {StartLoc,
  EndLoc,
  Decl,
  getClosestAncestorDecl(*Expr),
@@ -259,8 +280,6 @@ public:
   bool VisitNestedNameSpecifierLocations(NestedNameSpecifierLoc NestedLoc) {
 if (!NestedLoc.getNestedNameSpecifier()->getAsType())
   return true;
-if (IsTypeAliasWhichWillBeRenamedElsewhere(NestedLoc.getTypeLoc()))
-  return true;
 
 if (const auto *TargetDecl =
 getSupportedDeclFromTypeLoc(NestedLoc.getTypeLoc())) {
@@ -278,9 +297,6 @@ public:
   }
 
   bool VisitTypeLoc(TypeLoc Loc) {
-if (IsTypeAliasWhichWillBeRenamedElsewhere(Loc))
-  return true;
-
 auto Parents = Context.getParents(Loc);
 TypeLoc ParentTypeLoc;
 if (!Parents.empty()) {
@@ -314,13 +330,18 @@ public:
 if (!ParentTypeLoc.isNull() &&
 isInUSRSet(getSupportedDeclFromTypeLoc(ParentTypeLoc)))
   return true;
-RenameInfo Info = {StartLocationForType(Loc),
-   EndLocationForType(Loc),
-   TargetDecl,
-   getClosestAncestorDecl(Loc),
-   GetNestedNameForType(Loc),
-   /*IgnorePrefixQualifers=*/false};
-RenameInfos.push_back(Info);
+
+auto StartLoc = StartLocationForType(Loc);
+auto EndLoc = En

[clang-tools-extra] r316090 - Support Objective-C/C++ source files in check_clang_tidy.py

2017-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 18 08:56:39 2017
New Revision: 316090

URL: http://llvm.org/viewvc/llvm-project?rev=316090&view=rev
Log:
Support Objective-C/C++ source files in check_clang_tidy.py

check_clang_tidy.py currently only handles C and C++ source files.

This extends the logic to also handle Objective-C (.m) and
Objective-C++ (.mm) files.

However, by default, clang compiles .m/.mm files using Objective-C 1.0
syntax. Objective-C 2.0 has been the default in Xcode for about 10
years, and Objective-C Automatic Reference Counting (ARC) for about 6
years, so this enables both by default.

(Clients which actually want to test clang-tidy checks for Objective-C
 1.0 or non-ARC files can pass custom flags to check_clang_tidy.py
 after --, which will disable the Objective-C 2.0 and ARC flags).

I did not add logic to handle running clang-tidy on Objective-C header
files alone; they also use the .h file extension, so we'd need to
look inside their contents.

I included a new test to confirm the new behavior.

Depends On D38963

Patch by Ben Hamilton!

Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=316090&r1=316089&r2=316090&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Wed Oct 18 
08:56:39 2017
@@ -26,6 +26,7 @@ Example:
 """
 
 import argparse
+import os
 import re
 import subprocess
 import sys
@@ -53,18 +54,19 @@ def main():
   temp_file_name = args.temp_file_name
 
   file_name_with_extension = assume_file_name or input_file_name
-
-  extension = '.cpp'
-  if (file_name_with_extension.endswith('.c')):
-extension = '.c'
-  if (file_name_with_extension.endswith('.hpp')):
-extension = '.hpp'
+  _, extension = os.path.splitext(file_name_with_extension)
+  if extension not in ['.c', '.hpp', '.m', '.mm']:
+extension = '.cpp'
   temp_file_name = temp_file_name + extension
 
   clang_tidy_extra_args = extra_args
   if len(clang_tidy_extra_args) == 0:
-clang_tidy_extra_args = ['--', '--std=c++11'] \
-if extension == '.cpp' or extension == '.hpp' else ['--']
+clang_tidy_extra_args = ['--']
+if extension in ['.cpp', '.hpp', '.mm']:
+  clang_tidy_extra_args.append('--std=c++11')
+if extension in ['.m', '.mm']:
+  clang_tidy_extra_args.extend(
+  ['-fobjc-abi-version=2', '-fobjc-arc'])
 
   # Tests should not rely on STL being available, and instead provide mock
   # implementations of relevant APIs.


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


r316152 - Fix a few nits in RenamingAction.

2017-10-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Oct 19 01:20:55 2017
New Revision: 316152

URL: http://llvm.org/viewvc/llvm-project?rev=316152&view=rev
Log:
Fix a few nits in RenamingAction.

* Add missing override keyword.
* avoid unnecessary copy of std::string.

Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp?rev=316152&r1=316151&r2=316152&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp Thu Oct 19 
01:20:55 2017
@@ -77,10 +77,10 @@ private:
 class RenameOccurrences final : public SourceChangeRefactoringRule {
 public:
   RenameOccurrences(const NamedDecl *ND, std::string NewName)
-  : Finder(ND), NewName(NewName) {}
+  : Finder(ND), NewName(std::move(NewName)) {}
 
   Expected
-  createSourceReplacements(RefactoringRuleContext &Context) {
+  createSourceReplacements(RefactoringRuleContext &Context) override {
 Expected Occurrences =
 Finder.findSymbolOccurrences(Context);
 if (!Occurrences)


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


r316212 - [clang-refactor] Add "-Inplace" option to the commandline tool.

2017-10-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 20 05:37:16 2017
New Revision: 316212

URL: http://llvm.org/viewvc/llvm-project?rev=316212&view=rev
Log:
[clang-refactor] Add "-Inplace" option to the commandline tool.

Summary:
Change clang-refactor default behavior to print the new code after refactoring
(instead of editing the source files), which would make it easier to use
and debug the refactoring action.

Reviewers: arphaman, ioeric

Reviewed By: arphaman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/test/Refactor/tool-apply-replacements.cpp
cfe/trunk/tools/clang-refactor/ClangRefactor.cpp

Modified: cfe/trunk/test/Refactor/tool-apply-replacements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Refactor/tool-apply-replacements.cpp?rev=316212&r1=316211&r2=316212&view=diff
==
--- cfe/trunk/test/Refactor/tool-apply-replacements.cpp (original)
+++ cfe/trunk/test/Refactor/tool-apply-replacements.cpp Fri Oct 20 05:37:16 2017
@@ -1,10 +1,8 @@
-// RUN: rm -f %t.cp.cpp
-// RUN: cp %s %t.cp.cpp
-// RUN: clang-refactor local-rename -selection=%t.cp.cpp:9:7 -new-name=test 
%t.cp.cpp --
-// RUN: grep -v CHECK %t.cp.cpp | FileCheck %t.cp.cpp
-// RUN: cp %s %t.cp.cpp
-// RUN: clang-refactor local-rename -selection=%t.cp.cpp:9:7-9:15 
-new-name=test %t.cp.cpp --
-// RUN: grep -v CHECK %t.cp.cpp | FileCheck %t.cp.cpp
+// RUN: sed -e 's#//.*$##' %s > %t.cpp
+// RUN: clang-refactor local-rename -selection=%t.cpp:7:7 -new-name=test 
%t.cpp -- | FileCheck %s
+// RUN: clang-refactor local-rename -selection=%t.cpp:7:7-7:15 -new-name=test 
%t.cpp -- | FileCheck %s
+// RUN: clang-refactor local-rename -i -selection=%t.cpp:7:7 -new-name=test 
%t.cpp --
+// RUN: FileCheck -input-file=%t.cpp %s
 
 class RenameMe {
 // CHECK: class test {

Modified: cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-refactor/ClangRefactor.cpp?rev=316212&r1=316211&r2=316212&view=diff
==
--- cfe/trunk/tools/clang-refactor/ClangRefactor.cpp (original)
+++ cfe/trunk/tools/clang-refactor/ClangRefactor.cpp Fri Oct 20 05:37:16 2017
@@ -40,6 +40,11 @@ static cl::OptionCategory CommonRefactor
 static cl::opt Verbose("v", cl::desc("Use verbose output"),
  cl::cat(cl::GeneralCategory),
  cl::sub(*cl::AllSubCommands));
+
+static cl::opt Inplace("i", cl::desc("Inplace edit s"),
+ cl::cat(cl::GeneralCategory),
+ cl::sub(*cl::AllSubCommands));
+
 } // end namespace opts
 
 namespace {
@@ -436,13 +441,18 @@ public:
 return true;
   }
 
-  std::error_code EC;
-  llvm::raw_fd_ostream OS(File, EC, llvm::sys::fs::F_Text);
-  if (EC) {
-llvm::errs() << EC.message() << "\n";
-return true;
+  if (opts::Inplace) {
+std::error_code EC;
+llvm::raw_fd_ostream OS(File, EC, llvm::sys::fs::F_Text);
+if (EC) {
+  llvm::errs() << EC.message() << "\n";
+  return true;
+}
+OS << *Result;
+continue;
   }
-  OS << *Result;
+
+  llvm::outs() << *Result;
 }
 return false;
   }


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


[clang-tools-extra] r316221 - [clang-tidy] Add missing test files in r316090.

2017-10-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 20 10:54:53 2017
New Revision: 316221

URL: http://llvm.org/viewvc/llvm-project?rev=316221&view=rev
Log:
[clang-tidy] Add missing test files in r316090.

Added:
clang-tools-extra/trunk/test/clang-tidy/objc-arc-and-properties.m
clang-tools-extra/trunk/test/clang-tidy/objc-no-arc-or-properties.m

Added: clang-tools-extra/trunk/test/clang-tidy/objc-arc-and-properties.m
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/objc-arc-and-properties.m?rev=316221&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/objc-arc-and-properties.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/objc-arc-and-properties.m Fri Oct 
20 10:54:53 2017
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s misc-suspicious-semicolon %t
+
+// This test checks if Objective-C 2.0 (@properties) and
+// Automatic Reference Counting (ARC) are enabled for .m files
+// checked via check_clang_tidy.py.
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+@interface Foo
+@property (nonatomic, assign) int shouldDoStuff;
+- (void)nop;
+@end
+
+void fail(Foo *f)
+{
+  if(f.shouldDoStuff); [f nop];
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: potentially unintended 
semicolon [misc-suspicious-semicolon]
+  // CHECK-FIXES: if(f.shouldDoStuff) [f nop];
+}

Added: clang-tools-extra/trunk/test/clang-tidy/objc-no-arc-or-properties.m
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/objc-no-arc-or-properties.m?rev=316221&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/objc-no-arc-or-properties.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/objc-no-arc-or-properties.m Fri Oct 
20 10:54:53 2017
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s misc-suspicious-semicolon %t -- -- -fno-objc-arc 
-fobjc-abi-version=1
+
+// This test ensures check_clang_tidy.py allows disabling Objective-C ARC and
+// Objective-C 2.0 via passing arguments after -- on the command line.
+//
+// (We could include a test which doesn't pass any arguments after --
+// to check if ARC and ObjC 2.0 are disabled by default, but that test
+// could change behavior based on the default Objective-C runtime for
+// the platform, which would make this test flaky.)
+
+#if __has_feature(objc_arc)
+#error Objective-C ARC unexpectedly enabled even with -fno-objc-arc
+#endif
+
+#ifdef __OBJC2__
+#error Objective-C 2.0 unexpectedly enabled even with -fobjc-abi-version=1
+#endif
+
+@interface Foo
+- (int)shouldDoStuff;
+- (void)nop;
+@end
+
+void fail(Foo *f)
+{
+  if([f shouldDoStuff]); [f nop];
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: potentially unintended 
semicolon [misc-suspicious-semicolon]
+  // CHECK-FIXES: if([f shouldDoStuff]) [f nop];
+}


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


r316314 - [rename] Don't overwrite the template argument when renaming a template function.

2017-10-23 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 23 01:58:50 2017
New Revision: 316314

URL: http://llvm.org/viewvc/llvm-project?rev=316314&view=rev
Log:
[rename] Don't overwrite the template argument when renaming a template 
function.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: cierpuchaw, cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/RenameFunctionTest.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=316314&r1=316313&r2=316314&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Mon Oct 23 
01:58:50 2017
@@ -221,7 +221,12 @@ public:
 }
 
 auto StartLoc = Expr->getLocStart();
-auto EndLoc = Expr->getLocEnd();
+// For template function call expressions like `foo()`, we want to
+// restrict the end of location to just before the `<` character.
+SourceLocation EndLoc = Expr->hasExplicitTemplateArgs()
+? Expr->getLAngleLoc().getLocWithOffset(-1)
+: Expr->getLocEnd();
+
 // In case of renaming an enum declaration, we have to explicitly handle
 // unscoped enum constants referenced in expressions (e.g.
 // "auto r = ns1::ns2::Green" where Green is an enum constant of an 
unscoped

Modified: cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameFunctionTest.cpp?rev=316314&r1=316313&r2=316314&view=diff
==
--- cfe/trunk/unittests/Rename/RenameFunctionTest.cpp (original)
+++ cfe/trunk/unittests/Rename/RenameFunctionTest.cpp Mon Oct 23 01:58:50 2017
@@ -220,6 +220,25 @@ TEST_F(RenameFunctionTest, RenameFunctio
   CompareSnippets(Expected, After);
 }
 
+TEST_F(RenameFunctionTest, RenameTemplateFunctions) {
+  std::string Before = R"(
+  namespace na {
+  template T X();
+  }
+  namespace na { void f() { X(); } }
+  namespace nb { void g() { na::X  (); } }
+  )";
+  std::string Expected = R"(
+  namespace na {
+  template T Y();
+  }
+  namespace na { void f() { nb::Y(); } }
+  namespace nb { void g() { Y(); } }
+  )";
+  std::string After = runClangRenameOnCode(Before, "na::X", "nb::Y");
+  CompareSnippets(Expected, After);
+}
+
 TEST_F(RenameFunctionTest, RenameOutOfLineFunctionDecls) {
   std::string Before = R"(
   namespace na {


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


r316561 - [clang-rename] Fix and enable the failing TemplatedClassFunction test.

2017-10-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 25 01:25:25 2017
New Revision: 316561

URL: http://llvm.org/viewvc/llvm-project?rev=316561&view=rev
Log:
[clang-rename] Fix and enable the failing TemplatedClassFunction test.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp?rev=316561&r1=316560&r2=316561&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp Wed Oct 25 
01:25:25 2017
@@ -73,6 +73,7 @@ public:
 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
   USRSet.insert(getUSRForDecl(OverriddenMethod));
   }
+  addUSRsOfInstantiatedMethods(MethodDecl);
 } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
   handleCXXRecordDecl(RecordDecl);
 } else if (const auto *TemplateDecl =
@@ -84,9 +85,13 @@ public:
 return std::vector(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
 if (MethodDecl->isVirtual())
   OverriddenMethods.push_back(MethodDecl);
+if (MethodDecl->getInstantiatedFromMemberFunction())
+  InstantiatedMethods.push_back(MethodDecl);
 return true;
   }
 
@@ -137,6 +142,20 @@ private:
   addUSRsOfOverridenFunctions(OverriddenMethod);
   }
 
+  void addUSRsOfInstantiatedMethods(const CXXMethodDecl *MethodDecl) {
+// For renaming a class template method, all references of the instantiated
+// member methods should be renamed too, so add USRs of the instantiated
+// methods to the USR set.
+USRSet.insert(getUSRForDecl(MethodDecl));
+if (const auto *FT = MethodDecl->getInstantiatedFromMemberFunction())
+  USRSet.insert(getUSRForDecl(FT));
+for (const auto *Method : InstantiatedMethods) {
+  if (USRSet.find(getUSRForDecl(
+  Method->getInstantiatedFromMemberFunction())) != USRSet.end())
+USRSet.insert(getUSRForDecl(Method));
+}
+  }
+
   bool checkIfOverriddenFunctionAscends(const CXXMethodDecl *MethodDecl) {
 for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) {
   if (USRSet.find(getUSRForDecl(OverriddenMethod)) != USRSet.end())
@@ -150,6 +169,7 @@ private:
   ASTContext &Context;
   std::set USRSet;
   std::vector OverriddenMethods;
+  std::vector InstantiatedMethods;
   std::vector PartialSpecs;
 };
 } // namespace

Modified: cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp?rev=316561&r1=316560&r2=316561&view=diff
==
--- cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp (original)
+++ cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp Wed Oct 25 01:25:25 
2017
@@ -6,17 +6,22 @@ public:
 
 int main(int argc, char **argv) {
   A a;
-  a.foo();   /* Test 2 */ // CHECK: a.bar()   /* Test 2 */
+  A b;
+  A c;
+  a.foo();   /* Test 2 */ // CHECK: a.bar();   /* Test 2 */
+  b.foo();   /* Test 3 */ // CHECK: b.bar();   /* Test 3 */
+  c.foo();   /* Test 4 */ // CHECK: c.bar();   /* Test 4 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' 


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


r316571 - [rename] support renaming class member.

2017-10-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 25 04:54:45 2017
New Revision: 316571

URL: http://llvm.org/viewvc/llvm-project?rev=316571&view=rev
Log:
[rename] support renaming class member.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits, mgorny

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

Added:
cfe/trunk/unittests/Rename/RenameMemberTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=316571&r1=316570&r2=316571&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Wed Oct 25 
04:54:45 2017
@@ -212,6 +212,41 @@ public:
 return true;
   }
 
+  bool VisitMemberExpr(const MemberExpr *Expr) {
+const NamedDecl *Decl = Expr->getFoundDecl();
+auto StartLoc = Expr->getMemberLoc();
+auto EndLoc = Expr->getMemberLoc();
+if (isInUSRSet(Decl)) {
+  RenameInfos.push_back({StartLoc, EndLoc,
+/*FromDecl=*/nullptr,
+/*Context=*/nullptr,
+/*Specifier=*/nullptr,
+/*IgnorePrefixQualifiers=*/true});
+}
+return true;
+  }
+
+  bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) {
+// Fix the constructor initializer when renaming class members.
+for (const auto *Initializer : CD->inits()) {
+  // Ignore implicit initializers.
+  if (!Initializer->isWritten())
+continue;
+
+  if (const FieldDecl *FD = Initializer->getMember()) {
+if (isInUSRSet(FD)) {
+  auto Loc = Initializer->getSourceLocation();
+  RenameInfos.push_back({Loc, Loc,
+ /*FromDecl=*/nullptr,
+ /*Context=*/nullptr,
+ /*Specifier=*/nullptr,
+ /*IgnorePrefixQualifiers=*/true});
+}
+  }
+}
+return true;
+  }
+
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
 const NamedDecl *Decl = Expr->getFoundDecl();
 // Get the underlying declaration of the shadow declaration introduced by a
@@ -227,6 +262,20 @@ public:
 ? Expr->getLAngleLoc().getLocWithOffset(-1)
 : Expr->getLocEnd();
 
+if (const auto *MD = llvm::dyn_cast(Decl)) {
+  if (isInUSRSet(MD)) {
+// Handle renaming static template class methods, we only rename the
+// name without prefix qualifiers and restrict the source range to the
+// name.
+RenameInfos.push_back({EndLoc, EndLoc,
+   /*FromDecl=*/nullptr,
+   /*Context=*/nullptr,
+   /*Specifier=*/nullptr,
+   /*IgnorePrefixQualifiers=*/true});
+return true;
+  }
+}
+
 // In case of renaming an enum declaration, we have to explicitly handle
 // unscoped enum constants referenced in expressions (e.g.
 // "auto r = ns1::ns2::Green" where Green is an enum constant of an 
unscoped

Modified: cfe/trunk/unittests/Rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/CMakeLists.txt?rev=316571&r1=316570&r2=316571&view=diff
==
--- cfe/trunk/unittests/Rename/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Rename/CMakeLists.txt Wed Oct 25 04:54:45 2017
@@ -9,6 +9,7 @@ add_clang_unittest(ClangRenameTests
   RenameClassTest.cpp
   RenameEnumTest.cpp
   RenameAliasTest.cpp
+  RenameMemberTest.cpp
   RenameFunctionTest.cpp
   )
 

Added: cfe/trunk/unittests/Rename/RenameMemberTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameMemberTest.cpp?rev=316571&view=auto
==
--- cfe/trunk/unittests/Rename/RenameMemberTest.cpp (added)
+++ cfe/trunk/unittests/Rename/RenameMemberTest.cpp Wed Oct 25 04:54:45 2017
@@ -0,0 +1,229 @@
+//===-- ClangMemberTests.cpp - unit tests for renaming class members 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameMemberTest : public ClangRenameTest {
+public:
+  RenameMemberTest() {
+AppendToHeader(R"(
+struct NA {
+  void Foo();
+ 

[clang-tools-extra] r340800 - [clang-tidy] Abseil: no namepsace check

2018-08-28 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Aug 28 00:48:28 2018
New Revision: 340800

URL: http://llvm.org/viewvc/llvm-project?rev=340800&view=rev
Log:
[clang-tidy] Abseil: no namepsace check

This check ensures that users of Abseil do not open namespace absl in their 
code, as that violates our compatibility guidelines.

AbseilMatcher.h written by Hugo Gonzalez.

Patch by Deanna Garcia!

Added:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h
clang-tools-extra/trunk/clang-tidy/abseil/NoNamespaceCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/NoNamespaceCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-no-namespace.rst
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/external-file.h
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h
clang-tools-extra/trunk/test/clang-tidy/abseil-no-namespace.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Added: clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h?rev=340800&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h (added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h Tue Aug 28 
00:48:28 2018
@@ -0,0 +1,51 @@
+//===- AbseilMatcher.h - clang-tidy 
---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+namespace clang {
+namespace ast_matchers {
+
+/// Matches AST nodes that were found within Abseil files.
+///
+/// Example matches Y but not X
+/// (matcher = cxxRecordDecl(isInAbseilFile())
+/// \code
+///   #include "absl/strings/internal-file.h"
+///   class X {};
+/// \endcode
+/// absl/strings/internal-file.h:
+/// \code
+///   class Y {};
+/// \endcode
+///
+/// Usable as: Matcher, Matcher, Matcher,
+/// Matcher
+
+AST_POLYMORPHIC_MATCHER(isInAbseilFile,
+AST_POLYMORPHIC_SUPPORTED_TYPES(
+Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) {
+  auto &SourceManager = Finder->getASTContext().getSourceManager();
+  SourceLocation Loc = Node.getBeginLoc();
+  if (Loc.isInvalid())
+return false;
+  const FileEntry *FileEntry =
+  SourceManager.getFileEntryForID(SourceManager.getFileID(Loc));
+  if (!FileEntry)
+return false;
+  StringRef Filename = FileEntry->getName();
+  llvm::Regex RE(
+  "absl/(algorithm|base|container|debugging|memory|meta|numeric|strings|"
+  "synchronization|time|types|utility)");
+  return RE.match(Filename);
+}
+
+} // namespace ast_matchers
+} // namespace clang

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340800&r1=340799&r2=340800&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Tue Aug 28 
00:48:28 2018
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "DurationDivisionCheck.h"
 #include "FasterStrsplitDelimiterCheck.h"
+#include "NoNamespaceCheck.h"
 #include "StringFindStartswithCheck.h"
 
 namespace clang {
@@ -25,6 +26,7 @@ public:
 "abseil-duration-division");
 CheckFactories.registerCheck(
 "abseil-faster-strsplit-delimiter");
+CheckFactories.registerCheck("abseil-no-namespace");
 CheckFactories.registerCheck(
 "abseil-string-find-startswith");
   }

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340800&r1=340799&r2=340800&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Tue Aug 28 
00:48:28 2018
@@ -4,6 +4,7 @@ add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
   DurationDivisionCheck.cpp
   FasterStrsplitDelimiterCheck.cpp
+  NoNamespaceCheck.cpp
   StringFindStartswithCheck.cpp
 
   LINK_LIBS

Added: clang-tools-extra/trunk/clang-tidy/abseil/No

[clang-tools-extra] r341208 - [clangd] Collect symbol occurrences in SymbolCollector.

2018-08-31 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 31 05:54:13 2018
New Revision: 341208

URL: http://llvm.org/viewvc/llvm-project?rev=341208&view=rev
Log:
[clangd] Collect symbol occurrences in SymbolCollector.

SymbolCollector will be used for two cases:
 - collect Symbol type only, used for indexing preamble AST.
 - collect Symbol and SymbolOccurrences, used for indexing main AST.

For finding local references from the AST, we will implement it in other ways.

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

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=341208&r1=341207&r2=341208&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Fri Aug 31 05:54:13 2018
@@ -128,5 +128,48 @@ SymbolSlab SymbolSlab::Builder::build()
   return SymbolSlab(std::move(NewArena), std::move(Symbols));
 }
 
+raw_ostream &operator<<(raw_ostream &OS, SymbolOccurrenceKind K) {
+  if (K == SymbolOccurrenceKind::Unknown)
+return OS << "Unknown";
+  static const std::vector Messages = {"Decl", "Def", "Ref"};
+  bool VisitedOnce = false;
+  for (unsigned I = 0; I < Messages.size(); ++I) {
+if (static_cast(K) & 1u << I) {
+  if (VisitedOnce)
+OS << ", ";
+  OS << Messages[I];
+  VisitedOnce = true;
+}
+  }
+  return OS;
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const SymbolOccurrence &Occurrence) {
+  OS << Occurrence.Location << ":" << Occurrence.Kind;
+  return OS;
+}
+
+void SymbolOccurrenceSlab::insert(const SymbolID &SymID,
+  const SymbolOccurrence &Occurrence) {
+  assert(!Frozen &&
+ "Can't insert a symbol occurrence after the slab has been frozen!");
+  auto &SymOccurrences = Occurrences[SymID];
+  SymOccurrences.push_back(Occurrence);
+  SymOccurrences.back().Location.FileURI =
+  UniqueStrings.save(Occurrence.Location.FileURI);
+}
+
+void SymbolOccurrenceSlab::freeze() {
+  // Deduplicate symbol occurrenes.
+  for (auto &IDAndOccurrence : Occurrences) {
+auto &Occurrence = IDAndOccurrence.getSecond();
+std::sort(Occurrence.begin(), Occurrence.end());
+Occurrence.erase(std::unique(Occurrence.begin(), Occurrence.end()),
+ Occurrence.end());
+  }
+  Frozen = true;
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=341208&r1=341207&r2=341208&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Fri Aug 31 05:54:13 2018
@@ -32,9 +32,6 @@ struct SymbolLocation {
 uint32_t Line = 0; // 0-based
 // Using UTF-16 code units.
 uint32_t Column = 0; // 0-based
-bool operator==(const Position& P) const {
-  return Line == P.Line && Column == P.Column;
-}
   };
 
   // The URI of the source file where a symbol occurs.
@@ -45,11 +42,23 @@ struct SymbolLocation {
   Position End;
 
   explicit operator bool() const { return !FileURI.empty(); }
-  bool operator==(const SymbolLocation& Loc) const {
-return std::tie(FileURI, Start, End) ==
-   std::tie(Loc.FileURI, Loc.Start, Loc.End);
-  }
 };
+inline bool operator==(const SymbolLocation::Position &L,
+   const SymbolLocation::Position &R) {
+  return std::tie(L.Line, L.Column) == std::tie(R.Line, R.Column);
+}
+inline bool operator<(const SymbolLocation::Position &L,
+  const SymbolLocation::Position &R) {
+  return std::tie(L.Line, L.Column) < std::tie(R.Line, R.Column);
+}
+inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) {
+  return std::tie(L.FileURI, L.Start, L.End) ==
+ std::tie(R.FileURI, R.Start, R.End);
+}
+inline bool operator<(const SymbolLocation &L, const SymbolLocation &R) {
+  return std::tie(L.FileURI, L.Start, L.End) <
+ std::tie(R.FileURI, R.Start, R.End);
+}
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
 
 // The class identifies a particular C++ symbol (class, function, method, etc).
@@ -314,6 +323,9 @@ inline SymbolOccurrenceKind operator&(Sy
   return static_cast(static_cast(A) &
static_cast(B));
 }
+static const SymbolOccurrenceKind AllOccurrenceKinds =
+SymbolOccurrenceKind::Declaration | SymbolOccurrenceKind::Definition |
+SymbolOccurrenceKind::Reference;
 
 // 

[clang-tools-extra] r341242 - [clangd] Implement findOccurrences interface in dynamic index.

2018-08-31 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 31 12:53:37 2018
New Revision: 341242

URL: http://llvm.org/viewvc/llvm-project?rev=341242&view=rev
Log:
[clangd] Implement findOccurrences interface in dynamic index.

Summary:
Implement the interface in
  - FileIndex
  - MemIndex
  - MergeIndex

Depends on https://reviews.llvm.org/D50385.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Merge.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=341242&r1=341241&r2=341242&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Fri Aug 31 12:53:37 2018
@@ -16,9 +16,10 @@
 namespace clang {
 namespace clangd {
 
-SymbolSlab indexAST(ASTContext &AST, std::shared_ptr PP,
-llvm::Optional> TopLevelDecls,
-llvm::ArrayRef URISchemes) {
+std::pair
+indexAST(ASTContext &AST, std::shared_ptr PP,
+ llvm::Optional> TopLevelDecls,
+ llvm::ArrayRef URISchemes) {
   SymbolCollector::Options CollectorOpts;
   // FIXME(ioeric): we might also want to collect include headers. We would 
need
   // to make sure all includes are canonicalized (with CanonicalIncludes), 
which
@@ -31,8 +32,6 @@ SymbolSlab indexAST(ASTContext &AST, std
 CollectorOpts.URISchemes = URISchemes;
   CollectorOpts.Origin = SymbolOrigin::Dynamic;
 
-  SymbolCollector Collector(std::move(CollectorOpts));
-  Collector.setPreprocessor(PP);
   index::IndexingOptions IndexOpts;
   // We only need declarations, because we don't count references.
   IndexOpts.SystemSymbolFilter =
@@ -46,20 +45,45 @@ SymbolSlab indexAST(ASTContext &AST, std
 DeclsToIndex.assign(AST.getTranslationUnitDecl()->decls().begin(),
 AST.getTranslationUnitDecl()->decls().end());
 
+  // We only collect occurrences when indexing main AST.
+  // FIXME: this is a hacky way to detect whether we are indexing preamble AST
+  // or main AST, we should make it explicitly.
+  bool IsIndexMainAST = TopLevelDecls.hasValue();
+  if (IsIndexMainAST)
+CollectorOpts.OccurrenceFilter = AllOccurrenceKinds;
+
+  SymbolCollector Collector(std::move(CollectorOpts));
+  Collector.setPreprocessor(PP);
   index::indexTopLevelDecls(AST, DeclsToIndex, Collector, IndexOpts);
 
-  return Collector.takeSymbols();
+  const auto &SM = AST.getSourceManager();
+  const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  std::string FileName = MainFileEntry ? MainFileEntry->getName() : "";
+
+  auto Syms = Collector.takeSymbols();
+  auto Occurrences = Collector.takeOccurrences();
+  vlog("index {0}AST for {1}: \n"
+   "  symbol slab: {2} symbols, {3} bytes\n"
+   "  occurrence slab: {4} symbols, {5} bytes",
+   IsIndexMainAST ? "Main" : "Preamble", FileName, Syms.size(),
+   Syms.bytes(), Occurrences.size(), Occurrences.bytes());
+  return {std::move(Syms), std::move(Occurrences)};
 }
 
 FileIndex::FileIndex(std::vector URISchemes)
 : URISchemes(std::move(URISchemes)) {}
 
-void FileSymbols::update(PathRef Path, std::unique_ptr Slab) {
+void FileSymbols::update(PathRef Path, std::unique_ptr Slab,
+ std::unique_ptr Occurrences) {
   std::lock_guard Lock(Mutex);
   if (!Slab)
 FileToSlabs.erase(Path);
   else
 FileToSlabs[Path] = std::move(Slab);
+  if (!Occurrences)
+FileToOccurrenceSlabs.erase(Path);
+  else
+FileToOccurrenceSlabs[Path] = std::move(Occurrences);
 }
 
 std::shared_ptr> FileSymbols::allSymbols() {
@@ -85,19 +109,47 @@ std::shared_ptr FileSymbols::allOccurrences() const {
+  // The snapshot manages life time of symbol occurrence slabs and provides
+  // pointers to all occurrences in all occurrence slabs.
+  struct Snapshot {
+MemIndex::OccurrenceMap Occurrences; // ID => {Occurrence}
+std::vector> KeepAlive;
+  };
+
+  auto Snap = std::make_shared();
+  {
+std::lock_guard Lock(Mutex);
+
+for (const auto &FileAndSlab : FileToOccurrenceSlabs) {
+  Snap->KeepAlive.push_bac

[clang-tools-extra] r341463 - [clangd] Sort GoToDefinition results.

2018-09-05 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Sep  5 05:00:15 2018
New Revision: 341463

URL: http://llvm.org/viewvc/llvm-project?rev=341463&view=rev
Log:
[clangd] Sort GoToDefinition results.

Summary:
GoToDefinition returns all declaration results (implicit/explicit) that are
in the same location, and the results are returned in arbitrary order.

Some LSP clients defaultly take the first result as the final result, which
might present a bad result (implicit decl) to users.

This patch ranks the result based on whether the declarations are
referenced explicitly/implicitly. We put explicit declarations first.

This also improves the "hover" (which just take the first result) feature
in some cases.

Reviewers: ilya-biryukov

Subscribers: kadircet, ioeric, MaskRay, jkorous, mgrang, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=341463&r1=341462&r2=341463&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Wed Sep  5 05:00:15 2018
@@ -69,10 +69,20 @@ struct MacroDecl {
   const MacroInfo *Info;
 };
 
+struct DeclInfo {
+  const Decl *D;
+  // Indicates the declaration is referenced by an explicit AST node.
+  bool IsReferencedExplicitly = false;
+};
+
 /// Finds declarations locations that a given source location refers to.
 class DeclarationAndMacrosFinder : public index::IndexDataConsumer {
-  std::vector Decls;
   std::vector MacroInfos;
+  // The value of the map indicates whether the declaration has been referenced
+  // explicitly in the code.
+  // True means the declaration is explicitly referenced at least once; false
+  // otherwise.
+  llvm::DenseMap Decls;
   const SourceLocation &SearchedLocation;
   const ASTContext &AST;
   Preprocessor &PP;
@@ -82,13 +92,25 @@ public:
  ASTContext &AST, Preprocessor &PP)
   : SearchedLocation(SearchedLocation), AST(AST), PP(PP) {}
 
-  std::vector takeDecls() {
-// Don't keep the same declaration multiple times.
-// This can happen when nodes in the AST are visited twice.
-std::sort(Decls.begin(), Decls.end());
-auto Last = std::unique(Decls.begin(), Decls.end());
-Decls.erase(Last, Decls.end());
-return std::move(Decls);
+  // Get all DeclInfo of the found declarations.
+  // The results are sorted by "IsReferencedExplicitly" and declaration
+  // location.
+  std::vector getFoundDecls() const {
+std::vector Result;
+for (auto It : Decls) {
+  Result.emplace_back();
+  Result.back().D = It.first;
+  Result.back().IsReferencedExplicitly = It.second;
+}
+
+// Sort results. Declarations being referenced explicitly come first.
+std::sort(Result.begin(), Result.end(),
+  [](const DeclInfo &L, const DeclInfo &R) {
+if (L.IsReferencedExplicitly != R.IsReferencedExplicitly)
+  return L.IsReferencedExplicitly > R.IsReferencedExplicitly;
+return L.D->getBeginLoc() < R.D->getBeginLoc();
+  });
+return Result;
   }
 
   std::vector takeMacroInfos() {
@@ -112,15 +134,30 @@ public:
   SourceLocation Loc,
   index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 if (Loc == SearchedLocation) {
+  // Check whether the E has an implicit AST node (e.g. ImplicitCastExpr).
+  auto hasImplicitExpr = [](const Expr *E) {
+if (!E || E->child_begin() == E->child_end())
+  return false;
+// Use the first child is good enough for most cases -- normally the
+// expression returned by handleDeclOccurence contains exactly one
+// child expression.
+const auto *FirstChild = *E->child_begin();
+return llvm::isa(FirstChild) ||
+   llvm::isa(FirstChild) ||
+   llvm::isa(FirstChild) ||
+   llvm::isa(FirstChild);
+  };
+
+  bool IsExplicit = !hasImplicitExpr(ASTNode.OrigE);
   // Find and add definition declarations (for GoToDefinition).
   // We don't use parameter `D`, as Parameter `D` is the canonical
   // declaration, which is the first declaration of a redeclarable
   // declaration, and it could be a forward declaration.
   if (const auto *Def = getDefinition(D)) {
-Decls.push_back(Def);
+Decls[Def] |= IsExplicit;
   } else {
 // Couldn't find a definition, fall back to use `D`.
-Decls.push_back(D);
+Decls[D] |= IsExplicit;
   }
 }
 return true;
@@ -158,7 +195,7 @@ private:
 };
 
 struct IdentifiedSymbol {
-  std::vector Decls;
+  std::vector Decls;
   std::vector Macros;
 };
 
@@ -172,7 +209,7 @@ Identif

[clang-tools-extra] r338517 - [clangd] Make SymbolLocation => bool conversion explicitly.

2018-08-01 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Aug  1 04:24:50 2018
New Revision: 338517

URL: http://llvm.org/viewvc/llvm-project?rev=338517&view=rev
Log:
[clangd] Make SymbolLocation => bool conversion explicitly.

Summary:
The implicit bool conversion could happen superisingly, e.g. when
checking `if (Loc1 == Loc2)`, the compiler will convert SymbolLocation to
bool before comparing (because we don't define operator `==` for 
SymbolLocation).

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=338517&r1=338516&r2=338517&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Wed Aug  1 04:24:50 2018
@@ -30,6 +30,9 @@ struct SymbolLocation {
 uint32_t Line = 0; // 0-based
 // Using UTF-16 code units.
 uint32_t Column = 0; // 0-based
+bool operator==(const Position& P) const {
+  return Line == P.Line && Column == P.Column;
+}
   };
 
   // The URI of the source file where a symbol occurs.
@@ -39,7 +42,11 @@ struct SymbolLocation {
   Position Start;
   Position End;
 
-  operator bool() const { return !FileURI.empty(); }
+  explicit operator bool() const { return !FileURI.empty(); }
+  bool operator==(const SymbolLocation& Loc) const {
+return std::tie(FileURI, Start, End) ==
+   std::tie(Loc.FileURI, Loc.Start, Loc.End);
+  }
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
 


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


[clang-tools-extra] r338526 - [clangd] Correct the namespace of ParsedAST forward declaration, NFC.

2018-08-01 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Aug  1 05:50:44 2018
New Revision: 338526

URL: http://llvm.org/viewvc/llvm-project?rev=338526&view=rev
Log:
[clangd] Correct the namespace of ParsedAST forward declaration, NFC.

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

Modified: clang-tools-extra/trunk/clangd/FindSymbols.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.h?rev=338526&r1=338525&r2=338526&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.h (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.h Wed Aug  1 05:50:44 2018
@@ -17,8 +17,8 @@
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {
-class ParsedAST;
 namespace clangd {
+class ParsedAST;
 class SymbolIndex;
 
 /// Searches for the symbols matching \p Query. The syntax of \p Query can be


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


[clang-tools-extra] r339011 - [clangd] Index Interfaces for Xrefs

2018-08-06 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Aug  6 06:14:32 2018
New Revision: 339011

URL: http://llvm.org/viewvc/llvm-project?rev=339011&view=rev
Log:
[clangd] Index Interfaces for Xrefs

Summary:
This is the first step of implementing Xrefs in clangd:
  - add index interfaces, and related data structures.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=339011&r1=339010&r2=339011&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Mon Aug  6 06:14:32 2018
@@ -9,6 +9,7 @@
 
 #include "FileIndex.h"
 #include "SymbolCollector.h"
+#include "../Logger.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Preprocessor.h"
 
@@ -105,5 +106,11 @@ void FileIndex::lookup(
   Index.lookup(Req, Callback);
 }
 
+void FileIndex::findOccurrences(
+const OccurrencesRequest &Req,
+llvm::function_ref Callback) const {
+  log("findOccurrences is not implemented.");
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.h?rev=339011&r1=339010&r2=339011&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.h Mon Aug  6 06:14:32 2018
@@ -73,6 +73,10 @@ public:
   void lookup(const LookupRequest &Req,
   llvm::function_ref Callback) const 
override;
 
+
+  void findOccurrences(const OccurrencesRequest &Req,
+   llvm::function_ref
+   Callback) const override;
 private:
   FileSymbols FSymbols;
   MemIndex Index;

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=339011&r1=339010&r2=339011&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Aug  6 06:14:32 2018
@@ -287,6 +287,40 @@ private:
   std::vector Symbols;  // Sorted by SymbolID to allow lookup.
 };
 
+// Describes the kind of a symbol occurrence.
+//
+// This is a bitfield which can be combined from different kinds.
+enum class SymbolOccurrenceKind : uint8_t {
+  Unknown = 0,
+  Declaration = static_cast(index::SymbolRole::Declaration),
+  Definition = static_cast(index::SymbolRole::Definition),
+  Reference = static_cast(index::SymbolRole::Reference),
+};
+inline SymbolOccurrenceKind operator|(SymbolOccurrenceKind L,
+  SymbolOccurrenceKind R) {
+  return static_cast(static_cast(L) |
+   static_cast(R));
+}
+inline SymbolOccurrenceKind &operator|=(SymbolOccurrenceKind &L,
+SymbolOccurrenceKind R) {
+  return L = L | R;
+}
+inline SymbolOccurrenceKind operator&(SymbolOccurrenceKind A,
+  SymbolOccurrenceKind B) {
+  return static_cast(static_cast(A) &
+   static_cast(B));
+}
+
+// Represents a symbol occurrence in the source file. It could be a
+// declaration/definition/reference occurrence.
+//
+// WARNING: Location does not own the underlying data - Copies are shallow.
+struct SymbolOccurrence {
+  // The location of the occurrence.
+  SymbolLocation Location;
+  SymbolOccurrenceKind Kind = SymbolOccurrenceKind::Unknown;
+};
+
 struct FuzzyFindRequest {
   /// \brief A query string for the fuzzy find. This is matched against 
symbols'
   /// un-qualified identifiers and should not contain qualifiers like "::".
@@ -312,6 +346,11 @@ struct LookupRequest {
   llvm::DenseSet IDs;
 };
 
+struct OccurrencesRequest {
+  llvm::DenseSet IDs;
+  SymbolOccurrenceKind Filter;
+};
+
 /// \brief Interface for symbol indexes that can be used for searching or
 /// matching symbols among a set of symbols based on names or unique IDs.
 class SymbolIndex {
@@ -334,8 +373,15 @@ public:
   lookup(const LookupRequest &Req,
  llvm::function_ref Callback) const = 0;
 
-  // FIXME: add interfaces for more index

[clang-tools-extra] r324328 - [clangd] Fix incorrect file path for symbols defined by the compile command-line option.

2018-02-06 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Feb  6 01:50:35 2018
New Revision: 324328

URL: http://llvm.org/viewvc/llvm-project?rev=324328&view=rev
Log:
[clangd] Fix incorrect file path for symbols defined by the compile 
command-line option.

Summary:

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=324328&r1=324327&r2=324328&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Feb  6 
01:50:35 2018
@@ -124,10 +124,15 @@ SymbolLocation GetSymbolLocation(const N
 
   SourceLocation Loc = SM.getSpellingLoc(D->getLocation());
   if (D->getLocation().isMacroID()) {
-// The symbol is formed via macro concatenation, the spelling location will
-// be "", which is not interesting to us, use the expansion
-// location instead.
-if (llvm::StringRef(Loc.printToString(SM)).startswith(""
+//   * symbols controlled and defined by a compile command-line option
+// `-DName=foo`, the spelling location will be "".
+std::string PrintLoc = Loc.printToString(SM);
+if (llvm::StringRef(PrintLoc).startswith("")) {
   FilePathStorage = makeAbsolutePath(
   SM, SM.getFilename(SM.getExpansionLoc(D->getLocation())),
   FallbackDir);

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=324328&r1=324327&r2=324328&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Tue Feb  
6 01:50:35 2018
@@ -82,7 +82,8 @@ public:
 
 class SymbolCollectorTest : public ::testing::Test {
 public:
-  bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode) {
+  bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode,
+  const std::vector &ExtraArgs = {}) {
 llvm::IntrusiveRefCntPtr InMemoryFileSystem(
 new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
@@ -90,8 +91,11 @@ public:
 
 auto Factory = llvm::make_unique(CollectorOpts);
 
+std::vector Args = {"symbol_collector", "-fsyntax-only",
+ "-std=c++11", TestFileName};
+Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end());
 tooling::ToolInvocation Invocation(
-{"symbol_collector", "-fsyntax-only", "-std=c++11", TestFileName},
+Args,
 Factory->create(), Files.get(),
 std::make_shared());
 
@@ -264,6 +268,24 @@ TEST_F(SymbolCollectorTest, SymbolFormed
 CPath(TestFileName;
 }
 
+TEST_F(SymbolCollectorTest, SymbolFormedByCLI) {
+  CollectorOpts.IndexMainFiles = false;
+
+  Annotations Header(R"(
+#ifdef NAME
+$expansion[[class NAME {}]];
+#endif
+  )");
+
+  runSymbolCollector(Header.code(), /*Main=*/"",
+ /*ExtraArgs=*/{"-DNAME=name"});
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(
+  AllOf(QName("name"),
+LocationOffsets(Header.offsetRange("expansion")),
+CPath(TestHeaderName;
+}
+
 TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) {
   CollectorOpts.IndexMainFiles = false;
   const std::string Header = R"(


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


[clang-tools-extra] r324742 - [clang-move] Don't dump macro symbols.

2018-02-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Feb  9 07:57:30 2018
New Revision: 324742

URL: http://llvm.org/viewvc/llvm-project?rev=324742&view=rev
Log:
[clang-move] Don't dump macro symbols.

Reviewers: ioeric

Subscribers: klimek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=324742&r1=324741&r2=324742&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Feb  9 07:57:30 2018
@@ -523,6 +523,7 @@ void ClangMoveTool::registerMatchers(ast
   auto AllDeclsInHeader = namedDecl(
   unless(ForwardClassDecls), unless(namespaceDecl()),
   unless(usingDirectiveDecl()), // using namespace decl.
+  notInMacro(),
   InOldHeader,
   hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(,
   hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl();
@@ -905,10 +906,9 @@ void ClangMoveTool::onEndOfTranslationUn
 
   if (RemovedDecls.empty())
 return;
-  // Ignore symbols that are not supported (e.g. typedef and enum) when
-  // checking if there is unremoved symbol in old header. This makes sure that
-  // we always move old files to new files when all symbols produced from
-  // dump_decls are moved.
+  // Ignore symbols that are not supported when checking if there is unremoved
+  // symbol in old header. This makes sure that we always move old files to new
+  // files when all symbols produced from dump_decls are moved.
   auto IsSupportedKind = [](const clang::NamedDecl *Decl) {
 switch (Decl->getKind()) {
 case Decl::Kind::Function:

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=324742&r1=324741&r2=324742&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Feb  9 
07:57:30 2018
@@ -391,6 +391,26 @@ TEST(ClangMove, DontMoveAll) {
   }
 }
 
+TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
+  const char TestCode[] = "#include \"foo.h\"";
+  std::vector TestHeaders = {
+"#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n",
+"#define DEFINE(x) int var_##x = 1;\nDEFINE(foo);\nclass Bar {};\n",
+  };
+  move::MoveDefinitionSpec Spec;
+  Spec.Names.push_back("Bar");
+  Spec.OldHeader = "foo.h";
+  Spec.OldCC = "foo.cc";
+  Spec.NewHeader = "new_foo.h";
+  Spec.NewCC = "new_foo.cc";
+
+  for (const auto& Header : TestHeaders) {
+auto Results = runClangMoveOnCode(Spec, Header.c_str(), TestCode);
+EXPECT_EQ("", Results[Spec.OldHeader]);
+EXPECT_EQ(Header, Results[Spec.NewHeader]);
+  }
+}
+
 TEST(ClangMove, MacroInFunction) {
   const char TestHeader[] = "#define INT int\n"
 "class A {\npublic:\n  int f();\n};\n"
@@ -570,7 +590,9 @@ TEST(ClangMove, DumpDecls) {
 "extern int kGlobalInt;\n"
 "extern const char* const kGlobalStr;\n"
 "} // namespace b\n"
-"} // namespace a\n";
+"} // namespace a\n"
+"#define DEFINE_FOO class Foo {};\n"
+"DEFINE_FOO\n";
   const char TestCode[] = "#include \"foo.h\"\n";
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("B");


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


[clang-tools-extra] r324886 - [clang-move] Fix the incorrect expansion end location.

2018-02-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Feb 12 04:26:12 2018
New Revision: 324886

URL: http://llvm.org/viewvc/llvm-project?rev=324886&view=rev
Log:
[clang-move] Fix the incorrect expansion end location.

Summary:
Before the fix, if clang-move decides to move the following macro statement, it 
only moves the first line `DEFINE(A,`.

```
DEFINE(A,
   B);
```

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=324886&r1=324885&r2=324886&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Mon Feb 12 04:26:12 2018
@@ -280,7 +280,7 @@ SourceLocation
 getLocForEndOfDecl(const clang::Decl *D,
const LangOptions &LangOpts = clang::LangOptions()) {
   const auto &SM = D->getASTContext().getSourceManager();
-  auto EndExpansionLoc = SM.getExpansionLoc(D->getLocEnd());
+  auto EndExpansionLoc = SM.getExpansionRange(D->getLocEnd()).second;
   std::pair LocInfo = SM.getDecomposedLoc(EndExpansionLoc);
   // Try to load the file buffer.
   bool InvalidTemp = false;

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=324886&r1=324885&r2=324886&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Mon Feb 12 
04:26:12 2018
@@ -431,12 +431,16 @@ TEST(ClangMove, MacroInFunction) {
 
 TEST(ClangMove, DefinitionInMacro) {
   const char TestHeader[] = "#define DEF(CLASS) void CLASS##_::f() {}\n"
-"class A_ {\nvoid f();\n};\n"
+"#define DEF2(CLASS, ...) void CLASS##_::f2() {}\n"
+"class A_ {\nvoid f();\nvoid f2();\n};\n"
 "class B {};\n";
   const char TestCode[] = "#include \"foo.h\"\n"
-  "DEF(A)\n";
+  "DEF(A)\n\n"
+  "DEF2(A,\n"
+  " 123)\n";
   const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
- "DEF(A)\n";
+ "DEF(A)\n\n"
+ "DEF2(A, 123)\n";
   move::MoveDefinitionSpec Spec;
   Spec.Names.push_back("A_");
   Spec.OldHeader = "foo.h";


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


[clang-tools-extra] r324992 - [clangd] SymbolLocation only covers symbol name.

2018-02-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Feb 13 01:53:50 2018
New Revision: 324992

URL: http://llvm.org/viewvc/llvm-project?rev=324992&view=rev
Log:
[clangd] SymbolLocation only covers symbol name.

Summary:
* Change the offset range to half-open, [start, end).
* Fix a few fixmes.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=324992&r1=324991&r2=324992&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Tue Feb 13 01:53:50 2018
@@ -19,7 +19,7 @@ using namespace llvm;
 raw_ostream &operator<<(raw_ostream &OS, const SymbolLocation &L) {
   if (!L)
 return OS << "(none)";
-  return OS << L.FileURI << "[" << L.StartOffset << "-" << L.EndOffset << "]";
+  return OS << L.FileURI << "[" << L.StartOffset << "-" << L.EndOffset << ")";
 }
 
 SymbolID::SymbolID(StringRef USR)

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=324992&r1=324991&r2=324992&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Tue Feb 13 01:53:50 2018
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H
 
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Hashing.h"
@@ -25,11 +26,9 @@ namespace clangd {
 struct SymbolLocation {
   // The URI of the source file where a symbol occurs.
   llvm::StringRef FileURI;
-  // The 0-based offset to the first character of the symbol from the beginning
-  // of the source file.
+  // The 0-based offsets of the symbol from the beginning of the source file,
+  // using half-open range, [StartOffset, EndOffset).
   unsigned StartOffset = 0;
-  // The 0-based offset to the last character of the symbol from the beginning
-  // of the source file.
   unsigned EndOffset = 0;
 
   operator bool() const { return !FileURI.empty(); }
@@ -121,9 +120,10 @@ struct Symbol {
   // The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
   llvm::StringRef Scope;
   // The location of the symbol's definition, if one was found.
-  // This covers the whole definition (e.g. class body).
+  // This just covers the symbol name (e.g. without class/function body).
   SymbolLocation Definition;
   // The location of the preferred declaration of the symbol.
+  // This just covers the symbol name.
   // This may be the same as Definition.
   //
   // A C++ symbol may have multiple declarations, and we pick one to prefer.

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=324992&r1=324991&r2=324992&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Feb 13 
01:53:50 2018
@@ -132,21 +132,14 @@ bool shouldFilterDecl(const NamedDecl *N
 // For symbols defined inside macros:
 //   * use expansion location, if the symbol is formed via macro concatenation.
 //   * use spelling location, otherwise.
-//
-// FIXME: EndOffset is inclusive (closed range), and should be exclusive.
-// FIXME: Because the underlying ranges are token ranges, this code chops the
-//last token in half if it contains multiple characters.
-// FIXME: We probably want to get just the location of the symbol name, not
-//the whole e.g. class.
 llvm::Optional
 getSymbolLocation(const NamedDecl &D, SourceManager &SM,
   const SymbolCollector::Options &Opts,
+  const clang::LangOptions& LangOpts,
   std::string &FileURIStorage) {
-  SourceLocation Loc = D.getLocation();
-  SourceLocation StartLoc = SM.getSpellingLoc(D.getLocStart());
-  SourceLocation EndLoc = SM.getSpellingLoc(D.getLocEnd());
-  if (Loc.isMacroID()) {
-std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM);
+  SourceLocation SpellingLoc = SM.getSpellingLoc(D.getLocation());
+  if (D.getLocation().isMacroID()) {
+std::string PrintLoc = SpellingLoc.printToString(SM);
 if (llvm::StringRef(PrintLoc).startswith("")) {
   // We use the expan

[clang-tools-extra] r324993 - [clangd] Remove an already-done FIXME, NFC

2018-02-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Feb 13 01:56:45 2018
New Revision: 324993

URL: http://llvm.org/viewvc/llvm-project?rev=324993&view=rev
Log:
[clangd] Remove an already-done FIXME, NFC

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

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=324993&r1=324992&r2=324993&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Tue Feb 13 01:56:45 2018
@@ -162,7 +162,6 @@ struct Symbol {
   // Optional details of the symbol.
   const Details *Detail = nullptr;
 
-  // FIXME: add definition location of the symbol.
   // FIXME: add all occurrences support.
   // FIXME: add extra fields for index scoring signals.
 };


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


[clang-tools-extra] r325484 - [clangd] Bump vs-code clangd extension v0.0.3

2018-02-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Feb 19 02:49:12 2018
New Revision: 325484

URL: http://llvm.org/viewvc/llvm-project?rev=325484&view=rev
Log:
[clangd] Bump vs-code clangd extension v0.0.3

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits, ioeric

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=325484&r1=325483&r2=325484&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Mon Feb 
19 02:49:12 2018
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.2",
+"version": "0.0.3",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


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


[clang-tools-extra] r325499 - [clangd] Add brief instructions on how to make a release for vscode-clangd extension.

2018-02-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Feb 19 06:01:52 2018
New Revision: 325499

URL: http://llvm.org/viewvc/llvm-project?rev=325499&view=rev
Log:
[clangd] Add brief instructions on how to make a release for vscode-clangd 
extension.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md?rev=325499&r1=325498&r2=325499&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md Mon Feb 19 
06:01:52 2018
@@ -49,3 +49,28 @@ point to the binary.
$ code .
# When VS Code starts, press .
 ```
+
+## Publish to VS Code Marketplace
+
+New changes to `clangd-vscode` are not released until a new version is 
published
+to the marketplace.
+
+### Requirements
+
+* Make sure install the `vsce` command (`npm install -g vsce`)
+* `llvm-vs-code-extensions` account
+* Bump the version in `package.json`, and commit the change to upstream
+
+The extension is published under `llvm-vs-code-extensions` account, which is
+currently maintained by clangd developers. If you want to make a new release,
+please contact cfe-...@lists.llvm.org.
+
+### Steps
+
+```bash
+  $ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
+  # For the first time, you need to login in the account. vsce will ask you for
+the account password, and remember it for future commands.
+  $ vsce login llvm-vs-code-extensions
+  $ vsce publish
+```


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


[clang-tools-extra] r325503 - [clangd] Correct the doc, password => Personal Access Token.

2018-02-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Feb 19 06:26:55 2018
New Revision: 325503

URL: http://llvm.org/viewvc/llvm-project?rev=325503&view=rev
Log:
[clangd] Correct the doc, password => Personal Access Token.

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md?rev=325503&r1=325502&r2=325503&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md Mon Feb 19 
06:26:55 2018
@@ -70,7 +70,7 @@ please contact cfe-...@lists.llvm.org.
 ```bash
   $ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
   # For the first time, you need to login in the account. vsce will ask you for
-the account password, and remember it for future commands.
+the Personal Access Token, and remember it for future commands.
   $ vsce login llvm-vs-code-extensions
   $ vsce publish
 ```


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


[clang-tools-extra] r325779 - [clangd] Correct setting ignoreWarnings in CodeCompletion.

2018-02-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Feb 22 05:35:01 2018
New Revision: 325779

URL: http://llvm.org/viewvc/llvm-project?rev=325779&view=rev
Log:
[clangd] Correct setting ignoreWarnings in CodeCompletion.

Summary:
We should set the flag before creating ComplierInstance -- when
CopmilerInstance gets initialized, it also initializes the DiagnosticsEngine
using the DiagnosticOptions.

This was hidden deeply -- as clang suppresses all diagnostics when we
hit the code-completion (but internally it does do unnecessary analysis stuff).

As a bonus point, this fix will optmize the completion speed -- clang won't do
any analysis (e.g. -Wunreachable-code, -Wthread-safety-analysisi) at all 
internally.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=325779&r1=325778&r2=325779&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Feb 22 05:35:01 2018
@@ -696,11 +696,11 @@ bool semaCodeComplete(std::unique_ptrCanReuse(*CI, ContentsBuffer.get(), Bounds,
  Input.VFS.get());
   }
+  // The diagnostic options must be set before creating a CompilerInstance.
+  CI->getDiagnosticOpts().IgnoreWarnings = true;
   auto Clang = prepareCompilerInstance(
   std::move(CI), Input.Preamble, std::move(ContentsBuffer),
   std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer);
-  auto &DiagOpts = Clang->getDiagnosticOpts();
-  DiagOpts.IgnoreWarnings = true;
 
   // Disable typo correction in Sema.
   Clang->getLangOpts().SpellChecking = false;

Modified: clang-tools-extra/trunk/clangd/Headers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=325779&r1=325778&r2=325779&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.cpp (original)
+++ clang-tools-extra/trunk/clangd/Headers.cpp Thu Feb 22 05:35:01 2018
@@ -79,12 +79,12 @@ calculateIncludePath(llvm::StringRef Fil
   // added more than once.
   CI->getPreprocessorOpts().SingleFileParseMode = true;
 
+  // The diagnostic options must be set before creating a CompilerInstance.
+  CI->getDiagnosticOpts().IgnoreWarnings = true;
   auto Clang = prepareCompilerInstance(
   std::move(CI), /*Preamble=*/nullptr,
   llvm::MemoryBuffer::getMemBuffer(Code, File),
   std::make_shared(), FS, IgnoreDiags);
-  auto &DiagOpts = Clang->getDiagnosticOpts();
-  DiagOpts.IgnoreWarnings = true;
 
   if (Clang->getFrontendOpts().Inputs.empty())
 return llvm::make_error(


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


r305898 - Fix unused-variable compilation error.

2017-06-21 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jun 21 06:26:58 2017
New Revision: 305898

URL: http://llvm.org/viewvc/llvm-project?rev=305898&view=rev
Log:
Fix unused-variable compilation error.

Modified:
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=305898&r1=305897&r2=305898&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed Jun 21 06:26:58 2017
@@ -73,12 +73,14 @@ TemporaryFiles::~TemporaryFiles() {
 void TemporaryFiles::addFile(StringRef File) {
   llvm::MutexGuard Guard(Mutex);
   auto IsInserted = Files.insert(File).second;
+  (void)IsInserted;
   assert(IsInserted && "File has already been added");
 }
 
 void TemporaryFiles::removeFile(StringRef File) {
   llvm::MutexGuard Guard(Mutex);
   auto WasPresent = Files.erase(File);
+  (void)WasPresent;
   assert(WasPresent && "File was not tracked");
   llvm::sys::fs::remove(File);
 }


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


[clang-tools-extra] r306091 - [clang-tidy] Fix a false positive in modernize-use-nullptr.

2017-06-23 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jun 23 04:36:49 2017
New Revision: 306091

URL: http://llvm.org/viewvc/llvm-project?rev=306091&view=rev
Log:
[clang-tidy] Fix a false positive in modernize-use-nullptr.

Summary:
The FP happens when a casting nullptr expression is used within a 
NULL-default-arguemnt cxx constructor.

Before the fix, the check will give a warning on nullptr when running
with the test case, which should not happen:

```
G(g(static_cast(nullptr)));
^~~
nullptr
```

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, xazax.hun

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=306091&r1=306090&r2=306091&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Fri Jun 23 
04:36:49 2017
@@ -200,12 +200,14 @@ public:
   return true;
 }
 
-if (!FirstSubExpr)
-  FirstSubExpr = C->getSubExpr()->IgnoreParens();
-
-// Ignore the expr if it is already a nullptr literal expr.
-if (isa(FirstSubExpr))
+auto* CastSubExpr = C->getSubExpr()->IgnoreParens();
+// Ignore cast expressions which cast nullptr literal.
+if (isa(CastSubExpr)) {
   return true;
+}
+
+if (!FirstSubExpr)
+  FirstSubExpr = CastSubExpr;
 
 if (C->getCastKind() != CK_NullToPointer &&
 C->getCastKind() != CK_NullToMemberPointer) {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp?rev=306091&r1=306090&r2=306091&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp Fri Jun 
23 04:36:49 2017
@@ -261,3 +261,17 @@ class TemplateClass {
 void IgnoreSubstTemplateType() {
   TemplateClass a(1);
 }
+
+// Test on casting nullptr.
+struct G {
+  explicit G(bool, const char * = NULL) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use nullptr
+  // CHECK-FIXES: explicit G(bool, const char * = nullptr) {}
+};
+bool g(const char*);
+void test_cast_nullptr() {
+  G(g(nullptr));
+  G(g((nullptr)));
+  G(g(static_cast(nullptr)));
+  G(g(static_cast(nullptr)));
+}


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


[clang-tools-extra] r320678 - [clangd] Fix the unitttest build error on buildbot.

2017-12-14 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Dec 14 01:20:21 2017
New Revision: 320678

URL: http://llvm.org/viewvc/llvm-project?rev=320678&view=rev
Log:
[clangd] Fix the unitttest build error on buildbot.

Modified:
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt?rev=320678&r1=320677&r2=320678&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt Thu Dec 14 01:20:21 
2017
@@ -25,6 +25,7 @@ target_link_libraries(ClangdTests
   clangDaemon
   clangFormat
   clangFrontend
+  clangIndex
   clangSema
   clangTooling
   clangToolingCore


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


[clang-tools-extra] r320694 - [clangd] Construct SymbolSlab from YAML format.

2017-12-14 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Dec 14 04:17:14 2017
New Revision: 320694

URL: http://llvm.org/viewvc/llvm-project?rev=320694&view=rev
Log:
[clangd] Construct SymbolSlab from YAML format.

Summary: This will be used together with D40548 for the global index source 
(experimental).

Reviewers: sammccall

Reviewed By: sammccall

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

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

Added:
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=320694&r1=320693&r2=320694&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Dec 14 04:17:14 2017
@@ -22,6 +22,7 @@ add_clang_library(clangDaemon
   index/MemIndex.cpp
   index/Index.cpp
   index/SymbolCollector.cpp
+  index/SymbolYAML.cpp
 
   LINK_LIBS
   clangAST

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=320694&r1=320693&r2=320694&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Dec 14 04:17:14 2017
@@ -10,18 +10,24 @@
 #include "Index.h"
 
 #include "llvm/Support/SHA1.h"
+#include "llvm/ADT/StringExtras.h"
 
 namespace clang {
 namespace clangd {
 
-namespace {
-ArrayRef toArrayRef(StringRef S) {
-  return {reinterpret_cast(S.data()), S.size()};
+SymbolID::SymbolID(llvm::StringRef USR)
+: HashValue(llvm::SHA1::hash(arrayRefFromStringRef(USR))) {}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID) {
+  OS << toHex(llvm::toStringRef(ID.HashValue));
+  return OS;
 }
-} // namespace
 
-SymbolID::SymbolID(llvm::StringRef USR)
-: HashValue(llvm::SHA1::hash(toArrayRef(USR))) {}
+void operator>>(llvm::StringRef Str, SymbolID &ID) {
+  std::string HexString = fromHex(Str);
+  assert(HexString.size() == 20);
+  std::copy(HexString.begin(), HexString.end(), ID.HashValue.begin());
+}
 
 SymbolSlab::const_iterator SymbolSlab::begin() const { return Symbols.begin(); 
}
 

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=320694&r1=320693&r2=320694&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Dec 14 04:17:14 2017
@@ -54,10 +54,22 @@ private:
   friend llvm::hash_code hash_value(const SymbolID &ID) {
 return hash_value(ArrayRef(ID.HashValue));
   }
+  friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+   const SymbolID &ID);
+  friend void operator>>(llvm::StringRef Str, SymbolID &ID);
 
   std::array HashValue;
 };
 
+// Write SymbolID into the given stream. SymbolID is encoded as a 40-bytes
+// hex string.
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID);
+
+// Construct SymbolID from a hex string.
+// The HexStr is required to be a 40-bytes hex string, which is encoded from 
the
+// "<<" operator.
+void operator>>(llvm::StringRef HexStr, SymbolID &ID);
+
 // The class presents a C++ symbol, e.g. class, function.
 //
 // FIXME: instead of having own copy fields for each symbol, we can share

Added: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=320694&view=auto
==
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (added)
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Thu Dec 14 04:17:14 2017
@@ -0,0 +1,148 @@
+//===--- SymbolYAML.cpp --*- 
C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "SymbolYAML.h"
+
+#include "Index.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Errc.h"
+
+LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(clang::clangd::Symbol)
+
+namespace llvm {
+namespace ya

[clang-tools-extra] r321106 - [clangd] Don't use the optional "severity" when comparing Diagnostic.

2017-12-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Dec 19 12:52:56 2017
New Revision: 321106

URL: http://llvm.org/viewvc/llvm-project?rev=321106&view=rev
Log:
[clangd] Don't use the optional "severity" when comparing Diagnostic.

Summary:
We use Diagnostic as a key to find the corresponding FixIt when we do
the "apply-fix", but the "severity" field could be omitted, in some cases,
the codeAction request sent from LSP clients (e.g. VScode) doesn't include the
`severity` field, which makes clangd fail to find the FixIt.

Test the following code in VScode, before the fix, no FixIt shown.

```
void main() {}
^~~~
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=321106&r1=321105&r2=321106&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Dec 19 12:52:56 2017
@@ -88,7 +88,8 @@ private:
   bool IsDone = false;
 
   std::mutex FixItsMutex;
-  typedef std::map>
+  typedef std::map,
+   LSPDiagnosticCompare>
   DiagnosticToReplacementMap;
   /// Caches FixIts per file and diagnostics
   llvm::StringMap FixItsMap;

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=321106&r1=321105&r2=321106&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Tue Dec 19 12:52:56 2017
@@ -322,14 +322,15 @@ struct Diagnostic {
 
   /// The diagnostic's message.
   std::string message;
-
-  friend bool operator==(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) ==
-   std::tie(RHS.range, RHS.severity, RHS.message);
-  }
-  friend bool operator<(const Diagnostic &LHS, const Diagnostic &RHS) {
-return std::tie(LHS.range, LHS.severity, LHS.message) <
-   std::tie(RHS.range, RHS.severity, RHS.message);
+};
+/// A LSP-specific comparator used to find diagnostic in a container like
+/// std:map.
+/// We only use the required fields of Diagnostic to do the comparsion to avoid
+/// any regression issues from LSP clients (e.g. VScode), see
+/// https://git.io/vbr29
+struct LSPDiagnosticCompare {
+  bool operator()(const Diagnostic& LHS, const Diagnostic& RHS) const {
+return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
   }
 };
 bool fromJSON(const json::Expr &, Diagnostic &);


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


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

2017-12-21 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Dec 21 00:45:18 2017
New Revision: 321252

URL: http://llvm.org/viewvc/llvm-project?rev=321252&view=rev
Log:
[clangd] Use the clang-tools-extra as the official repo for `vscode-clangd` 
extension.

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

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

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

Reviewers: sammccall, krasimir

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/LICENSE
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md
Removed:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.txt
Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Added: clang-tools-extra/trunk/clangd/clients/clangd-vscode/LICENSE
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/LICENSE?rev=321252&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/LICENSE (added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/LICENSE Thu Dec 21 
00:45:18 2017
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 The LLVM Developers
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

Added: clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md?rev=321252&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md (added)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md Thu Dec 21 
00:45:18 2017
@@ -0,0 +1,51 @@
+# vscode-clangd
+
+Provides C/C++ language IDE features for VS Code using 
[clangd](https://clang.llvm.org/extra/clangd.html).
+
+## Usage
+
+`vscode-clangd` provides the features designated by the [Language Server
+Protocol](https://github.com/Microsoft/language-server-protocol), such as
+code completion, code formatting and goto definition.
+
+**Note**: `clangd` is under heavy development, not all LSP features are
+implemented. See [Current 
Status](https://clang.llvm.org/extra/clangd.html#current-status)
+for details.
+
+To use `vscode-clangd` extension in VS Code, you need to install 
`vscode-clangd`
+from VS Code extension marketplace.
+
+`vscode-clangd` will attempt to find the `clangd` binary on your `PATH`.
+Alternatively, the `clangd` executable can be specified in your VS Code
+`settings.json` file:
+
+```json
+{
+"clangd.path": "/absolute/path/to/clangd"
+}
+```
+
+To obtain `clangd` binary, please see the [installing 
Clangd](https://clang.llvm.org/extra/clangd.html#installing-clangd).
+
+## Development
+
+A guide of developing `vscode-clangd` extension.
+
+### Requirements
+
+* VS Code
+* node.js and npm
+
+### Steps
+
+1. Make sure you disable the installed `vscode-clangd` extension in VS Code.
+2. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
+point to the binary.
+3. In order to start a development instance of VS code extended with this, run:
+
+```bash
+   $ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
+   $ npm install
+   $ code .
+   # When VS Code starts, press .
+```

Removed: clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.txt?rev=321251&view=auto
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vsc

[clang-tools-extra] r321358 - [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Dec 22 06:38:05 2017
New Revision: 321358

URL: http://llvm.org/viewvc/llvm-project?rev=321358&view=rev
Log:
[clangd] Add a tool to build YAML-format global symbols.

Summary:
The tools is used to generate global symbols for clangd (global code 
completion),
The format is YAML, which is only for **experiment**.

Usage:
./bin/global-symbol-builder  > global-symbols.yaml

TEST:
used the tool to generate global symbols for LLVM (~72MB).

Reviewers: sammccall

Reviewed By: sammccall

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

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

Added:
clang-tools-extra/trunk/clangd/global-symbol-builder/
clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=321358&r1=321357&r2=321358&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Dec 22 06:38:05 2017
@@ -47,3 +47,4 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_
   add_subdirectory(fuzzer)
 endif()
 add_subdirectory(tool)
+add_subdirectory(global-symbol-builder)

Added: clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt?rev=321358&view=auto
==
--- clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt Fri Dec 
22 06:38:05 2017
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+set(LLVM_LINK_COMPONENTS
+Support
+)
+
+add_clang_executable(global-symbol-builder
+  GlobalSymbolBuilderMain.cpp
+  )
+
+target_link_libraries(global-symbol-builder
+  PRIVATE
+  clangAST
+  clangIndex
+  clangDaemon
+  clangBasic
+  clangFrontend
+  clangTooling
+)

Added: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=321358&view=auto
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (added)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Fri Dec 22 06:38:05 2017
@@ -0,0 +1,110 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- 
C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, 
nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "ch

[clang-tools-extra] r322067 - [clangd] Catch more symbols in SymbolCollector.

2018-01-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan  9 02:44:09 2018
New Revision: 322067

URL: http://llvm.org/viewvc/llvm-project?rev=322067&view=rev
Log:
[clangd] Catch more symbols in SymbolCollector.

Summary:
We currently only collect external-linkage symbols in the collector,
which results in missing some typical symbols (like no-linkage type alias 
symbols).

This patch relaxes the constraint a bit to allow collecting more symbols.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=322067&r1=322066&r2=322067&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Tue Jan  9 
02:44:09 2018
@@ -80,8 +80,15 @@ bool SymbolCollector::handleDeclOccurenc
 return true;
 
   if (const NamedDecl *ND = llvm::dyn_cast(D)) {
-// FIXME: Should we include the internal linkage symbols?
-if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
+// FIXME: figure out a way to handle internal linkage symbols (e.g. static
+// variables, function) defined in the .cc files. Also we skip the symbols
+// in anonymous namespace as the qualifier names of these symbols are like
+// `foobar`, which need a special handling.
+// In real world projects, we have a relatively large set of header files
+// that define static variables (like "static const int A = 1;"), we still
+// want to collect these symbols, although they cause potential ODR
+// violations.
+if (ND->isInAnonymousNamespace())
   return true;
 
 llvm::SmallString<128> USR;

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=322067&r1=322066&r2=322067&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Tue Jan  
9 02:44:09 2018
@@ -29,6 +29,7 @@
 using testing::Eq;
 using testing::Field;
 using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 // GMock helpers for matching Symbol.
 MATCHER_P(QName, Name, "") {
@@ -97,16 +98,53 @@ TEST_F(SymbolCollectorTest, CollectSymbo
 };
 void f1();
 inline void f2() {}
+static const int KInt = 2;
+const char* kStr = "123";
   )";
   const std::string Main = R"(
 namespace {
 void ff() {} // ignore
 }
+
 void f1() {}
+
+namespace foo {
+// Type alias
+typedef int int32;
+using int32_t = int32;
+
+// Variable
+int v1;
+
+// Namespace
+namespace bar {
+int v2;
+}
+// Namespace alias
+namespace baz = bar;
+
+// FIXME: using declaration is not supported as the IndexAction will ignore
+// implicit declarations (the implicit using shadow declaration) by 
default,
+// and there is no way to customize this behavior at the moment.
+using bar::v2;
+} // namespace foo
   )";
   runSymbolCollector(Header, Main);
-  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Foo::f"),
-QName("f1"), QName("f2")));
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAreArray(
+  {QName("Foo"),
+   QName("Foo::f"),
+   QName("f1"),
+   QName("f2"),
+   QName("KInt"),
+   QName("kStr"),
+   QName("foo"),
+   QName("foo::bar"),
+   QName("foo::int32"),
+   QName("foo::int32_t"),
+   QName("foo::v1"),
+   QName("foo::bar::v2"),
+   QName("foo::baz")}));
 }
 
 TEST_F(SymbolCollectorTest, YAMLConversions) {


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


[clang-tools-extra] r322191 - [clangd] Add static index for the global code completion.

2018-01-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jan 10 06:44:34 2018
New Revision: 322191

URL: http://llvm.org/viewvc/llvm-project?rev=322191&view=rev
Log:
[clangd] Add static index for the global code completion.

Summary:
Use the YAML-format symbols (generated by the global-symbol-builder tool) to
do the global code completion.
It is **experimental** only , but it allows us to experience global code
completion on a relatively small project.

Tested with LLVM project.

Reviewers: sammccall, ioeric

Reviewed By: sammccall, ioeric

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=322191&r1=322190&r2=322191&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jan 10 06:44:34 2018
@@ -283,10 +283,12 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  const clangd::CodeCompleteOptions &CCOpts,
  llvm::Optional ResourceDir,
  llvm::Optional CompileCommandsDir,
- bool BuildDynamicSymbolIndex)
+ bool BuildDynamicSymbolIndex,
+ SymbolIndex *StaticIdx)
 : Out(Out), CDB(std::move(CompileCommandsDir)), CCOpts(CCOpts),
   Server(CDB, /*DiagConsumer=*/*this, FSProvider, AsyncThreadsCount,
- StorePreamblesInMemory, BuildDynamicSymbolIndex, ResourceDir) {}
+ StorePreamblesInMemory, BuildDynamicSymbolIndex, StaticIdx,
+ ResourceDir) {}
 
 bool ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=322191&r1=322190&r2=322191&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Jan 10 06:44:34 2018
@@ -22,6 +22,7 @@ namespace clang {
 namespace clangd {
 
 class JSONOutput;
+class SymbolIndex;
 
 /// This class provides implementation of an LSP server, glueing the JSON
 /// dispatch and ClangdServer together.
@@ -35,7 +36,8 @@ public:
   const clangd::CodeCompleteOptions &CCOpts,
   llvm::Optional ResourceDir,
   llvm::Optional CompileCommandsDir,
-  bool BuildDynamicSymbolIndex);
+  bool BuildDynamicSymbolIndex,
+  SymbolIndex *StaticIdx = nullptr);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be
   /// opened in binary mode. Output will be written using Out variable passed 
to

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=322191&r1=322190&r2=322191&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jan 10 06:44:34 2018
@@ -134,10 +134,11 @@ ClangdServer::ClangdServer(GlobalCompila
FileSystemProvider &FSProvider,
unsigned AsyncThreadsCount,
bool StorePreamblesInMemory,
-   bool BuildDynamicSymbolIndex,
+   bool BuildDynamicSymbolIndex, SymbolIndex 
*StaticIdx,
llvm::Optional ResourceDir)
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
   FileIdx(BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
+  StaticIdx(StaticIdx),
   // Pass a callback into `Units` to extract symbols from a newly parsed
   // file and rebuild the file index synchronously each time an AST is
   // parsed.
@@ -251,6 +252,8 @@ void ClangdServer::codeComplete(
   auto CodeCompleteOpts = Opts;
   if (FileIdx)
 CodeCompleteOpts.Index = FileIdx.get();
+  if (StaticIdx)
+CodeCompleteOpts.StaticIndex = StaticIdx;
 
  

[clang-tools-extra] r326778 - [clangd] Fix -Wpedantic warning, NFC.

2018-03-06 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Mar  6 04:56:18 2018
New Revision: 326778

URL: http://llvm.org/viewvc/llvm-project?rev=326778&view=rev
Log:
[clangd] Fix -Wpedantic warning, NFC.

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=326778&r1=326777&r2=326778&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Mar  6 04:56:18 2018
@@ -320,7 +320,7 @@ static llvm::Expected toHead
   if (!Resolved)
 return Resolved.takeError();
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
-};
+}
 
 Expected
 ClangdServer::insertInclude(PathRef File, StringRef Code,


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


[clang-tools-extra] r326799 - [clang-tidy] Fix one corner case in make-unique check.

2018-03-06 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Mar  6 06:34:35 2018
New Revision: 326799

URL: http://llvm.org/viewvc/llvm-project?rev=326799&view=rev
Log:
[clang-tidy] Fix one corner case in make-unique check.

Summary:
Previously, we tried to cover all "std::initializer_list" implicit conversion
cases in the code, but there are some corner cases that not covered (see
newly-added test in the patch).

Sipping all implicit AST nodes is a better way to filter out all these cases.

Reviewers: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=326799&r1=326798&r2=326799&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Mar  
6 06:34:35 2018
@@ -295,16 +295,8 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
   }
   return false;
 };
-// Check the implicit conversion from the std::initializer_list type to
-// a class type.
-if (IsStdInitListInitConstructExpr(Arg))
+if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
   return false;
-// The Arg can be a CXXBindTemporaryExpr, checking its underlying
-// construct expr.
-if (const auto * CTE = dyn_cast(Arg)) {
-  if (IsStdInitListInitConstructExpr(CTE->getSubExpr()))
-return false;
-}
   }
 }
 if (ArraySizeExpr.empty()) {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=326799&r1=326798&r2=326799&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Tue Mar  
6 06:34:35 2018
@@ -50,6 +50,7 @@ struct G {
 
 struct H {
   H(std::vector);
+  H(std::vector &, double);
   H(MyVector, int);
 };
 
@@ -344,6 +345,13 @@ void initialization(int T, Base b) {
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
   // CHECK-FIXES: PH2.reset(new H({1, 2, 3}, 1));
 
+  std::unique_ptr PH3 = std::unique_ptr(new H({1, 2, 3}, 1.0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PH3 = std::unique_ptr(new H({1, 2, 3}, 
1.0));
+  PH3.reset(new H({1, 2, 3}, 1.0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PH3.reset(new H({1, 2, 3}, 1.0));
+
   std::unique_ptr PI1 = std::unique_ptr(new I(G({1, 2, 3})));
   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PI1 = std::make_unique(G({1, 2, 3}));


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


[clang-tools-extra] r327023 - [clangd] Early return for #include goto definition.

2018-03-08 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Mar  8 08:28:12 2018
New Revision: 327023

URL: http://llvm.org/viewvc/llvm-project?rev=327023&view=rev
Log:
[clangd] Early return for #include goto definition.

Summary: This would save cost of walking over the AST, NFC.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, ioeric

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

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

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327023&r1=327022&r2=327023&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Mar  8 08:28:12 2018
@@ -174,6 +174,18 @@ std::vector findDefinitions(Pa
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto &IncludeLoc : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@ std::vector findDefinitions(Pa
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@ std::vector findDefinitions(Pa
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto &IncludeLoc : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 


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


[clang-tools-extra] r327111 - [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith

2018-03-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Mar  9 02:47:14 2018
New Revision: 327111

URL: http://llvm.org/viewvc/llvm-project?rev=327111&view=rev
Log:
[clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith

Patch by Niko Weh!

Reviewers: hokein

Subscribers: klimek, cfe-commits, ioeric, ilya-biryukov, ahedberg

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

Added:
clang-tools-extra/trunk/clang-tidy/abseil/
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-string-find-startswith.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=327111&r1=327110&r2=327111&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Mar  9 02:47:14 2018
@@ -27,6 +27,7 @@ add_clang_library(clangTidy
   )
 
 add_subdirectory(android)
+add_subdirectory(abseil)
 add_subdirectory(boost)
 add_subdirectory(bugprone)
 add_subdirectory(cert)

Added: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=327111&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Fri Mar  9 
02:47:14 2018
@@ -0,0 +1,38 @@
+//===--- AbseilTidyModule.cpp - clang-tidy 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "StringFindStartswithCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+class AbseilModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"abseil-string-find-startswith");
+  }
+};
+
+// Register the AbseilModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("abseil-module",
+"Add Abseil checks.");
+
+} // namespace abseil
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the AbseilModule.
+volatile int AbseilModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=327111&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Fri Mar  9 
02:47:14 2018
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyAbseilModule
+  AbseilTidyModule.cpp
+  StringFindStartswithCheck.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp?rev=327111&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp Fri 
Mar  9 02:47:14 2018
@@ -0,0 +1,133 @@
+//===--- StringFindStartswithCheck.cc - clang-tidy---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--

[clang-tools-extra] r327129 - [clangd] Use identifier range as the definition range.

2018-03-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Mar  9 06:00:34 2018
New Revision: 327129

URL: http://llvm.org/viewvc/llvm-project?rev=327129&view=rev
Log:
[clangd] Use identifier range as the definition range.

Summary: This also matches the range in symbol index.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/clangd/AST.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Added: clang-tools-extra/trunk/clangd/AST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=327129&view=auto
==
--- clang-tools-extra/trunk/clangd/AST.cpp (added)
+++ clang-tools-extra/trunk/clangd/AST.cpp Fri Mar  9 06:00:34 2018
@@ -0,0 +1,42 @@
+//===--- AST.cpp - Utility AST functions  ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AST.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/SourceManager.h"
+
+namespace clang {
+namespace clangd {
+using namespace llvm;
+
+SourceLocation findNameLoc(const clang::Decl* D) {
+  const auto& SM = D->getASTContext().getSourceManager();
+  // FIXME: Revisit the strategy, the heuristic is limitted when handling
+  // macros, we should use the location where the whole definition occurs.
+  SourceLocation SpellingLoc = SM.getSpellingLoc(D->getLocation());
+  if (D->getLocation().isMacroID()) {
+std::string PrintLoc = SpellingLoc.printToString(SM);
+if (llvm::StringRef(PrintLoc).startswith("")) {
+  // We use the expansion location for the following symbols, as spelling
+  // locations of these symbols are not interesting to us:
+  //   * symbols formed via macro concatenation, the spelling location will
+  // be ""
+  //   * symbols controlled and defined by a compile command-line option
+  // `-DName=foo`, the spelling location will be "".
+  SpellingLoc = SM.getExpansionRange(D->getLocation()).first;
+}
+  }
+  return SpellingLoc;
+}
+
+} // namespace clangd
+} // namespace clang

Added: clang-tools-extra/trunk/clangd/AST.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=327129&view=auto
==
--- clang-tools-extra/trunk/clangd/AST.h (added)
+++ clang-tools-extra/trunk/clangd/AST.h Fri Mar  9 06:00:34 2018
@@ -0,0 +1,34 @@
+//===--- AST.h - Utility AST functions  -*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Various code that examines C++ source code using AST.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
+
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+class SourceManager;
+class Decl;
+
+namespace clangd {
+
+/// Find the identifier source location of the given D.
+///
+/// The returned location is usually the spelling location where the name of 
the
+/// decl occurs in the code.
+SourceLocation findNameLoc(const clang::Decl* D);
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=327129&r1=327128&r2=327129&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Mar  9 06:00:34 2018
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_library(clangDaemon
+  AST.cpp
   ClangdLSPServer.cpp
   ClangdServer.cpp
   ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327129&r1=327128&r2=327129&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp 

[clang-tools-extra] r327131 - [clangd] Fix failing lit test.

2018-03-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Mar  9 06:16:46 2018
New Revision: 327131

URL: http://llvm.org/viewvc/llvm-project?rev=327131&view=rev
Log:
[clangd] Fix failing lit test.

This test is missed in r327129.

Modified:
clang-tools-extra/trunk/test/clangd/xrefs.test

Modified: clang-tools-extra/trunk/test/clangd/xrefs.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/xrefs.test?rev=327131&r1=327130&r2=327131&view=diff
==
--- clang-tools-extra/trunk/test/clangd/xrefs.test (original)
+++ clang-tools-extra/trunk/test/clangd/xrefs.test Fri Mar  9 06:16:46 2018
@@ -10,11 +10,11 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
-# CHECK-NEXT:  "character": 9,
+# CHECK-NEXT:  "character": 5,
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:},
 # CHECK-NEXT:"start": {
-# CHECK-NEXT:  "character": 0,
+# CHECK-NEXT:  "character": 4,
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:}
 # CHECK-NEXT:  },


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


[clang-tools-extra] r327293 - [clangd] Fix diagnostic errors in the test code, NFC.

2018-03-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Mar 12 09:49:24 2018
New Revision: 327293

URL: http://llvm.org/viewvc/llvm-project?rev=327293&view=rev
Log:
[clangd] Fix diagnostic errors in the test code, NFC.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, ioeric

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

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

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=327293&r1=327292&r2=327293&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Mon Mar 12 09:49:24 
2018
@@ -596,7 +596,9 @@ TEST(GoToInclude, All) {
   auto FooH = testPath("foo.h");
   auto FooHUri = URIForFile{FooH};
 
-  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  const char *HeaderContents = R"cpp([[]]#pragma once
+ int a;
+ )cpp";
   Annotations HeaderAnnotations(HeaderContents);
   FS.Files[FooH] = HeaderAnnotations.code();
 


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


[clang-tools-extra] r327386 - [clangd] Remove extra ";", NFC.

2018-03-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Mar 13 05:26:28 2018
New Revision: 327386

URL: http://llvm.org/viewvc/llvm-project?rev=327386&view=rev
Log:
[clangd] Remove extra ";", NFC.

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

Modified: clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp?rev=327386&r1=327385&r2=327386&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp Tue Mar 13 
05:26:28 2018
@@ -90,7 +90,7 @@ Position pos(int line, int character) {
   Res.line = line;
   Res.character = character;
   return Res;
-};
+}
 
 /// Matches diagnostic that has exactly one fix with the same range and message
 /// as the diagnostic itself.


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


[clang-tools-extra] r327387 - [clangd] Fix irrelevant declaratations in goto definition (on macros).

2018-03-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Mar 13 05:30:59 2018
New Revision: 327387

URL: http://llvm.org/viewvc/llvm-project?rev=327387&view=rev
Log:
[clangd] Fix irrelevant declaratations in goto definition (on macros).

Summary:
DeclrationAndMacrosFinder will find some declarations (not macro!) that are
referened inside the macro somehow, isSearchedLocation() is not sufficient, we
don't know whether the searched source location is macro or not.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327387&r1=327386&r2=327387&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Mar 13 05:30:59 2018
@@ -127,6 +127,16 @@ private:
 MacroInfo *MacroInf = MacroDef.getMacroInfo();
 if (MacroInf) {
   MacroInfos.push_back(MacroDecl{IdentifierInfo->getName(), MacroInf});
+  // Clear all collected delcarations if this is a macro search.
+  //
+  // In theory, there should be no declarataions being collected when 
we
+  // search a source location that refers to a macro.
+  // The occurrence location returned by `handleDeclOccurence` is
+  // limited (FID, Offset are from expansion location), we will collect
+  // all declarations inside the macro.
+  //
+  // FIXME: Avoid adding decls from inside macros in 
handlDeclOccurence.
+  Decls.clear();
 }
   }
 }

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=327387&r1=327386&r2=327387&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Tue Mar 13 05:30:59 
2018
@@ -213,6 +213,15 @@ TEST(GoToDefinition, All) {
 #undef macro
   )cpp",
 
+  R"cpp(// Macro
+   class TTT { public: int a; };
+   #define [[FF(S) if (int b = S.a) {}]]
+   void f() {
+ TTT t;
+ F^F(t);
+   }
+  )cpp",
+
   R"cpp(// Forward class declaration
 class Foo;
 class [[Foo]] {};


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


[clang-tools-extra] r327401 - [clangd] Use the macro name range as the definition range.

2018-03-13 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Mar 13 07:31:31 2018
New Revision: 327401

URL: http://llvm.org/viewvc/llvm-project?rev=327401&view=rev
Log:
[clangd] Use the macro name range as the definition range.

Summary: This also aligns with the behavior of declarations.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327401&r1=327400&r2=327401&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Mar 13 07:31:31 2018
@@ -219,9 +219,8 @@ std::vector findDefinitions(Pa
   }
 
   for (auto Item : MacroInfos) {
-SourceRange SR(Item.Info->getDefinitionLoc(),
-   Item.Info->getDefinitionEndLoc());
-auto L = makeLocation(AST, SR);
+auto Loc = Item.Info->getDefinitionLoc();
+auto L = makeLocation(AST, SourceRange(Loc, Loc));
 if (L)
   Result.push_back(*L);
   }

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=327401&r1=327400&r2=327401&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Tue Mar 13 07:31:31 
2018
@@ -207,7 +207,7 @@ TEST(GoToDefinition, All) {
 
   R"cpp(// Macro
 #define MACRO 0
-#define [[MACRO 1]]
+#define [[MACRO]] 1
 int main() { return ^MACRO; }
 #define MACRO 2
 #undef macro
@@ -215,7 +215,7 @@ TEST(GoToDefinition, All) {
 
   R"cpp(// Macro
class TTT { public: int a; };
-   #define [[FF(S) if (int b = S.a) {}]]
+   #define [[FF]](S) if (int b = S.a) {}
void f() {
  TTT t;
  F^F(t);


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


[clang-tools-extra] r327887 - [clang-move] Fix the failing test caused by changes in clang-format.

2018-03-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Mar 19 12:13:03 2018
New Revision: 327887

URL: http://llvm.org/viewvc/llvm-project?rev=327887&view=rev
Log:
[clang-move] Fix the failing test caused by changes in clang-format.

Modified:
clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp

Modified: clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp?rev=327887&r1=327886&r2=327887&view=diff
==
--- clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp Mon Mar 
19 12:13:03 2018
@@ -412,7 +412,6 @@
 // CHECK-NEW-CPP-NEXT: }
 // CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: void Fun1() { HelperFun5(); }
-// CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: } // namespace a
 // CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: namespace b {


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


[clang-tools-extra] r333882 - [clangd] Remove the dead offset fields in Symbol.

2018-06-04 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Jun  4 03:43:59 2018
New Revision: 333882

URL: http://llvm.org/viewvc/llvm-project?rev=333882&view=rev
Log:
[clangd] Remove the dead offset fields in Symbol.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=333882&r1=333881&r2=333882&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Jun  4 03:43:59 2018
@@ -34,12 +34,6 @@ struct SymbolLocation {
 
   // The URI of the source file where a symbol occurs.
   llvm::StringRef FileURI;
-  // The 0-based offsets of the symbol from the beginning of the source file,
-  // using half-open range, [StartOffset, EndOffset).
-  // DO NOT use these fields, as they will be removed immediately.
-  // FIXME(hokein): remove these fields in favor of Position.
-  unsigned StartOffset = 0;
-  unsigned EndOffset = 0;
 
   /// The symbol range, using half-open range [Start, End).
   Position Start;


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


[clang-tools-extra] r334176 - [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Jun  7 01:49:55 2018
New Revision: 334176

URL: http://llvm.org/viewvc/llvm-project?rev=334176&view=rev
Log:
[clangd] Fix using the incorrect Index for go-to-definition.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=334176&r1=334175&r2=334176&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Jun  7 01:49:55 2018
@@ -302,7 +302,7 @@ void ClangdServer::findDefinitions(PathR
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));


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


[clang-tools-extra] r334270 - [clang-tidy] Improve string type matcher for abseil-string-find-starts-with check.

2018-06-08 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jun  8 01:19:22 2018
New Revision: 334270

URL: http://llvm.org/viewvc/llvm-project?rev=334270&view=rev
Log:
[clang-tidy] Improve string type matcher for abseil-string-find-starts-with 
check.

Summary:
This patch improves the check to match the desugared "string" type (so that it
can handle custom-implemented string classes), see the newly-added test.

Reviewers: alexfh

Subscribers: klimek, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp?rev=334270&r1=334269&r2=334270&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp Fri 
Jun  8 01:19:22 2018
@@ -36,10 +36,13 @@ void StringFindStartswithCheck::register
   auto ZeroLiteral = integerLiteral(equals(0));
   auto StringClassMatcher = cxxRecordDecl(hasAnyName(SmallVector(
   StringLikeClasses.begin(), StringLikeClasses.end(;
+  auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
 
   auto StringFind = cxxMemberCallExpr(
   // .find()-call on a string...
-  callee(cxxMethodDecl(hasName("find"), ofClass(StringClassMatcher))),
+  callee(cxxMethodDecl(hasName("find"))),
+  on(hasType(StringType)),
   // ... with some search expression ...
   hasArgument(0, expr().bind("needle")),
   // ... and either "0" as second argument or the default argument (also 
0).

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp?rev=334270&r1=334269&r2=334270&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-string-find-startswith.cpp 
Fri Jun  8 01:19:22 2018
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-string-find-startswith %t
+// RUN: %check_clang_tidy %s abseil-string-find-startswith %t -- \
+// RUN:   -config="{CheckOptions: [{key: 
'abseil-string-find-startswith.StringLikeClasses', value: 
'::std::basic_string;::basic_string'}]}" \
+// RUN:   -- -std=c++11
 
 namespace std {
 template  class allocator {};
@@ -15,14 +17,23 @@ struct basic_string {
 };
 typedef basic_string string;
 typedef basic_string wstring;
+
+struct cxx_string {
+  int find(const char *s, int pos = 0);
+};
 } // namespace std
 
+struct basic_string : public std::cxx_string {
+  basic_string();
+};
+typedef basic_string global_string;
+
 std::string foo(std::string);
 std::string bar();
 
 #define A_MACRO(x, y) ((x) == (y))
 
-void tests(std::string s) {
+void tests(std::string s, global_string s2) {
   s.find("a") == 0;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of 
find() == 0 [abseil-string-find-startswith]
   // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, "a");{{$}}
@@ -47,6 +58,10 @@ void tests(std::string s) {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
   // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "a");{{$}}
 
+  s2.find("a") == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s2, "a");{{$}}
+
   // expressions that don't trigger the check are here.
   A_MACRO(s.find("a"), 0);
   s.find("a", 1) == 0;


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


[clang-tools-extra] r334812 - [clangd] Fix buildbot error.

2018-06-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jun 15 02:32:36 2018
New Revision: 334812

URL: http://llvm.org/viewvc/llvm-project?rev=334812&view=rev
Log:
[clangd] Fix buildbot error.

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=334812&r1=334811&r2=334812&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jun 15 02:32:36 2018
@@ -858,7 +858,7 @@ public:
 // calculate the file proximity, which would capture include/ and src/
 // project setup where headers and implementations are not in the same
 // directory.
-FileProximityMatch({FileName}) {}
+FileProximityMatch(ArrayRef({FileName})) {}
 
   CompletionList run(const SemaCompleteInput &SemaCCInput) && {
 trace::Span Tracer("CodeCompleteFlow");


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


[clang-tools-extra] r344054 - [clangd] Fix an accident change in r342999.

2018-10-09 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct  9 08:16:14 2018
New Revision: 344054

URL: http://llvm.org/viewvc/llvm-project?rev=344054&view=rev
Log:
[clangd] Fix an accident change in r342999.

Modified:
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp?rev=344054&r1=344053&r2=344054&view=diff
==
--- clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp Tue Oct  9 
08:16:14 2018
@@ -286,7 +286,7 @@ std::string toYAML(const Symbol &S) {
 llvm::raw_string_ostream OS(Buf);
 llvm::yaml::Output Yout(OS);
 Symbol Sym = S; // copy: Yout<< requires mutability.
-OS << Sym;
+Yout << Sym;
   }
   return Buf;
 }


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


[clang-tools-extra] r344330 - [clangd] Support hover on "aut^o *".

2018-10-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 12 03:11:02 2018
New Revision: 344330

URL: http://llvm.org/viewvc/llvm-project?rev=344330&view=rev
Log:
[clangd] Support hover on "aut^o *".

Reviewers: kadircet

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

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=344330&r1=344329&r2=344330&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Oct 12 03:11:02 2018
@@ -579,20 +579,28 @@ public:
 
   llvm::Optional getDeducedType() { return DeducedType; }
 
+  // Remove the surrounding Reference or Pointer type of the given type T.
+  QualType UnwrapReferenceOrPointer(QualType T) {
+// "auto &" is represented as a ReferenceType containing an AutoType
+if (const ReferenceType *RT = dyn_cast(T.getTypePtr()))
+  return RT->getPointeeType();
+// "auto *" is represented as a PointerType containing an AutoType
+if (const PointerType *PT = dyn_cast(T.getTypePtr()))
+  return PT->getPointeeType();
+return T;
+  }
+
   // Handle auto initializers:
   //- auto i = 1;
   //- decltype(auto) i = 1;
   //- auto& i = 1;
+  //- auto* i = &a;
   bool VisitDeclaratorDecl(DeclaratorDecl *D) {
 if (!D->getTypeSourceInfo() ||
 D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
   return true;
 
-auto DeclT = D->getType();
-// "auto &" is represented as a ReferenceType containing an AutoType
-if (const ReferenceType *RT = dyn_cast(DeclT.getTypePtr()))
-  DeclT = RT->getPointeeType();
-
+auto DeclT = UnwrapReferenceOrPointer(D->getType());
 const AutoType *AT = dyn_cast(DeclT.getTypePtr());
 if (AT && !AT->getDeducedType().isNull()) {
   // For auto, use the underlying type because the const& would be
@@ -626,11 +634,7 @@ public:
 if (CurLoc != SearchedLocation)
   return true;
 
-auto T = D->getReturnType();
-// "auto &" is represented as a ReferenceType containing an AutoType.
-if (const ReferenceType *RT = dyn_cast(T.getTypePtr()))
-  T = RT->getPointeeType();
-
+auto T = UnwrapReferenceOrPointer(D->getReturnType());
 const AutoType *AT = dyn_cast(T.getTypePtr());
 if (AT && !AT->getDeducedType().isNull()) {
   DeducedType = T.getUnqualifiedType();

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=344330&r1=344329&r2=344330&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Oct 12 03:11:02 
2018
@@ -756,6 +756,15 @@ TEST(Hover, All) {
   "int",
   },
   {
+  R"cpp(// Simple initialization with auto*
+void foo() {
+  int a = 1;
+  ^auto* i = &a;
+}
+  )cpp",
+  "int",
+  },
+  {
   R"cpp(// Auto with initializer list.
 namespace std
 {
@@ -861,6 +870,16 @@ TEST(Hover, All) {
 }
   )cpp",
   "struct Bar",
+  },
+  {
+  R"cpp(// auto* in function return
+struct Bar {};
+^auto* test() {
+  Bar* bar;
+  return bar;
+}
+  )cpp",
+  "struct Bar",
   },
   {
   R"cpp(// const auto& in function return


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


[clang-tools-extra] r344507 - [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 04:46:26 2018
New Revision: 344507

URL: http://llvm.org/viewvc/llvm-project?rev=344507&view=rev
Log:
[clangd] Fix some references missing in dynamic index.

Summary:
Previously, SymbolCollector postfilters all references at the end to
find all references of interesting symbols.
It was incorrect when indxing main AST where we don't see locations
of symbol declarations and definitions in the main AST (as those are in
preamble AST).

The fix is to do earily check during collecting references.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=344507&r1=344506&r2=344507&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Oct 15 
04:46:26 2018
@@ -345,16 +345,20 @@ bool SymbolCollector::handleDeclOccurenc
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
-  if ((static_cast(Opts.RefFilter) & Roles) &&
-  SM.getFileID(SpellingLoc) == SM.getMainFileID())
-DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  bool CollectRef = static_cast(Opts.RefFilter) & Roles;
+  bool IsOnlyRef =
+  !(Roles & (static_cast(index::SymbolRole::Declaration) |
+ static_cast(index::SymbolRole::Definition)));
 
-  // Don't continue indexing if this is a mere reference.
-  if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
-Roles & static_cast(index::SymbolRole::Definition)))
+  if (IsOnlyRef && !CollectRef)
 return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
+  if (CollectRef && SM.getFileID(SpellingLoc) == SM.getMainFileID())
+DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  // Don't continue indexing if this is a mere reference.
+  if (IsOnlyRef)
+return true;
 
   auto ID = getSymbolID(ND);
   if (!ID)
@@ -476,17 +480,15 @@ void SymbolCollector::finish() {
 std::string MainURI = *MainFileURI;
 for (const auto &It : DeclRefs) {
   if (auto ID = getSymbolID(It.first)) {
-if (Symbols.find(*ID)) {
-  for (const auto &LocAndRole : It.second) {
-Ref R;
-auto Range =
-getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-R.Location.Start = Range.first;
-R.Location.End = Range.second;
-R.Location.FileURI = MainURI;
-R.Kind = toRefKind(LocAndRole.second);
-Refs.insert(*ID, R);
-  }
+for (const auto &LocAndRole : It.second) {
+  Ref R;
+  auto Range =
+  getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
+  R.Location.Start = Range.first;
+  R.Location.End = Range.second;
+  R.Location.FileURI = MainURI;
+  R.Kind = toRefKind(LocAndRole.second);
+  Refs.insert(*ID, R);
 }
   }
 }

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=344507&r1=344506&r2=344507&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Mon Oct 15 
04:46:26 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "Annotations.h"
+#include "AST.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -15,6 +16,7 @@
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -346,6 +348,55 @@ TEST(FileIndexTest, CollectMacros) {
   EXPECT_TRUE(SeenSymbol);
 }
 
+TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  Annotations Main(R"cpp(
+#include "foo.h"
+void f() {
+  [[Foo]] foo;
+}
+  )cpp");
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("foo.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(),

[clang-tools-extra] r344508 - [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 05:32:49 2018
New Revision: 344508

URL: http://llvm.org/viewvc/llvm-project?rev=344508&view=rev
Log:
[clangd] dump xrefs information in dexp tool.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt?rev=344508&r1=344507&r2=344508&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt Mon Oct 15 
05:32:49 2018
@@ -1,3 +1,5 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
 
 set(LLVM_LINK_COMPONENTS

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=344508&r1=344507&r2=344508&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Mon Oct 15 05:32:49 
2018
@@ -12,8 +12,9 @@
 //
 
//===--===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -52,6 +53,26 @@ void reportTime(StringRef Name, llvm::fu
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
+std::vector
+getSymbolIDsFromIndex(llvm::StringRef QualifiedName, const SymbolIndex *Index) 
{
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = clang::clangd::splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {Names.first};
+
+  Request.Query = Names.second;
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 // REPL commands inherit from Command and contain their options as members.
 // Creating a Command populates parser options, parseAndRun() resets them.
 class Command {
@@ -88,7 +109,6 @@ public:
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -139,19 +159,32 @@ class Lookup : public Command {
   cl::opt ID{
   "id",
   cl::Positional,
-  cl::Required,
   cl::desc("Symbol ID to look up (hex)"),
   };
+  cl::opt Name{
+  "name", cl::desc("Qualified name to look up."),
+  };
 
   void run() override {
-auto SID = clang::clangd::SymbolID::fromStr(ID);
-if (!SID) {
-  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
   return;
 }
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;
@@ -162,13 +195,62 @@ class Lookup : public Command {
   }
 };
 
+class Refs : public Command {
+  cl::opt ID{
+  "id", cl::Positional,
+  cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  cl::opt Name{
+  "name", cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt Filter{
+  "filter", cl::init(".*"),
+  cl::desc(
+  "Print all results from files matching this regular expression."),
+  };
+
+  void run() override {
+ 

[clang-tools-extra] r344510 - [clangd] Remove an unused include header, NFC.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 05:39:45 2018
New Revision: 344510

URL: http://llvm.org/viewvc/llvm-project?rev=344510&view=rev
Log:
[clangd] Remove an unused include header, NFC.

Modified:
clang-tools-extra/trunk/clangd/index/Merge.cpp

Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=344510&r1=344509&r2=344510&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Merge.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp Mon Oct 15 05:39:45 2018
@@ -13,7 +13,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 
 namespace clang {
 namespace clangd {


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


[clang-tools-extra] r344521 - [clangd] Add createIndex in dexp

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 08:12:40 2018
New Revision: 344521

URL: http://llvm.org/viewvc/llvm-project?rev=344521&view=rev
Log:
[clangd] Add createIndex in dexp

Summary:
This would allow easily injecting our internal customization.

Also updates the stale "symbol-collection-file" flag.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=344521&r1=344520&r2=344521&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Mon Oct 15 08:12:40 
2018
@@ -31,9 +31,9 @@ using namespace llvm;
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@ struct {
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@ int main(int argc, const char *argv[]) {
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 


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


[clang-tools-extra] r344678 - [clangd] Collect refs from headers.

2018-10-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 17 01:38:36 2018
New Revision: 344678

URL: http://llvm.org/viewvc/llvm-project?rev=344678&view=rev
Log:
[clangd] Collect refs from headers.

Summary:
Add a flag to SymbolCollector to collect refs fdrom headers.

Note that we collect refs from headers in static index, and we don't do it for
dynamic index because of the preamble (we skip function body in preamble,
collecting it will result incomplete results).

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=344678&r1=344677&r2=344678&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Wed Oct 17 01:38:36 
2018
@@ -66,8 +66,10 @@ createStaticIndexingAction(SymbolCollect
   Opts.CollectIncludePath = true;
   Opts.CountReferences = true;
   Opts.Origin = SymbolOrigin::Static;
-  if (RefsCallback != nullptr)
+  if (RefsCallback != nullptr) {
 Opts.RefFilter = RefKind::All;
+Opts.RefsInHeaders = true;
+  }
   auto Includes = llvm::make_unique();
   addSystemHeadersMapping(Includes.get());
   Opts.Includes = Includes.get();

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.h?rev=344678&r1=344677&r2=344678&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.h (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.h Wed Oct 17 01:38:36 2018
@@ -21,9 +21,8 @@ namespace clangd {
 // Only a subset of SymbolCollector::Options are respected:
 //   - include paths are always collected, and canonicalized appropriately
 //   - references are always counted
-//   - main-file refs are collected (if RefsCallback is non-null)
+//   - all references are collected (if RefsCallback is non-null)
 //   - the symbol origin is always Static
-// FIXME: refs from headers should also be collected.
 std::unique_ptr
 createStaticIndexingAction(SymbolCollector::Options Opts,
std::function SymbolsCallback,

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=344678&r1=344677&r2=344678&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed Oct 17 
01:38:36 2018
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Index/IndexSymbol.h"
@@ -354,7 +355,8 @@ bool SymbolCollector::handleDeclOccurenc
 return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
-  if (CollectRef && SM.getFileID(SpellingLoc) == SM.getMainFileID())
+  if (CollectRef &&
+  (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID()))
 DeclRefs[ND].emplace_back(SpellingLoc, Roles);
   // Don't continue indexing if this is a mere reference.
   if (IsOnlyRef)
@@ -474,26 +476,43 @@ void SymbolCollector::finish() {
   }
 
   const auto &SM = ASTCtx->getSourceManager();
-  auto* MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
+  llvm::DenseMap URICache;
+  auto GetURI = [&](FileID FID) -> llvm::Optional {
+auto Found = URICache.find(FID);
+if (Found == URICache.end()) {
+  // Ignore cases where we can not find a corresponding file entry
+  // for the loc, thoses are not interesting, e.g. symbols formed
+  // via macro concatenation.
+  if (auto *FileEntry = SM.getFileEntryForID(FID)) {
+auto FileURI = toURI(SM, FileEntry->getName(), Opts);
+if (!FileURI) {
+  log("Failed to create URI for file: {0}\n", FileEntry);
+  FileURI = ""; // reset to empty as we also want to cache this case.
+}
+Found = URICache.insert({FID, *FileURI}).first;
+  }
+}
+return Found->second;
+  };
 
-  if (auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts)) {
-std::string MainURI = *MainFileURI;
+  if (auto MainFileURI

[clang-tools-extra] r344679 - [clangd] Print numbers of symbols and refs as well when loading the

2018-10-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 17 01:48:04 2018
New Revision: 344679

URL: http://llvm.org/viewvc/llvm-project?rev=344679&view=rev
Log:
[clangd] Print numbers of symbols and refs as well when loading the
index.

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=344679&r1=344678&r2=344679&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Wed Oct 17 01:48:04 
2018
@@ -496,13 +496,18 @@ std::unique_ptr loadIndex(l
 }
   }
 
+  size_t SymSize = Symbols.size();
+  size_t RefSize = Refs.size();
   trace::Span Tracer("BuildIndex");
   auto Index =
   UseDex ? dex::Dex::build(std::move(Symbols), std::move(Refs), URISchemes)
  : MemIndex::build(std::move(Symbols), std::move(Refs));
-  vlog("Loaded {0} from {1} with estimated memory usage {2}",
+  vlog("Loaded {0} from {1} with estimated memory usage {2} bytes\n"
+   "  - number of symbos: {3}\n"
+   "  - number of refs: {4}\n",
UseDex ? "Dex" : "MemIndex", SymbolFilename,
-   Index->estimateMemoryUsage());
+   Index->estimateMemoryUsage(),
+   SymSize, RefSize);
   return Index;
 }
 


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


[clang-tools-extra] r344680 - [clangd] Fix buildbot failure.

2018-10-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 17 01:54:48 2018
New Revision: 344680

URL: http://llvm.org/viewvc/llvm-project?rev=344680&view=rev
Log:
[clangd] Fix buildbot failure.

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=344680&r1=344679&r2=344680&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed Oct 17 
01:54:48 2018
@@ -480,9 +480,6 @@ void SymbolCollector::finish() {
   auto GetURI = [&](FileID FID) -> llvm::Optional {
 auto Found = URICache.find(FID);
 if (Found == URICache.end()) {
-  // Ignore cases where we can not find a corresponding file entry
-  // for the loc, thoses are not interesting, e.g. symbols formed
-  // via macro concatenation.
   if (auto *FileEntry = SM.getFileEntryForID(FID)) {
 auto FileURI = toURI(SM, FileEntry->getName(), Opts);
 if (!FileURI) {
@@ -490,6 +487,11 @@ void SymbolCollector::finish() {
   FileURI = ""; // reset to empty as we also want to cache this case.
 }
 Found = URICache.insert({FID, *FileURI}).first;
+  } else {
+// Ignore cases where we can not find a corresponding file entry
+// for the loc, thoses are not interesting, e.g. symbols formed
+// via macro concatenation.
+return llvm::None;
   }
 }
 return Found->second;


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


[clang-tools-extra] r344733 - [clang-tidy] Ignore a case where the fix of make_unique check introduces side effect.

2018-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Oct 18 02:13:34 2018
New Revision: 344733

URL: http://llvm.org/viewvc/llvm-project?rev=344733&view=rev
Log:
[clang-tidy] Ignore a case where the fix of make_unique check introduces side 
effect.

Summary:
Previously, ptr.reset(new char[5]) will be replaced with `p =
make_unique(5)`, the fix has side effect -- doing
default initialization, it may cause performace regression (we are
bitten by this rececntly)

The check should be conservative for these cases.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=344733&r1=344732&r2=344733&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Thu Oct 
18 02:13:34 2018
@@ -121,6 +121,15 @@ void MakeSmartPtrCheck::check(const Matc
   if (New->getNumPlacementArgs() != 0)
 return;
 
+  // Be conservative for cases where we construct an array without any
+  // initalization.
+  // For example,
+  //P.reset(new int[5]) // check fix: P = make_unique(5)
+  //
+  // The fix of the check has side effect, it introduces default initialization
+  // which maybe unexpected and cause performance regression.
+  if (New->isArray() && !New->hasInitializer())
+return;
   if (Construct)
 checkConstruct(SM, Result.Context, Construct, Type, New);
   else if (Reset)

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=344733&r1=344732&r2=344733&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Thu Oct 
18 02:13:34 2018
@@ -403,18 +403,15 @@ void initialization(int T, Base b) {
   // CHECK-FIXES: FFs = std::make_unique(Num2);
 
   std::unique_ptr FI;
-  FI.reset(new int[5]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
-  // CHECK-FIXES: FI = std::make_unique(5);
-  FI.reset(new int[5]());
+  FI.reset(new int[5]()); // default initialization.
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
   // CHECK-FIXES: FI = std::make_unique(5);
+
+  // The check doesn't give warnings and fixes for cases where the original new
+  // expresion doesn't do any initialization.
+  FI.reset(new int[5]);
   FI.reset(new int[Num]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
-  // CHECK-FIXES: FI = std::make_unique(Num);
   FI.reset(new int[Num2]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
-  // CHECK-FIXES: FI = std::make_unique(Num2);
 }
 
 void aliases() {


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


[clang-tools-extra] r344735 - [clangd] Encode Line/Column as a 32-bits integer.

2018-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Oct 18 03:43:50 2018
New Revision: 344735

URL: http://llvm.org/viewvc/llvm-project?rev=344735&view=rev
Log:
[clangd] Encode Line/Column as a 32-bits integer.

Summary:
This would buy us more memory. Using a 32-bits integer is enough for
most human-readable source code (up to 4M lines and 4K columns).

Previsouly, we used 8 bytes for a position, now 4 bytes, it would save
us 8 bytes for each Ref and each Symbol instance.

For LLVM-project binary index file, we save ~13% memory.

| Before | After |
| 412MB  | 355MB |

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=344735&r1=344734&r2=344735&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Thu Oct 18 03:43:50 2018
@@ -140,10 +140,10 @@ getWorkspaceSymbols(StringRef Query, int
 Location L;
 L.uri = URIForFile((*Path));
 Position Start, End;
-Start.line = CD.Start.Line;
-Start.character = CD.Start.Column;
-End.line = CD.End.Line;
-End.character = CD.End.Column;
+Start.line = CD.Start.line();
+Start.character = CD.Start.column();
+End.line = CD.End.line();
+End.character = CD.End.column();
 L.range = {Start, End};
 SymbolKind SK = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind);
 std::string Scope = Sym.Scope;

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=344735&r1=344734&r2=344735&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Oct 18 03:43:50 2018
@@ -57,10 +57,10 @@ llvm::Optional toLSPLocation(c
   }
   Location LSPLoc;
   LSPLoc.uri = URIForFile(*Path);
-  LSPLoc.range.start.line = Loc.Start.Line;
-  LSPLoc.range.start.character = Loc.Start.Column;
-  LSPLoc.range.end.line = Loc.End.Line;
-  LSPLoc.range.end.character = Loc.End.Column;
+  LSPLoc.range.start.line = Loc.Start.line();
+  LSPLoc.range.start.character = Loc.Start.column();
+  LSPLoc.range.end.line = Loc.End.line();
+  LSPLoc.range.end.character = Loc.End.column();
   return LSPLoc;
 }
 

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=344735&r1=344734&r2=344735&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Oct 18 03:43:50 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "Index.h"
+#include "Logger.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
@@ -18,11 +19,30 @@ namespace clang {
 namespace clangd {
 using namespace llvm;
 
+constexpr uint32_t SymbolLocation::Position::MaxLine;
+constexpr uint32_t SymbolLocation::Position::MaxColumn;
+void SymbolLocation::Position::setLine(uint32_t L) {
+  if (L > MaxLine) {
+log("Set an overflowed Line {0}", L);
+Line = MaxLine;
+return;
+  }
+  Line = L;
+}
+void SymbolLocation::Position::setColumn(uint32_t Col) {
+  if (Col > MaxColumn) {
+log("Set an overflowed Column {0}", Col);
+Column = MaxColumn;
+return;
+  }
+  Column = Col;
+}
+
 raw_ostream &operator<<(raw_ostream &OS, const SymbolLocation &L) {
   if (!L)
 return OS << "(none)";
-  return OS << L.FileURI << "[" << L.Start.Line << ":" << L.Start.Column << "-"
-<< L.End.Line << ":" << L.End.Column << ")";
+  return OS << L.FileURI << "[" << L.Start.line() << ":" << L.Start.column()
+<< "-" << L.End.line() << ":" << L.End.column() << ")";
 }
 
 SymbolID::SymbolID(StringRef USR)

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=344735&r1=344734&r2=344735&view=diff
=

[clang-tools-extra] r344745 - [clangd] Clear the semantic of RefSlab::size.

2018-10-18 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Oct 18 08:33:20 2018
New Revision: 344745

URL: http://llvm.org/viewvc/llvm-project?rev=344745&view=rev
Log:
[clangd] Clear the semantic of RefSlab::size.

Summary:
The RefSlab::size can easily cause confusions, it returns the number of
different symbols, rahter than the number of all references.

- add numRefs() method and cache it, since calculating it everytime is 
nontrivial.
- clear misused places.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=344745&r1=344744&r2=344745&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Oct 18 08:33:20 2018
@@ -174,9 +174,9 @@ llvm::Error BackgroundIndex::index(tooli
   Action->EndSourceFile();
 
   log("Indexed {0} ({1} symbols, {2} refs)", Inputs.CompileCommand.Filename,
-  Symbols.size(), Refs.size());
+  Symbols.size(), Refs.numRefs());
   SPAN_ATTACH(Tracer, "symbols", int(Symbols.size()));
-  SPAN_ATTACH(Tracer, "refs", int(Refs.size()));
+  SPAN_ATTACH(Tracer, "refs", int(Refs.numRefs()));
   // FIXME: partition the symbols by file rather than TU, to avoid duplication.
   IndexedSymbols.update(AbsolutePath,
 llvm::make_unique(std::move(Symbols)),

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=344745&r1=344744&r2=344745&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu Oct 18 08:33:20 2018
@@ -63,9 +63,9 @@ indexSymbols(ASTContext &AST, std::share
   auto Refs = Collector.takeRefs();
   vlog("index AST for {0} (main={1}): \n"
"  symbol slab: {2} symbols, {3} bytes\n"
-   "  ref slab: {4} symbols, {5} bytes",
+   "  ref slab: {4} symbols, {5} refs, {6} bytes",
FileName, IsIndexMainAST, Syms.size(), Syms.bytes(), Refs.size(),
-   Refs.bytes());
+   Refs.numRefs(), Refs.bytes());
   return {std::move(Syms), std::move(Refs)};
 }
 

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=344745&r1=344744&r2=344745&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Oct 18 08:33:20 2018
@@ -172,17 +172,19 @@ RefSlab RefSlab::Builder::build() && {
   // Reallocate refs on the arena to reduce waste and indirections when 
reading.
   std::vector>> Result;
   Result.reserve(Refs.size());
+  size_t NumRefs = 0;
   for (auto &Sym : Refs) {
 auto &SymRefs = Sym.second;
 llvm::sort(SymRefs);
 // FIXME: do we really need to dedup?
 SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end());
 
+NumRefs += SymRefs.size();
 auto *Array = Arena.Allocate(SymRefs.size());
 std::uninitialized_copy(SymRefs.begin(), SymRefs.end(), Array);
 Result.emplace_back(Sym.first, ArrayRef(Array, SymRefs.size()));
   }
-  return RefSlab(std::move(Result), std::move(Arena));
+  return RefSlab(std::move(Result), std::move(Arena), NumRefs);
 }
 
 void SwapIndex::reset(std::unique_ptr Index) {

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=344745&r1=344744&r2=344745&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Oct 18 08:33:20 2018
@@ -407,7 +407,9 @@ public:
 
   const_iterator begin() const { return Refs.begin(); }
   const_iterator end() const { return Refs.end(); }
+  /// Gets the number of symbols.
   size_t size() const { return Refs.size(); }
+  size_t numRefs() const { return NumRefs; }
   bool empty() const { return Refs.empty(); }
 
   size_t bytes() const {
@@ -431,11 +433,14 @@ public:
   };
 
 private:
-  RefSlab(std::vector Refs, llvm::BumpPtrAllocator Arena)
-  : Arena(std::move(Arena)), Refs(std::move(Refs)) {}
+  RefSlab(std::vector Refs, llvm::BumpPtrAllocator Arena,

[clang-tools-extra] r344777 - [clangd] Remove the overflow log.

2018-10-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 19 01:35:24 2018
New Revision: 344777

URL: http://llvm.org/viewvc/llvm-project?rev=344777&view=rev
Log:
[clangd] Remove the overflow log.

Summary:
LLVM codebase has generated files (all are build/Target/XXX/*.inc) that
exceed the MaxLine & MaxColumn. Printing these log would be noisy.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=344777&r1=344776&r2=344777&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Oct 19 01:35:24 2018
@@ -37,6 +37,11 @@ const Decl *getDefinition(const Decl *D)
   return nullptr;
 }
 
+void logIfOverflow(const SymbolLocation &Loc) {
+  if (Loc.Start.hasOverflow() || Loc.End.hasOverflow())
+log("Possible overflow in symbol location: {0}", Loc);
+}
+
 // Convert a SymbolLocation to LSP's Location.
 // HintPath is used to resolve the path of URI.
 // FIXME: figure out a good home for it, and share the implementation with
@@ -61,6 +66,7 @@ llvm::Optional toLSPLocation(c
   LSPLoc.range.start.character = Loc.Start.column();
   LSPLoc.range.end.line = Loc.End.line();
   LSPLoc.range.end.character = Loc.End.column();
+  logIfOverflow(Loc);
   return LSPLoc;
 }
 

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=344777&r1=344776&r2=344777&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Fri Oct 19 01:35:24 2018
@@ -23,7 +23,6 @@ constexpr uint32_t SymbolLocation::Posit
 constexpr uint32_t SymbolLocation::Position::MaxColumn;
 void SymbolLocation::Position::setLine(uint32_t L) {
   if (L > MaxLine) {
-log("Set an overflowed Line {0}", L);
 Line = MaxLine;
 return;
   }
@@ -31,7 +30,6 @@ void SymbolLocation::Position::setLine(u
 }
 void SymbolLocation::Position::setColumn(uint32_t Col) {
   if (Col > MaxColumn) {
-log("Set an overflowed Column {0}", Col);
 Column = MaxColumn;
 return;
   }

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=344777&r1=344776&r2=344777&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Fri Oct 19 01:35:24 2018
@@ -43,6 +43,10 @@ struct SymbolLocation {
 void setColumn(uint32_t Column);
 uint32_t column() const { return Column; }
 
+bool hasOverflow() const {
+  return Line >= MaxLine || Column >= MaxColumn;
+}
+
 static constexpr uint32_t MaxLine = (1 << 20) - 1;
 static constexpr uint32_t MaxColumn = (1 << 12) - 1;
 

Modified: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp?rev=344777&r1=344776&r2=344777&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Fri Oct 19 01:35:24 
2018
@@ -46,10 +46,15 @@ TEST(SymbolLocation, Position) {
   EXPECT_EQ(1u, Pos.line());
   Pos.setColumn(2);
   EXPECT_EQ(2u, Pos.column());
+  EXPECT_FALSE(Pos.hasOverflow());
 
   Pos.setLine(Position::MaxLine + 1); // overflow
+  EXPECT_TRUE(Pos.hasOverflow());
   EXPECT_EQ(Pos.line(), Position::MaxLine);
+  Pos.setLine(1); // reset the overflowed line.
+
   Pos.setColumn(Position::MaxColumn + 1); // overflow
+  EXPECT_TRUE(Pos.hasOverflow());
   EXPECT_EQ(Pos.column(), Position::MaxColumn);
 }
 


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


[clang-tools-extra] r345134 - [clangd] Hide position line and column fields.

2018-10-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 24 05:56:41 2018
New Revision: 345134

URL: http://llvm.org/viewvc/llvm-project?rev=345134&view=rev
Log:
[clangd] Hide position line and column fields.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=345134&r1=345133&r2=345134&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Wed Oct 24 05:56:41 2018
@@ -50,8 +50,7 @@ struct SymbolLocation {
 static constexpr uint32_t MaxLine = (1 << 20) - 1;
 static constexpr uint32_t MaxColumn = (1 << 12) - 1;
 
-// Clients should use getters and setters to access these members.
-// FIXME: hide these members.
+  private:
 uint32_t Line : 20; // 0-based
 // Using UTF-16 code units.
 uint32_t Column : 12; // 0-based


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


[clang-tools-extra] r351081 - [clangd] Add Limit parameter for xref.

2019-01-14 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Jan 14 10:11:09 2019
New Revision: 351081

URL: http://llvm.org/viewvc/llvm-project?rev=351081&view=rev
Log:
[clangd] Add Limit parameter for xref.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/XRefs.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=351081&r1=351080&r2=351081&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Jan 14 10:11:09 2019
@@ -710,7 +710,7 @@ void ClangdLSPServer::onChangeConfigurat
 void ClangdLSPServer::onReference(const ReferenceParams &Params,
   Callback> Reply) {
   Server->findReferences(Params.textDocument.uri.file(), Params.position,
- std::move(Reply));
+ CCOpts.Limit, std::move(Reply));
 }
 
 void ClangdLSPServer::onSymbolInfo(const TextDocumentPositionParams &Params,

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=351081&r1=351080&r2=351081&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Jan 14 10:11:09 2019
@@ -500,13 +500,13 @@ void ClangdServer::documentSymbols(llvm:
Bind(Action, std::move(CB)));
 }
 
-void ClangdServer::findReferences(PathRef File, Position Pos,
+void ClangdServer::findReferences(PathRef File, Position Pos, uint32_t Limit,
   Callback> CB) {
-  auto Action = [Pos, this](Callback> CB,
-llvm::Expected InpAST) {
+  auto Action = [Pos, Limit, this](Callback> CB,
+   llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findReferences(InpAST->AST, Pos, Index));
+CB(clangd::findReferences(InpAST->AST, Pos, Limit, Index));
   };
 
   WorkScheduler.runWithAST("References", File, Bind(Action, std::move(CB)));

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=351081&r1=351080&r2=351081&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Jan 14 10:11:09 2019
@@ -181,7 +181,7 @@ public:
Callback> CB);
 
   /// Retrieve locations for symbol references.
-  void findReferences(PathRef File, Position Pos,
+  void findReferences(PathRef File, Position Pos, uint32_t Limit,
   Callback> CB);
 
   /// Run formatting for \p Rng inside \p File with content \p Code.

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=351081&r1=351080&r2=351081&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Mon Jan 14 10:11:09 2019
@@ -704,7 +704,9 @@ llvm::Optional getHover(ParsedAST
 }
 
 std::vector findReferences(ParsedAST &AST, Position Pos,
- const SymbolIndex *Index) {
+ uint32_t Limit, const SymbolIndex *Index) 
{
+  if (!Limit)
+Limit = std::numeric_limits::max();
   std::vector Results;
   const SourceManager &SM = AST.getASTContext().getSourceManager();
   auto MainFilePath =
@@ -733,26 +735,30 @@ std::vector findReferences(Par
   }
 
   // Now query the index for references from other files.
-  if (!Index)
-return Results;
-  RefsRequest Req;
-  for (const Decl *D : TargetDecls) {
-// Not all symbols can be referenced from outside (e.g. function-locals).
-// TODO: we could skip TU-scoped symbols here (e.g. static functions) if
-// we know t

r351222 - [Tooling] Make clang-tool find libc++ dir on mac when running on a file without compilation database.

2019-01-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 15 11:05:50 2019
New Revision: 351222

URL: http://llvm.org/viewvc/llvm-project?rev=351222&view=rev
Log:
[Tooling] Make clang-tool find libc++ dir on mac when running on a file without 
compilation database.

Summary:
This is a regression of r348365.

When clang-tools run on a file without a complation database (`clang-check 
/tmp/t.cc`),
we will use fixed compilation database as a fallback. However the actual 
compiler
path in the fallback complation command is just `clang-tool` which is
insufficient to detect the libc++ dir.

Reviewers: ilya-biryukov, EricWF

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
Modified:
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=351222&r1=351221&r2=351222&view=diff
==
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Tue Jan 15 11:05:50 2019
@@ -227,6 +227,16 @@ struct FilterUnusedFlags {
   }
 };
 
+std::string GetClangToolCommand() {
+  static int Dummy;
+  std::string ClangExecutable =
+  llvm::sys::fs::getMainExecutable("clang", (void *)&Dummy);
+  SmallString<128> ClangToolPath;
+  ClangToolPath = llvm::sys::path::parent_path(ClangExecutable);
+  llvm::sys::path::append(ClangToolPath, "clang-tool");
+  return ClangToolPath.str();
+}
+
 } // namespace
 
 /// Strips any positional args and possible argv[0] from a command-line
@@ -266,9 +276,9 @@ static bool stripPositionalArgs(std::vec
   Diagnostics));
   NewDriver->setCheckInputsExist(false);
 
-  // This becomes the new argv[0]. The value is actually not important as it
-  // isn't used for invoking Tools.
-  Args.insert(Args.begin(), "clang-tool");
+  // This becomes the new argv[0]. The value is used to detect libc++ include
+  // dirs on Mac, it isn't used for other platforms.
+  Args.insert(Args.begin(), GetClangToolCommand().c_str());
 
   // By adding -c, we force the driver to treat compilation as the last phase.
   // It will then issue warnings via Diagnostics about un-used options that
@@ -366,7 +376,7 @@ FixedCompilationDatabase::loadFromFile(S
 
 FixedCompilationDatabase::
 FixedCompilationDatabase(Twine Directory, ArrayRef CommandLine) {
-  std::vector ToolCommandLine(1, "clang-tool");
+  std::vector ToolCommandLine(1, GetClangToolCommand());
   ToolCommandLine.insert(ToolCommandLine.end(),
  CommandLine.begin(), CommandLine.end());
   CompileCommands.emplace_back(Directory, StringRef(),

Added: cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp?rev=351222&view=auto
==
--- cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp 
(added)
+++ cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp Tue 
Jan 15 11:05:50 2019
@@ -0,0 +1,16 @@
+// Clang on MacOS can find libc++ living beside the installed compiler.
+// This test makes sure our libTooling-based tools emulate this properly with
+// fixed compilation database.
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+//
+// Install the mock libc++ (simulates the libc++ directory structure).
+// RUN: cp -r %S/Inputs/mock-libcxx %t/
+//
+// RUN: cp clang-check %t/mock-libcxx/bin/
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: %t/mock-libcxx/bin/clang-check -p "%t" "%t/test.cpp" -- -stdlib=libc++
+
+#include 
+vector v;


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


r351229 - [Tooling] Fix broken compliation databse tests.

2019-01-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 15 11:51:39 2019
New Revision: 351229

URL: http://llvm.org/viewvc/llvm-project?rev=351229&view=rev
Log:
[Tooling] Fix broken compliation databse tests.

I forgot to update the unittest in r351222.

Modified:
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=351229&r1=351228&r2=351229&view=diff
==
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Tue Jan 15 11:51:39 
2019
@@ -14,11 +14,15 @@
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Path.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace tooling {
 
+using testing::ElementsAre;
+using testing::EndsWith;
+
 static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
   EXPECT_EQ(nullptr,
@@ -467,21 +471,15 @@ TEST(unescapeJsonCommandLine, ParsesSing
 }
 
 TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
-  std::vector CommandLine;
-  CommandLine.push_back("one");
-  CommandLine.push_back("two");
-  FixedCompilationDatabase Database(".", CommandLine);
+  FixedCompilationDatabase Database(".", /*CommandLine*/ {"one", "two"});
   StringRef FileName("source");
   std::vector Result =
 Database.getCompileCommands(FileName);
   ASSERT_EQ(1ul, Result.size());
-  std::vector ExpectedCommandLine(1, "clang-tool");
-  ExpectedCommandLine.insert(ExpectedCommandLine.end(),
- CommandLine.begin(), CommandLine.end());
-  ExpectedCommandLine.push_back("source");
   EXPECT_EQ(".", Result[0].Directory);
   EXPECT_EQ(FileName, Result[0].Filename);
-  EXPECT_EQ(ExpectedCommandLine, Result[0].CommandLine);
+  EXPECT_THAT(Result[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "one", "two", "source"));
 }
 
 TEST(FixedCompilationDatabase, GetAllFiles) {
@@ -537,12 +535,8 @@ TEST(ParseFixedCompilationDatabase, Retu
 Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  std::vector CommandLine;
-  CommandLine.push_back("clang-tool");
-  CommandLine.push_back("-DDEF3");
-  CommandLine.push_back("-DDEF4");
-  CommandLine.push_back("source");
-  ASSERT_EQ(CommandLine, Result[0].CommandLine);
+  ASSERT_THAT(Result[0].CommandLine, ElementsAre(EndsWith("clang-tool"),
+ "-DDEF3", "-DDEF4", 
"source"));
   EXPECT_EQ(2, Argc);
 }
 
@@ -558,10 +552,8 @@ TEST(ParseFixedCompilationDatabase, Retu
 Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  std::vector CommandLine;
-  CommandLine.push_back("clang-tool");
-  CommandLine.push_back("source");
-  ASSERT_EQ(CommandLine, Result[0].CommandLine);
+  ASSERT_THAT(Result[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "source"));
   EXPECT_EQ(2, Argc);
 }
 
@@ -577,12 +569,8 @@ TEST(ParseFixedCompilationDatabase, Hand
 Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  std::vector Expected;
-  Expected.push_back("clang-tool");
-  Expected.push_back("-c");
-  Expected.push_back("-DDEF3");
-  Expected.push_back("source");
-  ASSERT_EQ(Expected, Result[0].CommandLine);
+  ASSERT_THAT(Result[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source"));
   EXPECT_EQ(2, Argc);
 }
 
@@ -599,12 +587,9 @@ TEST(ParseFixedCompilationDatabase, Hand
   std::vector Result = Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  std::vector Expected;
-  Expected.push_back("clang-tool");
-  Expected.push_back("-fsyntax-only");
-  Expected.push_back("-DDEF3");
-  Expected.push_back("source");
-  ASSERT_EQ(Expected, Result[0].CommandLine);
+  ASSERT_THAT(
+  Result[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "-fsyntax-only", "-DDEF3", 
"source"));
 }
 
 TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
@@ -620,9 +605,8 @@ TEST(ParseFixedCompilationDatabase, Hand
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
   std::vector Expected;
-  Expected.push_back("clang-tool");
-  Expected.push_back("source");
-  ASSERT_EQ(Expected, Result[0].CommandLine);
+  ASSERT_THAT(Result[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "source"));
   EXPECT_EQ(2, Argc);
 }
 


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


[clang-tools-extra] r351792 - [clangd] Support clang-tidy configuration in clangd.

2019-01-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 22 01:39:05 2019
New Revision: 351792

URL: http://llvm.org/viewvc/llvm-project?rev=351792&view=rev
Log:
[clangd] Support clang-tidy configuration in clangd.

Summary:
This patch adds some basic supports for clang-tidy configurations in clangd:
  - clangd will respect .clang-tidy configurations for each file
  - we don't aim to support all clang-tidy options in clangd, only a
small subset of condfigurations (options related to which checks will be
enabled) are supported.
  - add a `clang-tidy-checks` CLI option that can override options from
.clang-tidy file

Reviewers: ilya-biryukov, sammccall

Reviewed By: sammccall

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, 
cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=351792&r1=351791&r2=351792&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jan 22 01:39:05 2019
@@ -720,11 +720,13 @@ void ClangdLSPServer::onSymbolInfo(const
 }
 
 ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
+ const FileSystemProvider &FSProvider,
  const clangd::CodeCompleteOptions &CCOpts,
  llvm::Optional CompileCommandsDir,
  bool UseDirBasedCDB,
  const ClangdServer::Options &Opts)
-: Transp(Transp), MsgHandler(new MessageHandler(*this)), CCOpts(CCOpts),
+: Transp(Transp), MsgHandler(new MessageHandler(*this)),
+  FSProvider(FSProvider), CCOpts(CCOpts),
   SupportedSymbolKinds(defaultSymbolKinds()),
   SupportedCompletionItemKinds(defaultCompletionItemKinds()),
   UseDirBasedCDB(UseDirBasedCDB),

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=351792&r1=351791&r2=351792&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Jan 22 01:39:05 2019
@@ -37,7 +37,8 @@ public:
   /// for compile_commands.json in all parent directories of each file.
   /// If UseDirBasedCDB is false, compile commands are not read from disk.
   // FIXME: Clean up signature around CDBs.
-  ClangdLSPServer(Transport &Transp, const clangd::CodeCompleteOptions &CCOpts,
+  ClangdLSPServer(Transport &Transp, const FileSystemProvider &FSProvider,
+  const clangd::CodeCompleteOptions &CCOpts,
   llvm::Optional CompileCommandsDir, bool UseDirBasedCDB,
   const ClangdServer::Options &Opts);
   ~ClangdLSPServer();
@@ -128,7 +129,7 @@ private:
   void call(StringRef Method, llvm::json::Value Params);
   void notify(StringRef Method, llvm::json::Value Params);
 
-  RealFileSystemProvider FSProvider;
+  const FileSystemProvider &FSProvider;
   /// Options used for code completion
   clangd::CodeCompleteOptions CCOpts;
   /// Options used for diagnostics.

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=351792&r1=351791&r2=351792&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jan 22 01:39:05 2019
@@ -105,6 +105,7 @@ ClangdServer::ClangdServer(const GlobalC
   DynamicIdx(Opts.BuildDynamicSymbolIndex
  ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex)
  : nullptr),
+  ClangTidyOptProvider(Opts.ClangTidyOptProvider),
   WorkspaceRoot(Opts.WorkspaceRoot),
   PCHs(std::make_shared()),
   // Pass a callback into `WorkScheduler` to extract symbols from a newly
@@ -140,13 +141,16 @@ ClangdServer::ClangdServer(const GlobalC
 
 voi

[clang-tools-extra] r351809 - [clangd] Fix the `-Wtype-limits` warning, NFC

2019-01-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 22 04:21:25 2019
New Revision: 351809

URL: http://llvm.org/viewvc/llvm-project?rev=351809&view=rev
Log:
[clangd] Fix the `-Wtype-limits` warning, NFC

The assertion is always true, and triggers a compiler warning, so remove it.

Modified:
clang-tools-extra/trunk/clangd/index/Merge.cpp

Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=351809&r1=351808&r2=351809&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Merge.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp Tue Jan 22 04:21:25 2019
@@ -102,7 +102,6 @@ void MergedIndex::refs(const RefsRequest
 Callback(O);
 --Remaining;
   });
-  assert(Remaining >= 0);
   if (Remaining == 0)
 return;
   // We return less than Req.Limit if static index returns more refs for dirty


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


[clang-tools-extra] r351812 - [clangd] Fix the broken buildbot.

2019-01-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 22 04:55:15 2019
New Revision: 351812

URL: http://llvm.org/viewvc/llvm-project?rev=351812&view=rev
Log:
[clangd] Fix the broken buildbot.

Modified:
clang-tools-extra/trunk/clangd/tool/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/CMakeLists.txt?rev=351812&r1=351811&r2=351812&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/tool/CMakeLists.txt Tue Jan 22 04:55:15 2019
@@ -17,6 +17,7 @@ endif()
 target_link_libraries(clangd
   PRIVATE
   clangBasic
+  clangTidy
   clangDaemon
   clangFormat
   clangFrontend


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


[clang-tools-extra] r351826 - [clangd] Followup fix of rL351818

2019-01-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 22 06:48:04 2019
New Revision: 351826

URL: http://llvm.org/viewvc/llvm-project?rev=351826&view=rev
Log:
[clangd] Followup fix of rL351818

ClangTidyOptions::getDefaults is not free, it will initialize all
clang-tidy modules to get check-specific options, and we don't use this
information in CodeComplete, so using an empty one (constructed by
default constructor) is sufficient.

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=351826&r1=351825&r2=351826&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Jan 22 06:48:04 2019
@@ -1019,9 +1019,11 @@ bool semaCodeComplete(std::unique_ptr VFS = Input.VFS;
   if (Input.Preamble && Input.Preamble->StatCache)
 VFS = Input.Preamble->StatCache->getConsumingFS(std::move(VFS));
-  auto CI = buildCompilerInvocation(
-  ParseInputs{Input.Command, VFS, Input.Contents,
-  tidy::ClangTidyOptions::getDefaults()});
+  ParseInputs PInput;
+  PInput.CompileCommand = Input.Command;
+  PInput.FS = VFS;
+  PInput.Contents = Input.Contents;
+  auto CI = buildCompilerInvocation(PInput);
   if (!CI) {
 elog("Couldn't create CompilerInvocation");
 return false;


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


[clang-tools-extra] r351929 - [clangd] Link clangTidy into clangd tests

2019-01-23 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jan 23 00:04:17 2019
New Revision: 351929

URL: http://llvm.org/viewvc/llvm-project?rev=351929&view=rev
Log:
[clangd] Link clangTidy into clangd tests

Patch by Nathan Ridge!

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

Modified:
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt?rev=351929&r1=351928&r2=351929&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt Wed Jan 23 00:04:17 
2019
@@ -59,6 +59,7 @@ target_link_libraries(ClangdTests
   clangLex
   clangSema
   clangSerialization
+  clangTidy
   clangTooling
   clangToolingCore
   clangToolingInclusions


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


[clang-tools-extra] r352049 - [clangd] Clean the cache of file statuses on vscode-clangd when clangd crashes.

2019-01-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Jan 24 06:25:53 2019
New Revision: 352049

URL: http://llvm.org/viewvc/llvm-project?rev=352049&view=rev
Log:
[clangd] Clean the cache of file statuses on vscode-clangd when clangd crashes.

Summary:
Clear the cached file statuses, otherwise we will leave some garbage texts on
the status bar when clangd crashes.

Reviewers: ilya-biryukov

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

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=352049&r1=352048&r2=352049&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Thu 
Jan 24 06:25:53 2019
@@ -40,6 +40,11 @@ class FileStatus {
 this.statusBarItem.show();
 }
 
+clear() {
+this.statuses.clear();
+this.statusBarItem.hide();
+}
+
 dispose() {
 this.statusBarItem.dispose();
 }
@@ -112,9 +117,16 @@ export function activate(context: vscode
 context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => 
{
 status.updateStatus();
 }));
-clangdClient.onReady().then(() => {
-clangdClient.onNotification(
-'textDocument/clangd.fileStatus',
-(fileStatus) => { status.onFileUpdated(fileStatus); });
-})
+clangdClient.onDidChangeState(
+({ newState }) => {
+if (newState == vscodelc.State.Running) {
+// clangd starts or restarts after crash.
+clangdClient.onNotification(
+'textDocument/clangd.fileStatus',
+(fileStatus) => { status.onFileUpdated(fileStatus); });
+} else if (newState == vscodelc.State.Stopped) {
+// Clear all cached statuses when clangd crashes.
+status.clear();
+}
+})
 }


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


[clang-tools-extra] r352183 - [clang-tidy] Add check for underscores in googletest names.

2019-01-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jan 25 02:03:49 2019
New Revision: 352183

URL: http://llvm.org/viewvc/llvm-project?rev=352183&view=rev
Log:
[clang-tidy] Add check for underscores in googletest names.

Summary: Adds a clang-tidy warning for underscores in googletest names.

Patch by Kar Epker!

Reviewers: hokein, alexfh, aaron.ballman

Reviewed By: hokein

Subscribers: Eugene.Zelenko, JonasToth, MyDeveloperDay, lebedev.ri, xazax.hun, 
mgorny, cfe-commits

Tags: #clang-tools-extra

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

Added:

clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-avoid-underscore-in-googletest-name.rst

clang-tools-extra/trunk/test/clang-tidy/readability-avoid-underscore-in-googletest-name.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Added: 
clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp?rev=352183&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
 (added)
+++ 
clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
 Fri Jan 25 02:03:49 2019
@@ -0,0 +1,89 @@
+//===--- AvoidUnderscoreInGoogletestNameCheck.cpp - clang-tidy --*- 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 
+
+#include "AvoidUnderscoreInGoogletestNameCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/MacroArgs.h"
+
+namespace clang {
+namespace tidy {
+namespace google {
+namespace readability {
+
+constexpr llvm::StringLiteral kDisabledTestPrefix = "DISABLED_";
+
+// Determines whether the macro is a Googletest test macro.
+static bool isGoogletestTestMacro(StringRef MacroName) {
+  static const llvm::StringSet<> MacroNames = {"TEST", "TEST_F", "TEST_P",
+   "TYPED_TEST", "TYPED_TEST_P"};
+  return MacroNames.find(MacroName) != MacroNames.end();
+}
+
+namespace {
+
+class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
+public:
+  AvoidUnderscoreInGoogletestNameCallback(
+  Preprocessor *PP, AvoidUnderscoreInGoogletestNameCheck *Check)
+  : PP(PP), Check(Check) {}
+
+  // Detects expansions of the TEST, TEST_F, TEST_P, TYPED_TEST, TYPED_TEST_P
+  // macros and checks that their arguments do not have any underscores.
+  void MacroExpands(const Token &MacroNameToken,
+const MacroDefinition &MacroDefinition, SourceRange Range,
+const MacroArgs *Args) override {
+IdentifierInfo *NameIdentifierInfo = MacroNameToken.getIdentifierInfo();
+if (!NameIdentifierInfo)
+  return;
+StringRef MacroName = NameIdentifierInfo->getName();
+if (!isGoogletestTestMacro(MacroName) || !Args ||
+Args->getNumMacroArguments() < 2)
+  return;
+const Token *TestCaseNameToken = Args->getUnexpArgument(0);
+const Token *TestNameToken = Args->getUnexpArgument(1);
+if (!TestCaseNameToken || !TestNameToken)
+  return;
+std::string TestCaseName = PP->getSpelling(*TestCaseNameToken);
+if (TestCaseName.find('_') != std::string::npos)
+  Check->diag(TestCaseNameToken->getLocation(),
+  "avoid using \"_\" in test case name \"%0\" according to "
+  "Googletest FAQ")
+  << TestCaseName;
+
+std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
+StringRef TestName = TestNameMaybeDisabled;
+TestName.consume_front(kDisabledTestPrefix);
+if (TestName.contains('_'))
+  Check->diag(TestNameToken->getLocation(),
+  "avoid using \"_\" in test name \"%0\" according to "
+  "Googletest FAQ")
+  << TestName;
+  }
+
+private:
+  Preprocessor *PP;
+  AvoidUnderscoreInGoogletestNameCheck *Check;
+};
+
+} // namespace
+
+void AvoidUnderscoreInGoogletestNameCheck::registerPPCallbacks(
+CompilerInstance &Compiler) {
+  Compiler.getPreprocessor().addPPCallbacks(
+  llvm::make_unique(
+  &Compiler.getPreprocessor(), this));
+}
+
+} // namespace readability
+} // namespace google
+} // namespace tidy
+} // na

[clang-tools-extra] r352184 - [clangd] Log clang-tidy configuration, NFC

2019-01-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jan 25 02:14:27 2019
New Revision: 352184

URL: http://llvm.org/viewvc/llvm-project?rev=352184&view=rev
Log:
[clangd] Log clang-tidy configuration, NFC

Summary: This is used for debugging purpose.

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=352184&r1=352183&r2=352184&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Jan 25 02:14:27 2019
@@ -265,6 +265,8 @@ ParsedAST::build(std::unique_ptr CTContext;
   {
 trace::Span Tracer("ClangTidyInit");
+vlog("ClangTidy configuration for file {0}: {1}", MainInput.getFile(),
+ tidy::configurationAsText(ClangTidyOpts));
 tidy::ClangTidyCheckFactories CTFactories;
 for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
   E.instantiate()->addCheckFactories(CTFactories);


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


[clang-tools-extra] r352205 - [clangd] NFC: fix clang-tidy warnings.

2019-01-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jan 25 07:14:03 2019
New Revision: 352205

URL: http://llvm.org/viewvc/llvm-project?rev=352205&view=rev
Log:
[clangd] NFC: fix clang-tidy warnings.

Most are about llvm code style violation (found via
readability-identifier-naming check).

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/SymbolID.cpp
clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=352205&r1=352204&r2=352205&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Fri Jan 25 07:14:03 2019
@@ -31,7 +31,7 @@ class raw_ostream;
 
 namespace vfs {
 class FileSystem;
-}
+} // namespace vfs
 } // namespace llvm
 
 namespace clang {
@@ -39,7 +39,7 @@ class PCHContainerOperations;
 
 namespace tooling {
 struct CompileCommand;
-}
+} // namespace tooling
 
 namespace clangd {
 

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=352205&r1=352204&r2=352205&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jan 25 07:14:03 2019
@@ -1588,9 +1588,9 @@ speculateCompletionFilter(llvm::StringRe
   // Start from the character before the cursor.
   int St = *Offset - 1;
   // FIXME(ioeric): consider UTF characters?
-  auto IsValidIdentifierChar = [](char c) {
-return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
-(c >= '0' && c <= '9') || (c == '_'));
+  auto IsValidIdentifierChar = [](char C) {
+return ((C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
+(C >= '0' && C <= '9') || (C == '_'));
   };
   size_t Len = 0;
   for (; (St >= 0) && IsValidIdentifierChar(Content[St]); --St, ++Len) {
@@ -1682,7 +1682,7 @@ CompletionItem CodeCompletion::render(co
   // is mainly to help LSP clients again, so that changes do not effect each
   // other.
   for (const auto &FixIt : FixIts) {
-if (IsRangeConsecutive(FixIt.range, LSP.textEdit->range)) {
+if (isRangeConsecutive(FixIt.range, LSP.textEdit->range)) {
   LSP.textEdit->newText = FixIt.newText + LSP.textEdit->newText;
   LSP.textEdit->range.start = FixIt.range.start;
 } else {

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=352205&r1=352204&r2=352205&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Fri Jan 25 07:14:03 2019
@@ -455,25 +455,25 @@ bool operator==(const SymbolDetails &LHS
 }
 
 llvm::json::Value toJSON(const SymbolDetails &P) {
-  llvm::json::Object result{{"name", llvm::json::Value(nullptr)},
+  llvm::json::Object Result{{"name", llvm::json::Value(nullptr)},
 {"containerName", llvm::json::Value(nullptr)},
 {"usr", llvm::json::Value(nullptr)},
 {"id", llvm::json::Value(nullptr)}};
 
   if (!P.name.empty())
-result["name"] = P.name;
+Result["name"] = P.name;
 
   if (!P.containerName.empty())
-result["containerName"] = P.containerName;
+Result["containerName"] = P.containerName;
 
   if (!P.USR.empty())
-result["usr"] = P.USR;
+Result["usr"] = P.USR;
 
   if (P.ID.hasValue())
-result["id"] = P.ID.getValue().str();
+Result["id"] = P.ID.getValue().str();
 
   // Older clang cannot compile 'return Result', even though it is legal.
-  return llvm::json::Value(std::move(result));
+  return llvm::json::Value(std::move(Result));
 }
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const SymbolDetails &S) {
@@ -559,10 +559,10 @@ bool fromJSON(const llvm::json::Value &P
   if (!O)
 return false;
 
-  int triggerKind;
-  if (!O.map("triggerKind", triggerKind))
+  int TriggerKind;
+  if (!O.map("triggerKind", TriggerKind))
 return false;
-  R.triggerKind = static_cast(triggerKind);
+  R.triggerKind = static_cast(TriggerKind);
 
   if (auto *TC = Params.getAsObject()->get("triggerCharacter"))
 return fromJSON(*TC, R.triggerCharacter);
@@ -619,11 +619,11 @@ bool fromJ

[clang-tools-extra] r352364 - [clang-tidy] Fix a build error.

2019-01-28 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Jan 28 06:07:45 2019
New Revision: 352364

URL: http://llvm.org/viewvc/llvm-project?rev=352364&view=rev
Log:
[clang-tidy] Fix a build error.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/DurationAdditionCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationAdditionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationAdditionCheck.cpp?rev=352364&r1=352363&r2=352364&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationAdditionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationAdditionCheck.cpp Mon Jan 
28 06:07:45 2019
@@ -54,7 +54,7 @@ void DurationAdditionCheck::check(const
  rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS()) + 
")")
 .str());
   } else {
-assert(Call == Binop->getRHS()->IgnoreParenImpCast() &&
+assert(Call == Binop->getRHS()->IgnoreParenImpCasts() &&
"Call should be found on the RHS");
 Hint = FixItHint::CreateReplacement(
 Binop->getSourceRange(),


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


[clang-tools-extra] r352367 - [clangd] Index main-file macros (bug 39761)

2019-01-28 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Jan 28 06:11:49 2019
New Revision: 352367

URL: http://llvm.org/viewvc/llvm-project?rev=352367&view=rev
Log:
[clangd] Index main-file macros (bug 39761)

Patch by Nathan Ridge!

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

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=352367&r1=352366&r2=352367&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Jan 28 
06:11:49 2019
@@ -379,13 +379,21 @@ bool SymbolCollector::handleMacroOccuren
 
   const auto &SM = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  if (SM.isInMainFile(SM.getExpansionLoc(DefLoc)))
-return true;
+
   // Header guards are not interesting in index. Builtin macros don't have
   // useful locations and are not needed for code completions.
   if (MI->isUsedForHeaderGuard() || MI->isBuiltinMacro())
 return true;
 
+  // Skip main-file symbols if we are not collecting them.
+  bool IsMainFileSymbol = SM.isInMainFile(SM.getExpansionLoc(DefLoc));
+  if (IsMainFileSymbol && !Opts.CollectMainFileSymbols)
+return false;
+
+  // Also avoid storing predefined macros like __DBL_MIN__.
+  if (SM.isWrittenInBuiltinFile(DefLoc))
+return true;
+
   // Mark the macro as referenced if this is a reference coming from the main
   // file. The macro may not be an interesting symbol, but it's cheaper to 
check
   // at the end.
@@ -410,7 +418,10 @@ bool SymbolCollector::handleMacroOccuren
   Symbol S;
   S.ID = std::move(*ID);
   S.Name = Name->getName();
-  S.Flags |= Symbol::IndexedForCodeCompletion;
+  if (!IsMainFileSymbol) {
+S.Flags |= Symbol::IndexedForCodeCompletion;
+S.Flags |= Symbol::VisibleOutsideFile;
+  }
   S.SymInfo = index::getSymbolInfoForMacro(*MI);
   std::string FileURI;
   // FIXME: use the result to filter out symbols.

Modified: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp?rev=352367&r1=352366&r2=352367&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp Mon Jan 28 
06:11:49 2019
@@ -87,13 +87,16 @@ protected:
 
 } // namespace
 
-TEST_F(WorkspaceSymbolsTest, NoMacro) {
+TEST_F(WorkspaceSymbolsTest, Macros) {
   addFile("foo.cpp", R"cpp(
-  #define MACRO X
-  )cpp");
+   #define MACRO X
+   )cpp");
 
-  // Macros are not in the index.
-  EXPECT_THAT(getSymbols("macro"), IsEmpty());
+  // LSP's SymbolKind doesn't have a "Macro" kind, and
+  // indexSymbolKindToSymbolKind() currently maps macros
+  // to SymbolKind::String.
+  EXPECT_THAT(getSymbols("macro"),
+  ElementsAre(AllOf(QName("MACRO"), 
WithKind(SymbolKind::String;
 }
 
 TEST_F(WorkspaceSymbolsTest, NoLocals) {

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=352367&r1=352366&r2=352367&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Mon Jan 
28 06:11:49 2019
@@ -1069,21 +1069,27 @@ TEST_F(SymbolCollectorTest, CollectMacro
 
 MAC(p);
   )");
-  const std::string Main = R"(
-#define MAIN 1  // not indexed
-USED(t);
-  )";
+
+  Annotations Main(R"(
+#define $main[[MAIN]] 1
+ USED(t);
+  )");
   CollectorOpts.CountReferences = true;
   CollectorOpts.CollectMacro = true;
-  runSymbolCollector(Header.code(), Main);
-  EXPECT_THAT(Symbols,
-  UnorderedElementsAre(QName("p"), QName("t"),
-   AllOf(QName("X"), DeclURI(TestHeaderURI),
- IncludeHeader(TestHeaderURI)),
-   AllOf(Labeled("MAC(x)"), RefCount(0),
- DeclRange(Header.range("mac"))),
-   AllOf(Labeled("USED(y)"), RefCount(1),
- DeclRange(Header.range("used");
+  runSymbolCollector(Header.code(), Main.code());
+  EXPECT_THAT(
+  Symbols,
+  UnorderedElementsAre(
+  QName("p"), QName("t"),
+  AllOf(QName("X"), DeclURI(TestHeaderURI),
+  

[clang-tools-extra] r352485 - [clangd] dlog clang-tidy configuration

2019-01-29 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jan 29 04:32:32 2019
New Revision: 352485

URL: http://llvm.org/viewvc/llvm-project?rev=352485&view=rev
Log:
[clangd] dlog clang-tidy configuration

vlog seems to be too spammy in unittests.

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

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=352485&r1=352484&r2=352485&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Jan 29 04:32:32 2019
@@ -272,7 +272,7 @@ ParsedAST::build(std::unique_ptr CTContext;
   {
 trace::Span Tracer("ClangTidyInit");
-vlog("ClangTidy configuration for file {0}: {1}", MainInput.getFile(),
+dlog("ClangTidy configuration for file {0}: {1}", MainInput.getFile(),
  tidy::configurationAsText(Opts.ClangTidyOpts));
 tidy::ClangTidyCheckFactories CTFactories;
 for (const auto &E : tidy::ClangTidyModuleRegistry::entries())


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


  1   2   3   4   5   6   7   8   9   10   >