From: Adrian Prantl Date: Thu, 10 Sep 2015 18:39:45 +0000 (+0000) Subject: Add a getDeclContextDescriptor() helper function to CGDebugInfo. (NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62c5ac041086e1707a13e4ec9aa93b49304e418e;p=clang Add a getDeclContextDescriptor() helper function to CGDebugInfo. (NFC) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247319 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 987e921432..61993f8d54 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/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(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(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(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(getTypeOrNull(QualType(Ty, 0))); if (T || shouldOmitDefinition(DebugKind, RD, CGM.getLangOpts())) { if (!T) - T = getOrCreateRecordFwdDecl( - Ty, getContextDescriptor(cast(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(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(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(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(FD->getDeclContext())) - FDContext = getContextDescriptor(cast(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(DC)); + VDContext = getContextDescriptor(cast(DC), TheCU); } llvm::DISubprogram * @@ -2460,7 +2461,7 @@ llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(const Decl *D) { return nullptr; // Setup context. - auto *S = getContextDescriptor(cast(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(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(getContextDescriptor(cast(DC))); + auto *Ctxt = cast(getDeclContextDescriptor(D)); return CreateRecordStaticField(D, Ctxt, cast(DC)); } @@ -3280,15 +3280,14 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, auto *VarD = cast(VD); if (VarD->isStaticDataMember()) { auto *RD = cast(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(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(NSDecl->getDeclContext())); + llvm::DIScope *Context = getDeclContextDescriptor(NSDecl); llvm::DINamespace *NS = DBuilder.createNameSpace(Context, NSDecl->getName(), FileD, LineNo); NameSpaceCache[NSDecl].reset(NS); diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 99272e60eb..e635cb28f1 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -366,8 +366,11 @@ private: llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD, uint64_t *OffSet); - /// Get context info for the decl. - llvm::DIScope *getContextDescriptor(const Decl *Decl); + /// Get context info for the DeclContext of \p Decl. + llvm::DIScope *getDeclContextDescriptor(const Decl *D); + /// Get context info for a given DeclContext \p Decl. + llvm::DIScope *getContextDescriptor(const Decl *Context, + llvm::DIScope *Default); llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);