diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-10-25 10:18:50 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-10-25 10:18:50 +0000 |
commit | 34b41f80aad3679c545a4ba9bca9c1a318d41844 (patch) | |
tree | 08aa80f7049b2162799a8dbaa4436351fbf67208 /lib/CodeGen/CGDebugInfo.cpp | |
parent | d9a2d5bdb747836917c2a5f7e12d075ec6762c77 (diff) |
Initialize debug info for special cases of functions that lack declarations and are generated by Clang (global initializers/destructors, thunks) . Fixes PR13942.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 5291fc838c..730f8661f0 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2050,14 +2050,22 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, FnBeginRegionCount.push_back(LexicalBlockStack.size()); const Decl *D = GD.getDecl(); + // Function may lack declaration in source code if it is created by Clang + // CodeGen (examples: _GLOBAL__I_a, __cxx_global_array_dtor, thunk). + bool HasDecl = (D != 0); // Use the location of the declaration. - SourceLocation Loc = D->getLocation(); - + SourceLocation Loc; + if (HasDecl) + Loc = D->getLocation(); + unsigned Flags = 0; llvm::DIFile Unit = getOrCreateFile(Loc); llvm::DIDescriptor FDContext(Unit); llvm::DIArray TParamsArray; - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + if (!HasDecl) { + // Use llvm function name. + Name = Fn->getName(); + } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { // If there is a DISubprogram for this function available then use it. llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator FI = SPCache.find(FD->getCanonicalDecl()); @@ -2104,12 +2112,13 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, Name = Name.substr(1); unsigned LineNo = getLineNumber(Loc); - if (D->isImplicit()) + if (!HasDecl || D->isImplicit()) Flags |= llvm::DIDescriptor::FlagArtificial; llvm::DIType DIFnType; llvm::DISubprogram SPDecl; - if (CGM.getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) { + if (HasDecl && + CGM.getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) { DIFnType = getOrCreateFunctionType(D, FnType, Unit); SPDecl = getFunctionDeclaration(D); } else { @@ -2132,7 +2141,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, // Push function on region stack. llvm::MDNode *SPN = SP; LexicalBlockStack.push_back(SPN); - RegionMap[D] = llvm::WeakVH(SP); + if (HasDecl) + RegionMap[D] = llvm::WeakVH(SP); } /// EmitLocation - Emit metadata to indicate a change in line/column |