Skip to content

Commit a5c8ec4

Browse files
committed
[CGDebugInfo] Emit subprograms for decls when AT_tail_call is understood
Currently, clang emits subprograms for declared functions when the target debugger or DWARF standard is known to support entry values (DW_OP_entry_value & the GNU equivalent). Treat DW_AT_tail_call the same way to allow debuggers to follow cross-TU tail calls. Pre-patch debug session with a cross-TU tail call: ``` * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f99 main`main at a.c:8:10 [opt] ``` Post-patch (note that the tail-calling frame, "helper", is visible): ``` * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f80 main`helper [opt] [artificial] frame #2: 0x0000000100000f99 main`main at a.c:8:10 [opt] ``` rdar://46577651 Differential Revision: https://reviews.llvm.org/D69743
1 parent dc34b1c commit a5c8ec4

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -3748,9 +3748,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
37483748
void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
37493749
QualType CalleeType,
37503750
const FunctionDecl *CalleeDecl) {
3751-
auto &CGOpts = CGM.getCodeGenOpts();
3752-
if (!CGOpts.EnableDebugEntryValues || !CGM.getLangOpts().Optimize ||
3753-
!CallOrInvoke)
3751+
if (!CallOrInvoke || getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
37543752
return;
37553753

37563754
auto *Func = CallOrInvoke->getCalledFunction();
@@ -4824,10 +4822,10 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
48244822
bool SupportsDWARFv4Ext =
48254823
CGM.getCodeGenOpts().DwarfVersion == 4 &&
48264824
(CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
4827-
(CGM.getCodeGenOpts().EnableDebugEntryValues &&
4828-
CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB));
4825+
CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
48294826

4830-
if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
4827+
if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5 &&
4828+
!CGM.getCodeGenOpts().EnableDebugEntryValues)
48314829
return llvm::DINode::FlagZero;
48324830

48334831
return llvm::DINode::FlagAllCallsDescribed;

clang/test/CodeGen/debug-info-extern-call.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-EXT
2-
// CHECK-EXT: !DISubprogram(name: "fn1"
1+
// When entry values are emitted, expect a subprogram for extern decls so that
2+
// the dwarf generator can describe call site parameters at extern call sites.
3+
//
4+
// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=ENTRY-VAL
5+
// ENTRY-VAL: !DISubprogram(name: "fn1"
36

4-
// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
5-
// CHECK-NOT: !DISubprogram(name: "fn1"
7+
// Similarly, when the debugger tuning is gdb, expect a subprogram for extern
8+
// decls so that the dwarf generator can describe information needed for tail
9+
// call frame reconstrution.
10+
//
11+
// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm %s -o - | FileCheck %s -check-prefix=GDB
12+
// GDB: !DISubprogram(name: "fn1"
13+
//
14+
// Do not emit a subprogram for extern decls when entry values are disabled and
15+
// the tuning is not set to gdb.
16+
//
17+
// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o - | FileCheck %s -check-prefix=SCE
18+
// SCE-NOT: !DISubprogram(name: "fn1"
619

720
extern int fn1(int a, int b);
821

clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
// NO-ATTR-NOT: FlagAllCallsDescribed
5858

59+
// HAS-ATTR-DAG: DISubprogram(name: "declaration1", {{.*}}, flags: DIFlagPrototyped
5960
// HAS-ATTR-DAG: DISubprogram(name: "declaration2", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition
6061
// HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
6162
// HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition

llvm/test/DebugInfo/X86/dwarf-callsite-related-attrs.ll

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525

2626
@sink = global i32 0, align 4, !dbg !0
2727

28+
define void @__has_no_subprogram() {
29+
entry:
30+
%0 = load volatile i32, i32* @sink, align 4
31+
%inc = add nsw i32 %0, 1
32+
store volatile i32 %inc, i32* @sink, align 4
33+
ret void
34+
}
35+
2836
; ASM: DW_TAG_subprogram
2937
; ASM: DW_AT_call_all_calls
3038
; OBJ: [[bat_sp:.*]]: DW_TAG_subprogram
@@ -70,6 +78,7 @@ entry:
7078
; OBJ: DW_AT_call_tail_call
7179
define void @_Z3foov() !dbg !25 {
7280
entry:
81+
tail call void @__has_no_subprogram()
7382
tail call void @_Z3barv(), !dbg !26
7483
tail call void @_Z3batv(), !dbg !27
7584
tail call void @_Z3barv(), !dbg !26

0 commit comments

Comments
 (0)