From ca40f30a20d0329900fa3d1e4b3252cece86ccc0 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 19 Dec 2012 22:21:18 +0000 Subject: [PATCH] [PCH/Modules] In ASTReader::completeVisibleDeclsMap, make sure to visit all modules when getting the decls for a namespace or translation unit. Otherwise the code-completion results will not be complete. rdar://12889089 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170596 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReader.cpp | 11 +++++---- test/Index/codecompletion-chained.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 test/Index/codecompletion-chained.cpp diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 08bc6b4818..f415573db8 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5429,13 +5429,15 @@ namespace { ASTReader &Reader; llvm::SmallVectorImpl &Contexts; llvm::DenseMap > &Decls; + bool VisitAll; public: DeclContextAllNamesVisitor(ASTReader &Reader, SmallVectorImpl &Contexts, llvm::DenseMap > &Decls) - : Reader(Reader), Contexts(Contexts), Decls(Decls) { } + SmallVector > &Decls, + bool VisitAll) + : Reader(Reader), Contexts(Contexts), Decls(Decls), VisitAll(VisitAll) { } static bool visit(ModuleFile &M, void *UserData) { DeclContextAllNamesVisitor *This @@ -5476,7 +5478,7 @@ namespace { } } - return FoundAnything; + return FoundAnything && !This->VisitAll; } }; } @@ -5502,7 +5504,8 @@ void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { } } - DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); + DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls, + /*VisitAll=*/DC->isFileContext()); ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); ++NumVisibleDeclContextsRead; diff --git a/test/Index/codecompletion-chained.cpp b/test/Index/codecompletion-chained.cpp new file mode 100644 index 0000000000..93e832f81e --- /dev/null +++ b/test/Index/codecompletion-chained.cpp @@ -0,0 +1,33 @@ + +// + +#ifndef HEADER1 +#define HEADER1 + +// CHECK-TU: FunctionDecl:{ResultType void}{TypedText foo} +void foo(); + +namespace Cake { +// CHECK-NAMESPACE: FunctionDecl:{ResultType void}{TypedText lie} +void lie(); +} + +#elif !defined(HEADER2) +#define HEADER2 + +namespace Cake { +extern int Baz; +} + +#else + +void func() { +Cake:: +} + +#endif + +// RUN: c-index-test -write-pch %t1.h.pch %s +// RUN: c-index-test -write-pch %t2.h.pch %s -include %t1.h +// RUN: c-index-test -code-completion-at=%s:25:1 %s -include %t2.h | FileCheck -check-prefix=CHECK-TU %s +// RUN: c-index-test -code-completion-at=%s:25:7 %s -include %t2.h | FileCheck -check-prefix=CHECK-NAMESPACE %s -- 2.40.0