diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 22 | ||||
-rw-r--r-- | lib/CodeGen/CGDeclCXX.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/CGVTables.cpp | 5 |
4 files changed, 36 insertions, 7 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 049294ec01..7915c37175 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -1650,6 +1650,8 @@ generateByrefCopyHelper(CodeGenFunction &CGF, SC_None, false, false); + // Initialize debug info if necessary. + CGF.maybeInitializeDebugInfo(); CGF.StartFunction(FD, R, Fn, FI, args, SourceLocation()); if (byrefInfo.needsCopy()) { @@ -1720,6 +1722,8 @@ generateByrefDisposeHelper(CodeGenFunction &CGF, SC_Static, SC_None, false, false); + // Initialize debug info if necessary. + CGF.maybeInitializeDebugInfo(); CGF.StartFunction(FD, R, Fn, FI, args, SourceLocation()); if (byrefInfo.needsDispose()) { 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 diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 9f7ee1ecee..67f710db0e 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -163,6 +163,9 @@ static llvm::Constant *createAtExitStub(CodeGenModule &CGM, CodeGenFunction CGF(CGM); + // Initialize debug info if needed. + CGF.maybeInitializeDebugInfo(); + CGF.StartFunction(GlobalDecl(), CGM.getContext().VoidTy, fn, CGM.getTypes().arrangeNullaryFunction(), FunctionArgList(), SourceLocation()); @@ -345,6 +348,9 @@ void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, llvm::Constant **Decls, unsigned NumDecls) { + // Initialize debug info if needed. + maybeInitializeDebugInfo(); + StartFunction(GlobalDecl(), getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(), FunctionArgList(), SourceLocation()); @@ -370,6 +376,9 @@ void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, void CodeGenFunction::GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> > &DtorsAndObjects) { + // Initialize debug info if needed. + maybeInitializeDebugInfo(); + StartFunction(GlobalDecl(), getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(), FunctionArgList(), SourceLocation()); @@ -406,6 +415,9 @@ CodeGenFunction::generateDestroyHelper(llvm::Constant *addr, llvm::Function *fn = CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor"); + // Initialize debug info if needed. + maybeInitializeDebugInfo(); + StartFunction(GlobalDecl(), getContext().VoidTy, fn, FI, args, SourceLocation()); diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index a1a661be84..5b37fe4b96 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -333,7 +333,10 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn, FunctionArgs.push_back(Param); } - + + // Initialize debug info if needed. + maybeInitializeDebugInfo(); + StartFunction(GlobalDecl(), ResultType, Fn, FnInfo, FunctionArgs, SourceLocation()); |