From eaacc885deefea195c5cc29b5b4d01996b9a335d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 20 Aug 2013 21:03:29 +0000 Subject: [PATCH] DebugInfo: Simplify/clarify propagation of typemembers between declaration and definition Based on code review feedback from Eric Christopher (on r188739) and Adrian Prantl (r188642). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188829 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 48 ++++++++++++++----------------------- lib/CodeGen/CGDebugInfo.h | 5 ++-- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 7177fe2cc3..d30925c7d2 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -602,10 +602,11 @@ llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, } // Creates a forward declaration for a RecordDecl in the given context. -llvm::DIType CGDebugInfo::getOrCreateRecordFwdDecl(const RecordDecl *RD, - llvm::DIDescriptor Ctx) { +llvm::DICompositeType +CGDebugInfo::getOrCreateRecordFwdDecl(const RecordDecl *RD, + llvm::DIDescriptor Ctx) { if (llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(RD))) - return T; + return llvm::DICompositeType(T); llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); unsigned Line = getLineNumber(RD->getLocation()); StringRef RDName = getClassName(RD); @@ -642,29 +643,11 @@ llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) { if (const NamespaceDecl *NSDecl = dyn_cast(Context)) return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl)); - if (const RecordDecl *RD = dyn_cast(Context)) { - if (!RD->isDependentType()) { - llvm::DICompositeType T(getTypeOrNull(CGM.getContext().getRecordType(RD))); - llvm::DICompositeType Ty(getOrCreateLimitedType( + if (const RecordDecl *RD = dyn_cast(Context)) + if (!RD->isDependentType()) + return getOrCreateLimitedType( CGM.getContext().getRecordType(RD)->castAs(), - getOrCreateMainFile())); - if (!Ty.getTypeArray().getNumElements()) { - if (T) { - llvm::DIArray PrevMem = T.getTypeArray(); - unsigned NumElements = PrevMem.getNumElements(); - if (NumElements == 1 && !PrevMem.getElement(0)) - NumElements = 0; - SmallVector EltTys; - EltTys.reserve(NumElements); - for (unsigned i = 0; i != NumElements; ++i) - EltTys.push_back(PrevMem.getElement(i)); - llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); - Ty.setTypeArray(Elements); - } - } - return llvm::DIDescriptor(Ty); - } - } + getOrCreateMainFile()); return TheCU; } @@ -2195,7 +2178,7 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile Unit) { QualType QTy(Ty, 0); - llvm::DIType T = getTypeOrNull(QTy); + llvm::DICompositeType T(getTypeOrNull(QTy)); // We may have cached a forward decl when we could have created // a non-forward decl. Go ahead and create a non-forward decl @@ -2203,7 +2186,12 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty, if (T && !T.isForwardDecl()) return T; // Otherwise create the type. - llvm::DIType Res = CreateLimitedType(Ty); + llvm::DICompositeType Res = CreateLimitedType(Ty); + + // Propagate members from the declaration to the definition + // CreateType(const RecordType*) will overwrite this with the members in the + // correct order if the full type is needed. + Res.setTypeArray(T.getTypeArray()); if (T && T.isForwardDecl()) ReplaceMap.push_back( @@ -2215,7 +2203,7 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty, } // TODO: Currently used for context chains when limiting debug info. -llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { +llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { RecordDecl *RD = Ty->getDecl(); // Get overall information about the record type for the debug info. @@ -2238,8 +2226,8 @@ llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { // destined for completion (might still have an issue if this caller only // required a declaration but the context construction ended up creating a // definition) - if (llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(RD))) - if (!T.isForwardDecl() || !RD->getDefinition()) + llvm::DICompositeType T(getTypeOrNull(CGM.getContext().getRecordType(RD))); + if (T && (!T.isForwardDecl() || !RD->getDefinition())) return T; // If this is just a forward declaration, construct an appropriately diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index d0e16bfe3e..6ecc7e5fe1 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -116,7 +116,7 @@ class CGDebugInfo { llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F); llvm::DIType CreateType(const RecordType *Ty, bool Declaration); llvm::DIType CreateTypeDefinition(const RecordType *Ty); - llvm::DIType CreateLimitedType(const RecordType *Ty); + llvm::DICompositeType CreateLimitedType(const RecordType *Ty); void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT); llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F); @@ -309,7 +309,8 @@ private: llvm::DIScope getCurrentContextDescriptor(const Decl *Decl); /// \brief Create a forward decl for a RecordType in a given context. - llvm::DIType getOrCreateRecordFwdDecl(const RecordDecl *, llvm::DIDescriptor); + llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordDecl *, + llvm::DIDescriptor); /// createContextChain - Create a set of decls for the context chain. llvm::DIDescriptor createContextChain(const Decl *Decl); -- 2.40.0