diff options
author | Eric Christopher <echristo@apple.com> | 2012-02-18 00:50:17 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2012-02-18 00:50:17 +0000 |
commit | 7ff0c5d30d365ba5d4f08e1d2fcea0370b21699b (patch) | |
tree | 9ac2aeff8a0226a9bbde79990e4372aeb42d5608 /lib/CodeGen/CGDebugInfo.cpp | |
parent | 1486d2c5d73302bdfdb1cece09d95958052c9cdb (diff) |
Add in a caching mechanism so that forward declarations are replaced
with full types if they exist.
rdar://10809898 and rdar://10209967 and rdar://10400981
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index aa7f150fcf..75e99ac5f2 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -553,9 +553,7 @@ llvm::DIType CGDebugInfo::CreatePointeeType(QualType PointeeTy, RecordDecl *RD = RTy->getDecl(); llvm::DIDescriptor FDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext())); - llvm::DIType RetTy = createRecordFwdDecl(RD, FDContext); - TypeCache[PointeeTy.getAsOpaquePtr()] = RetTy; - return RetTy; + return createRecordFwdDecl(RD, FDContext); } return getOrCreateType(PointeeTy, Unit); @@ -1616,6 +1614,10 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) { // Otherwise create the type. llvm::DIType Res = CreateTypeNode(Ty, Unit); + + llvm::DIType TC = getTypeOrNull(Ty); + if (TC.Verify() && TC.isForwardDecl()) + ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), TC)); // And update the type cache. TypeCache[Ty.getAsOpaquePtr()] = Res; @@ -1725,6 +1727,9 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(QualType Ty, // Otherwise create the type. llvm::DIType Res = CreateLimitedTypeNode(Ty, Unit); + if (T.Verify() && T.isForwardDecl()) + ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), T)); + // And update the type cache. TypeCache[Ty.getAsOpaquePtr()] = Res; return Res; @@ -1747,11 +1752,8 @@ llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { // If this is just a forward declaration, construct an appropriately // marked node and just return it. - if (!RD->getDefinition()) { - llvm::DIType RTy = createRecordFwdDecl(RD, RDContext); - TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RTy; - return RTy; - } + if (!RD->getDefinition()) + return createRecordFwdDecl(RD, RDContext); uint64_t Size = CGM.getContext().getTypeSize(Ty); uint64_t Align = CGM.getContext().getTypeAlign(Ty); @@ -2561,3 +2563,25 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { NameSpaceCache[NSDecl] = llvm::WeakVH(NS); return NS; } + +void CGDebugInfo::finalize(void) { + for (std::vector<std::pair<void *, llvm::WeakVH> >::const_iterator VI + = ReplaceMap.begin(), VE = ReplaceMap.end(); VI != VE; ++VI) { + llvm::DIType Ty, RepTy; + // Verify that the debug info still exists. + if (&*VI->second) + Ty = llvm::DIType(cast<llvm::MDNode>(VI->second)); + + llvm::DenseMap<void *, llvm::WeakVH>::iterator it = + TypeCache.find(VI->first); + if (it != TypeCache.end()) { + // Verify that the debug info still exists. + if (&*it->second) + RepTy = llvm::DIType(cast<llvm::MDNode>(it->second)); + } + + if (Ty.Verify() && RepTy.Verify()) + Ty.replaceAllUsesWith(RepTy); + } + DBuilder.finalize(); +} |