From 6dc689670cb6c83183a37b2ab45af48422028796 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 15 Aug 2013 22:30:23 +0000 Subject: [PATCH] DebugInfo: Split out the implementation of getStaticDataMemberDeclaration for future use llvm-svn: 188498 --- clang/lib/CodeGen/CGDebugInfo.cpp | 42 +++++++++++++++++-------------- clang/lib/CodeGen/CGDebugInfo.h | 1 + 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 9f138e7667de..049375f5d75f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2998,19 +2998,25 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, DbgDecl->setDebugLoc(llvm::DebugLoc::get(line, column, scope)); } -/// getStaticDataMemberDeclaration - If D is an out-of-class definition of -/// a static data member of a class, find its corresponding in-class -/// declaration. -llvm::DIDerivedType CGDebugInfo::getStaticDataMemberDeclaration(const VarDecl *D) { - if (D->isStaticDataMember()) { - llvm::DenseMap::iterator - MI = StaticDataMemberCache.find(D->getCanonicalDecl()); - if (MI != StaticDataMemberCache.end()) - // Verify the info still exists. - if (llvm::Value *V = MI->second) - return llvm::DIDerivedType(cast(V)); - } - return llvm::DIDerivedType(); +/// If D is an out-of-class definition of a static data member of a class, find +/// its corresponding in-class declaration. +llvm::DIDerivedType +CGDebugInfo::getStaticDataMemberDeclarationOrNull(const VarDecl *D) { + if (!D->isStaticDataMember()) + return llvm::DIDerivedType(); + return getStaticDataMemberDeclaration(D); +} + +llvm::DIDerivedType +CGDebugInfo::getStaticDataMemberDeclaration(const VarDecl *D) { + llvm::DenseMap::iterator + MI = StaticDataMemberCache.find(D->getCanonicalDecl()); + if (MI != StaticDataMemberCache.end()) + // Verify the info still exists. + if (llvm::Value *V = MI->second) + return llvm::DIDerivedType(cast(V)); + llvm_unreachable( + "A static data member declaration should be available at this point"); } /// EmitGlobalVariable - Emit information about a global variable. @@ -3042,11 +3048,9 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, LinkageName = StringRef(); llvm::DIDescriptor DContext = getContextDescriptor(dyn_cast(D->getDeclContext())); - llvm::DIGlobalVariable GV = - DBuilder.createStaticVariable(DContext, DeclName, LinkageName, Unit, - LineNo, getOrCreateType(T, Unit), - Var->hasInternalLinkage(), Var, - getStaticDataMemberDeclaration(D)); + llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( + DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), + Var->hasInternalLinkage(), Var, getStaticDataMemberDeclarationOrNull(D)); DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV))); } @@ -3094,7 +3098,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, return; llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( Unit, Name, Name, Unit, getLineNumber(VD->getLocation()), Ty, true, Init, - getStaticDataMemberDeclaration(cast(VD))); + getStaticDataMemberDeclarationOrNull(cast(VD))); DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV))); } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index f17d47ad37c2..6c4c34c3680d 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -357,6 +357,7 @@ private: /// getStaticDataMemberDeclaration - Return debug info descriptor to /// describe in-class static data member declaration for the given /// out-of-class definition. + llvm::DIDerivedType getStaticDataMemberDeclarationOrNull(const VarDecl *D); llvm::DIDerivedType getStaticDataMemberDeclaration(const VarDecl *D); /// getFunctionName - Get function name for the given FunctionDecl. If the