From 7671e53b668093edbf3f20fc5e43a341626c743a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 16 Dec 2011 16:34:57 +0000 Subject: [PATCH] If there is a definition of an ObjCInterfaceDecl, make it the Decl returned from the corresponding ObjCInterfaceType llvm-svn: 146740 --- clang/include/clang/AST/Type.h | 3 ++- clang/lib/AST/ASTContext.cpp | 4 ++++ clang/lib/AST/DeclObjC.cpp | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index c9bee81..de58396 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -4139,12 +4139,13 @@ inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { /// - It is its own base type. That is, if T is an ObjCInterfaceType*, /// T->getBaseType() == QualType(T, 0). class ObjCInterfaceType : public ObjCObjectType { - ObjCInterfaceDecl *Decl; + mutable ObjCInterfaceDecl *Decl; ObjCInterfaceType(const ObjCInterfaceDecl *D) : ObjCObjectType(Nonce_ObjCInterface), Decl(const_cast(D)) {} friend class ASTContext; // ASTContext creates these. + friend class ObjCInterfaceDecl; public: /// getDecl - Get the declaration of this interface. diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index de0250c..9784191 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2819,6 +2819,10 @@ QualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, return QualType(PrevDecl->TypeForDecl, 0); } + // Prefer the definition, if there is one. + if (const ObjCInterfaceDecl *Def = Decl->getDefinition()) + Decl = Def; + void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); Decl->TypeForDecl = T; diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 317dc95..02cc988 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -225,7 +225,11 @@ void ObjCInterfaceDecl::mergeClassExtensionProtocolList( void ObjCInterfaceDecl::allocateDefinitionData() { assert(!hasDefinition() && "ObjC class already has a definition"); Data = new (getASTContext()) DefinitionData(); - Data->Definition = this; + Data->Definition = this; + + // Make the type point at the definition, now that we have one. + if (TypeForDecl) + cast(TypeForDecl)->Decl = this; } void ObjCInterfaceDecl::startDefinition() { -- 2.7.4