From 1f94124b76680211f3585ac8c3b24b247f46fac3 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 21 Sep 2012 01:30:00 +0000 Subject: [PATCH] [PCH] After deserializing a DeclContext, if it has external lexical decls but not external visible decls, call DeclContext::setMustBuildLookupTable so that the "lazy decls" bit of the LookupPtr is set. Previously, in non-C++, if there were no new declarations causing the "lazy decls" bit to be set, then DeclContext::lookups_begin() would fail to return the decls from the PCH. Fixes rdar://12316296. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164351 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReader.cpp | 4 ++++ lib/Serialization/ASTReaderDecl.cpp | 3 +++ test/Index/rdar12316296-codecompletion.m | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/Index/rdar12316296-codecompletion.m diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 478217bd03..9fe6ef317e 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1661,6 +1661,10 @@ ASTReader::ReadASTBlock(ModuleFile &F) { return Failure; } + DeclContext *DC = Context.getTranslationUnitDecl(); + if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) + DC->setMustBuildLookupTable(); + return Success; } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 754ff36db7..c9788a3216 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -2127,6 +2127,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { } PendingVisibleUpdates.erase(I); } + + if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) + DC->setMustBuildLookupTable(); } assert(Idx == Record.size()); diff --git a/test/Index/rdar12316296-codecompletion.m b/test/Index/rdar12316296-codecompletion.m new file mode 100644 index 0000000000..f588a99837 --- /dev/null +++ b/test/Index/rdar12316296-codecompletion.m @@ -0,0 +1,23 @@ +// RUN: c-index-test -write-pch %t.h.pch %s +// RUN: c-index-test -code-completion-at=%s:19:1 %s -include %t.h | FileCheck %s + +// clang Code Completion returns nothing but preprocessor macros + +#ifndef HEADER +#define HEADER + +@interface I +@end + +// CHECK: FunctionDecl:{ResultType void}{TypedText foo} +void foo(); + +#else + +@implementation I +-(void)meth { + +} +@end + +#endif -- 2.40.0