diff options
author | Amjad Aboud <amjad.aboud@intel.com> | 2016-02-23 13:37:18 +0000 |
---|---|---|
committer | Amjad Aboud <amjad.aboud@intel.com> | 2016-02-23 13:37:18 +0000 |
commit | 30e7a8f694a19553f64b3a3a5de81ce317b9ec2f (patch) | |
tree | 2aebeb9b2230ca22f960ade5a34ddc4c64d81e8b /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | fc8f296782caf06e71fc7b1ed215173a388f3b77 (diff) | |
download | bcm5719-llvm-30e7a8f694a19553f64b3a3a5de81ce317b9ec2f.tar.gz bcm5719-llvm-30e7a8f694a19553f64b3a3a5de81ce317b9ec2f.zip |
Supporting all entities declared in lexical scope in LLVM debug info.
Differential Revision: http://reviews.llvm.org/D15977
llvm-svn: 261634
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 52bd805b81c..fe497f6b93f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -831,15 +831,18 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile *Unit) { + TypedefNameDecl *TD = Ty->getDecl(); // We don't set size information, but do specify where the typedef was // declared. - SourceLocation Loc = Ty->getDecl()->getLocation(); + SourceLocation Loc = TD->getLocation(); + + llvm::DIScope *TDContext = getDeclarationLexicalScope(*TD, QualType(Ty, 0)); // Typedefs are derived from some other type. return DBuilder.createTypedef( getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit), Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc), - getDeclContextDescriptor(Ty->getDecl())); + TDContext); } llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty, @@ -1472,6 +1475,23 @@ llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D, return T; } +void CGDebugInfo::recordDeclarationLexicalScope(const Decl &D) { + assert(LexicalBlockMap.find(&D) == LexicalBlockMap.end() && + "D is already mapped to lexical block scope"); + if (!LexicalBlockStack.empty()) + LexicalBlockMap[&D] = LexicalBlockStack.back(); +} + +llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl &D, + QualType Ty) { + auto I = LexicalBlockMap.find(&D); + if (I != LexicalBlockMap.end()) { + RetainedTypes.push_back(Ty.getAsOpaquePtr()); + return I->second; + } + return getDeclContextDescriptor(cast<Decl>(&D)); +} + void CGDebugInfo::completeType(const EnumDecl *ED) { if (DebugKind <= codegenoptions::DebugLineTablesOnly) return; @@ -2068,7 +2088,8 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) { // Cache the enum type so it is available when building the declcontext // and replace the declcontect with the real thing. TypeCache[Ty].reset(RetTy); - TmpContext->replaceAllUsesWith(getDeclContextDescriptor(ED)); + TmpContext->replaceAllUsesWith( + getDeclarationLexicalScope(*ED, QualType(Ty, 0))); ReplaceMap.emplace_back( std::piecewise_construct, std::make_tuple(Ty), @@ -2103,7 +2124,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) { llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); unsigned Line = getLineNumber(ED->getLocation()); - llvm::DIScope *EnumContext = getDeclContextDescriptor(ED); + llvm::DIScope *EnumContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0)); llvm::DIType *ClassTy = ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : nullptr; return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit, @@ -2364,7 +2385,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { unsigned Line = getLineNumber(RD->getLocation()); StringRef RDName = getClassName(RD); - llvm::DIScope *RDContext = getDeclContextDescriptor(RD); + llvm::DIScope *RDContext = getDeclarationLexicalScope(*RD, QualType(Ty, 0)); // If we ended up creating the type during the context chain construction, // just return that. @@ -2511,8 +2532,15 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, if (DC->isRecord()) DC = CGM.getContext().getTranslationUnitDecl(); - llvm::DIScope *Mod = getParentModuleOrNull(VD); - VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU); + if (VD->isStaticLocal()) { + // Get context for static locals (that are technically globals) the same way + // we do for "local" locals -- by using current lexical block. + assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); + VDContext = LexicalBlockStack.back(); + } else { + llvm::DIScope *Mod = getParentModuleOrNull(VD); + VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU); + } } llvm::DISubprogram * |