summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
diff options
context:
space:
mode:
authorAmjad Aboud <amjad.aboud@intel.com>2016-03-14 12:03:55 +0000
committerAmjad Aboud <amjad.aboud@intel.com>2016-03-14 12:03:55 +0000
commit22c997deb69f36b73675f0a07545de7127a0eb83 (patch)
tree6813b93fd1a6a3768c85bb9d908e37e9d65dddbe /clang/lib/CodeGen/CGDebugInfo.cpp
parentab0378b16c6accbd642e273400d718493423d7e1 (diff)
downloadbcm5719-llvm-22c997deb69f36b73675f0a07545de7127a0eb83.tar.gz
bcm5719-llvm-22c997deb69f36b73675f0a07545de7127a0eb83.zip
Recommitted r261634 "Supporting all entities declared in lexical scope in LLVM debug info."
After fixing PR26715 at r263379. llvm-svn: 263425
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp41
1 files changed, 34 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index e300ed538ac..6f39b093a46 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;
@@ -2057,7 +2077,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) {
// entered into the ReplaceMap: finalize() will replace the first
// FwdDecl with the second and then replace the second with
// complete type.
- llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
+ llvm::DIScope *EDContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0));
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
@@ -2101,7 +2121,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,
@@ -2362,7 +2382,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.
@@ -2509,8 +2529,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 *
OpenPOWER on IntegriCloud