Debug info: (Bugfix) Make sure artificial functions like _GLOBAL__I_a
are not associated with any source lines. Previously, if the Location of a Decl was empty, EmitFunctionStart would just keep using CurLoc, which would sometimes be correct (e.g., thunks) but in other cases would just point to a hilariously random location. This patch fixes this by completely eliminating all uses of CurLoc from EmitFunctionStart and rather have clients explicitly pass in a SourceLocation for the function header and the function body. rdar://problem/14985269 llvm-svn: 205999
This commit is contained in:
@@ -503,6 +503,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
|
||||
llvm::Function *Fn,
|
||||
const CGFunctionInfo &FnInfo,
|
||||
const FunctionArgList &Args,
|
||||
SourceLocation Loc,
|
||||
SourceLocation StartLoc) {
|
||||
const Decl *D = GD.getDecl();
|
||||
|
||||
@@ -580,9 +581,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
|
||||
QualType FnType =
|
||||
getContext().getFunctionType(RetTy, ArgTypes,
|
||||
FunctionProtoType::ExtProtoInfo());
|
||||
|
||||
DI->setLocation(StartLoc);
|
||||
DI->EmitFunctionStart(GD, FnType, CurFn, Builder);
|
||||
DI->EmitFunctionStart(GD, Loc, StartLoc, FnType, CurFn, Builder);
|
||||
}
|
||||
|
||||
if (ShouldInstrumentFunction())
|
||||
@@ -759,8 +758,24 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
|
||||
if (Stmt *Body = FD->getBody()) BodyRange = Body->getSourceRange();
|
||||
CurEHLocation = BodyRange.getEnd();
|
||||
|
||||
// Use the location of the start of the function to determine where
|
||||
// the function definition is located. By default use the location
|
||||
// of the declaration as the location for the subprogram. A function
|
||||
// may lack a declaration in the source code if it is created by code
|
||||
// gen. (examples: _GLOBAL__I_a, __cxx_global_array_dtor, thunk).
|
||||
SourceLocation Loc;
|
||||
if (FD) {
|
||||
Loc = FD->getLocation();
|
||||
|
||||
// If this is a function specialization then use the pattern body
|
||||
// as the location for the function.
|
||||
if (const FunctionDecl *SpecDecl = FD->getTemplateInstantiationPattern())
|
||||
if (SpecDecl->hasBody(SpecDecl))
|
||||
Loc = SpecDecl->getLocation();
|
||||
}
|
||||
|
||||
// Emit the standard function prologue.
|
||||
StartFunction(GD, ResTy, Fn, FnInfo, Args, BodyRange.getBegin());
|
||||
StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());
|
||||
|
||||
// Generate the body of the function.
|
||||
PGO.assignRegionCounters(GD.getDecl(), CurFn);
|
||||
|
||||
Reference in New Issue
Block a user