From: Douglas Gregor Date: Sat, 10 Sep 2011 00:22:34 +0000 (+0000) Subject: Clean up our handling of Objective-C definitions in AST files. Rather X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94da1587f7d584fc61df793229d197969f204cd9;p=clang Clean up our handling of Objective-C definitions in AST files. Rather than having CodeGen check whether a declaration comes from an AST file (which it shouldn't know or care about), make sure that the AST writer and reader pass along "interesting" declarations that CodeGen needs to know about. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139441 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 5fa6704dba..e3a6f4a86f 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -6387,7 +6387,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { if (const VarDecl *VD = dyn_cast(D)) { if (!VD->isFileVarDecl()) return false; - } else if (!isa(D)) + } else if (!isa(D) && !isa(D)) return false; // Weak references don't produce any output by themselves. @@ -6428,6 +6428,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { return true; } + if (const ObjCMethodDecl *Method = dyn_cast(D)) + return Method->hasBody(); + const VarDecl *VD = cast(D); assert(VD->isFileVarDecl() && "Expected file scoped var"); diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index f0ff9eb432..fa49f1e09f 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -3549,13 +3549,6 @@ llvm::Function *CGObjCCommonMac::GetMethodDefinition(const ObjCMethodDecl *MD) { if (I != MethodDefinitions.end()) return I->second; - if (MD->hasBody() && MD->isFromASTFile()) { - // MD isn't emitted yet because it comes from PCH. - CGM.EmitTopLevelDecl(const_cast(MD)); - assert(MethodDefinitions[MD] && "EmitTopLevelDecl didn't emit the method!"); - return MethodDefinitions[MD]; - } - return NULL; } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 594dc93325..9210056fbb 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1393,14 +1393,19 @@ inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { /// code generation, e.g., inline function definitions, Objective-C /// declarations with metadata, etc. static bool isConsumerInterestedIn(Decl *D) { - if (isa(D)) + if (isa(D) || + isa(D) || + isa(D)) return true; if (VarDecl *Var = dyn_cast(D)) return Var->isFileVarDecl() && Var->isThisDeclarationADefinition() == VarDecl::Definition; if (FunctionDecl *Func = dyn_cast(D)) return Func->doesThisDeclarationHaveABody(); - return isa(D) || isa(D); + if (ObjCMethodDecl *Method = dyn_cast(D)) + return Method->hasBody(); + + return false; } /// \brief Get the correct cursor and offset for loading a declaration. @@ -1732,9 +1737,15 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // AST consumer might need to know about, queue it. // We don't pass it to the consumer immediately because we may be in recursive // loading, and some declarations may still be initializing. - if (isConsumerInterestedIn(D)) - InterestingDecls.push_back(D); - + if (isConsumerInterestedIn(D)) { + if (Consumer) { + DeclGroupRef DG(D); + Consumer->HandleInterestingDecl(DG); + } else { + InterestingDecls.push_back(D); + } + } + return D; } diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 112ccb1d4b..55f1a6f9ce 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -1595,7 +1595,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() { /// decls. static bool isRequiredDecl(const Decl *D, ASTContext &Context) { // File scoped assembly or obj-c implementation must be seen. - if (isa(D) || isa(D)) + if (isa(D) || isa(D)) return true; return Context.DeclMustBeEmitted(D);