From eab6a36cf1eed9a7fec0babd2206048e28dedd02 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 21 Jun 2013 00:40:50 +0000 Subject: [PATCH] Alternative fix for r184473. This just seems a bit tidier/more principled. Based on a patch provided by Adrian - with the only minor tweak that it needed to use "getTypeOrNull" rather than "getCompletedTypeOrNull" since we don't store declarations in the CompletedTypes cache. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184509 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 39 ++++++++++++------------------------ lib/CodeGen/CGDebugInfo.h | 2 ++ lib/CodeGen/CodeGenTypes.cpp | 5 +++++ 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index f8c814cb94..e1b6342349 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1886,22 +1886,6 @@ llvm::DIType CGDebugInfo::getTypeOrNull(QualType Ty) { return llvm::DIType(); } -/// ContainsFwdDecl - True if Ty is either a forward declaration or a -/// derived type of a forward declaration. -static bool ContainsFwdDecl(llvm::DIType Ty) { - // Composite types such as structs inherit from DIDerivedType, so - // check this first and do an early exit. - if (Ty.isForwardDecl()) - return true; - - if (Ty.isDerivedType()) { - llvm::DIDerivedType DTy(Ty); - return ContainsFwdDecl(DTy.getTypeDerivedFrom()); - } - - return false; -} - /// getCompletedTypeOrNull - Get the type from the cache or return null if it /// doesn't exist. llvm::DIType CGDebugInfo::getCompletedTypeOrNull(QualType Ty) { @@ -1920,19 +1904,22 @@ llvm::DIType CGDebugInfo::getCompletedTypeOrNull(QualType Ty) { } // Verify that any cached debug info still exists. - if (V != 0) { - llvm::DIType CachedType(cast(V)); + if (V != 0) + return llvm::DIType(cast(V)); - // Unless we are limiting debug info, attempt to resolve any - // forward declarations. - if (DebugKind > CodeGenOptions::LimitedDebugInfo && - ContainsFwdDecl(CachedType)) - return llvm::DIType(); + return llvm::DIType(); +} - return CachedType; - } +void CGDebugInfo::completeFwdDecl(const RecordDecl &RD) { + // In limited debug info we only want to do this if the complete type was + // required. + if (DebugKind <= CodeGenOptions::LimitedDebugInfo) + return; - return llvm::DIType(); + llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(&RD)); + + if (T.Verify() && T.isForwardDecl()) + getOrCreateType(QTy, getOrCreateFile(RD.getLocation()); } /// getCachedInterfaceTypeOrNull - Get the type from the interface diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index fc62600c32..72a9d71d79 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -289,6 +289,8 @@ public: llvm::DIType getOrCreateInterfaceType(QualType Ty, SourceLocation Loc); + void completeFwdDecls(const RecordDecl *TD); + private: /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 4240216b23..6ebb418e5e 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -260,6 +260,11 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { // yet, we'll just do it lazily. if (RecordDeclTypes.count(Context.getTagDeclType(RD).getTypePtr())) ConvertRecordDeclType(RD); + + // If necessary, provide the full definition of a type only used with a + // declaration so far. + if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) + DI->completeFwdDecls(RD); } static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext, -- 2.40.0