diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-09-10 18:39:45 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-09-10 18:39:45 +0000 |
commit | 6ec370a4ed9a2545dda7549953c8f198cc26cd9e (patch) | |
tree | 1328bdf32a38cd39336e3b75a03e12e5b5443f04 /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | bb34b60359ec45607b1cd4e875377cacbe5564ab (diff) | |
download | bcm5719-llvm-6ec370a4ed9a2545dda7549953c8f198cc26cd9e.tar.gz bcm5719-llvm-6ec370a4ed9a2545dda7549953c8f198cc26cd9e.zip |
Add a getDeclContextDescriptor() helper function to CGDebugInfo. (NFC)
llvm-svn: 247319
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 987e9214320..61993f8d542 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -147,9 +147,14 @@ void CGDebugInfo::setLocation(SourceLocation Loc) { } } -llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context) { +llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(const Decl *D) { + return getContextDescriptor(cast<Decl>(D->getDeclContext()), TheCU); +} + +llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context, + llvm::DIScope *Default) { if (!Context) - return TheCU; + return Default; auto I = RegionMap.find(Context); if (I != RegionMap.end()) { @@ -165,7 +170,7 @@ llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context) { if (!RDecl->isDependentType()) return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl), getOrCreateMainFile()); - return TheCU; + return Default; } StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { @@ -770,7 +775,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, SourceLocation Loc = AliasDecl->getLocation(); return DBuilder.createTypedef( Src, internString(OS.str()), getOrCreateFile(Loc), getLineNumber(Loc), - getContextDescriptor(cast<Decl>(AliasDecl->getDeclContext()))); + getDeclContextDescriptor(AliasDecl)); } llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty, @@ -783,7 +788,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty, return DBuilder.createTypedef( getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit), Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc), - getContextDescriptor(cast<Decl>(Ty->getDecl()->getDeclContext()))); + getDeclContextDescriptor(Ty->getDecl())); } llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty, @@ -1510,8 +1515,7 @@ llvm::DIType *CGDebugInfo::CreateType(const RecordType *Ty) { llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(QualType(Ty, 0))); if (T || shouldOmitDefinition(DebugKind, RD, CGM.getLangOpts())) { if (!T) - T = getOrCreateRecordFwdDecl( - Ty, getContextDescriptor(cast<Decl>(RD->getDeclContext()))); + T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD)); return T; } @@ -1939,8 +1943,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) { // If this is just a forward declaration, construct an appropriately // marked node and just return it. if (!ED->getDefinition()) { - llvm::DIScope *EDContext = - getContextDescriptor(cast<Decl>(ED->getDeclContext())); + llvm::DIScope *EDContext = getDeclContextDescriptor(ED); llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); unsigned Line = getLineNumber(ED->getLocation()); StringRef EDName = ED->getName(); @@ -1980,8 +1983,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) { llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); unsigned Line = getLineNumber(ED->getLocation()); - llvm::DIScope *EnumContext = - getContextDescriptor(cast<Decl>(ED->getDeclContext())); + llvm::DIScope *EnumContext = getDeclContextDescriptor(ED); llvm::DIType *ClassTy = ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : nullptr; return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit, @@ -2228,8 +2230,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { unsigned Line = getLineNumber(RD->getLocation()); StringRef RDName = getClassName(RD); - llvm::DIScope *RDContext = - getContextDescriptor(cast<Decl>(RD->getDeclContext())); + llvm::DIScope *RDContext = getDeclContextDescriptor(RD); // If we ended up creating the type during the context chain construction, // just return that. @@ -2326,7 +2327,7 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit, FDContext = getOrCreateNameSpace(NSDecl); else if (const RecordDecl *RDecl = dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) - FDContext = getContextDescriptor(cast<Decl>(RDecl)); + FDContext = getContextDescriptor(RDecl, TheCU); // Collect template parameters. TParamsArray = CollectFunctionTemplateParams(FD, Unit); } @@ -2374,7 +2375,7 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, // outside the class by putting it in the global scope. if (DC->isRecord()) DC = CGM.getContext().getTranslationUnitDecl(); - VDContext = getContextDescriptor(dyn_cast<Decl>(DC)); + VDContext = getContextDescriptor(cast<Decl>(DC), TheCU); } llvm::DISubprogram * @@ -2460,7 +2461,7 @@ llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(const Decl *D) { return nullptr; // Setup context. - auto *S = getContextDescriptor(cast<Decl>(D->getDeclContext())); + auto *S = getDeclContextDescriptor(D); auto MI = SPCache.find(FD->getCanonicalDecl()); if (MI == SPCache.end()) { @@ -3050,7 +3051,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, unsigned column = getColumnNumber(loc); // Build the debug-info type for the block literal. - getContextDescriptor(cast<Decl>(blockDecl->getDeclContext())); + getDeclContextDescriptor(blockDecl); const llvm::StructLayout *blockLayout = CGM.getDataLayout().getStructLayout(block.StructureType); @@ -3194,8 +3195,7 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { // If the member wasn't found in the cache, lazily construct and add it to the // type (used when a limited form of the type is emitted). auto DC = D->getDeclContext(); - auto *Ctxt = - cast<llvm::DICompositeType>(getContextDescriptor(cast<Decl>(DC))); + auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D)); return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC)); } @@ -3280,15 +3280,14 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, auto *VarD = cast<VarDecl>(VD); if (VarD->isStaticDataMember()) { auto *RD = cast<RecordDecl>(VarD->getDeclContext()); - getContextDescriptor(RD); + getDeclContextDescriptor(VarD); // Ensure that the type is retained even though it's otherwise unreferenced. RetainedTypes.push_back( CGM.getContext().getRecordType(RD).getAsOpaquePtr()); return; } - llvm::DIScope *DContext = - getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext())); + llvm::DIScope *DContext = getDeclContextDescriptor(VD); auto &GV = DeclCache[VD]; if (GV) @@ -3301,7 +3300,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) { if (!LexicalBlockStack.empty()) return LexicalBlockStack.back(); - return getContextDescriptor(D); + return getContextDescriptor(D, TheCU); } void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) { @@ -3370,8 +3369,7 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { unsigned LineNo = getLineNumber(NSDecl->getLocation()); llvm::DIFile *FileD = getOrCreateFile(NSDecl->getLocation()); - llvm::DIScope *Context = - getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext())); + llvm::DIScope *Context = getDeclContextDescriptor(NSDecl); llvm::DINamespace *NS = DBuilder.createNameSpace(Context, NSDecl->getName(), FileD, LineNo); NameSpaceCache[NSDecl].reset(NS); |