From 1c1417edc0d2b8b154ca227ab2337c2c25f1fa76 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 9 Nov 2016 21:43:51 +0000 Subject: [PATCH] Use an artificial debug location for non-virtual thunks. Thunks are artificial and have no corresponding source location except for the line number on the DISubprogram, which is marked as artificial. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286400 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 5 ++--- lib/CodeGen/CGVTables.cpp | 9 +++++++-- test/CodeGenCXX/debug-info-thunk.cpp | 13 +++++++++++-- test/CodeGenCXX/debug-info-windows-dtor.cpp | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index c4e7ffdd54..ef4fb06c18 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -3032,9 +3032,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, if (!HasDecl || D->isImplicit()) { Flags |= llvm::DINode::FlagArtificial; - // Artificial functions without a location should not silently reuse CurLoc. - if (Loc.isInvalid()) - CurLoc = SourceLocation(); + // Artificial functions should not silently reuse CurLoc. + CurLoc = SourceLocation(); } unsigned LineNo = getLineNumber(Loc); unsigned ScopeLine = getLineNumber(ScopeLoc); diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 43c59e455e..3999c158d9 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -229,8 +229,11 @@ void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD, CGM.getCXXABI().addImplicitStructorParams(*this, ResultType, FunctionArgs); // Start defining the function. + auto NL = ApplyDebugLocation::CreateEmpty(*this); StartFunction(GlobalDecl(), ResultType, Fn, FnInfo, FunctionArgs, - MD->getLocation(), MD->getLocation()); + MD->getLocation()); + // Create a scope with an artificial location for the body of this function. + auto AL = ApplyDebugLocation::CreateArtificial(*this); // Since we didn't pass a GlobalDecl to StartFunction, do this ourselves. CGM.getCXXABI().EmitInstanceFunctionProlog(*this); @@ -282,7 +285,7 @@ void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr, // Add the rest of the arguments. for (const ParmVarDecl *PD : MD->parameters()) - EmitDelegateCallArg(CallArgs, PD, PD->getLocStart()); + EmitDelegateCallArg(CallArgs, PD, SourceLocation()); const FunctionProtoType *FPT = MD->getType()->getAs(); @@ -396,6 +399,8 @@ void CodeGenFunction::generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk) { StartThunk(Fn, GD, FnInfo); + // Create a scope with an artificial location for the body of this function. + auto AL = ApplyDebugLocation::CreateArtificial(*this); // Get our callee. llvm::Type *Ty = diff --git a/test/CodeGenCXX/debug-info-thunk.cpp b/test/CodeGenCXX/debug-info-thunk.cpp index cd00ec9373..5c9f2a4fd3 100644 --- a/test/CodeGenCXX/debug-info-thunk.cpp +++ b/test/CodeGenCXX/debug-info-thunk.cpp @@ -13,8 +13,17 @@ struct C : A, B { }; void C::f() { } - -// CHECK: !DISubprogram(linkageName: "_ZThn{{[48]}}_N1C1fEv" +// CHECK: define void @_ZThn{{[48]}}_N1C1fEv +// CHECK-SAME: !dbg ![[SP:[0-9]+]] +// CHECK-NOT: {{ret }} +// CHECK: = load{{.*}} !dbg ![[DBG:[0-9]+]] +// CHECK-NOT: {{ret }} +// CHECK: ret void, !dbg ![[DBG]] +// +// CHECK: ![[SP]] = distinct !DISubprogram(linkageName: "_ZThn{{[48]}}_N1C1fEv" // CHECK-SAME: line: 15 // CHECK-SAME: isDefinition: true +// CHECK-SAME: DIFlagArtificial // CHECK-SAME: ){{$}} +// +// CHECK: ![[DBG]] = !DILocation(line: 0 diff --git a/test/CodeGenCXX/debug-info-windows-dtor.cpp b/test/CodeGenCXX/debug-info-windows-dtor.cpp index e5a51abae6..8eb744a61b 100644 --- a/test/CodeGenCXX/debug-info-windows-dtor.cpp +++ b/test/CodeGenCXX/debug-info-windows-dtor.cpp @@ -19,4 +19,4 @@ template struct AB; // CHECK: define // CHECK: [[THUNK_VEC_DEL_DTOR]] = distinct !DISubprogram -// CHECK: [[THUNK_LOC]] = !DILocation(line: 15, scope: [[THUNK_VEC_DEL_DTOR]]) +// CHECK: [[THUNK_LOC]] = !DILocation(line: 0, scope: [[THUNK_VEC_DEL_DTOR]]) -- 2.40.0