xref: /aosp_15_r20/external/llvm/test/DebugInfo/Generic/debug-info-always-inline.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -always-inline -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker;
3*9880d681SAndroid Build Coastguard Worker; Generated from the following C++ source with:
4*9880d681SAndroid Build Coastguard Worker; clang -cc1 -disable-llvm-optzns -emit-llvm -g -stack-protector 2 test.cpp
5*9880d681SAndroid Build Coastguard Worker;
6*9880d681SAndroid Build Coastguard Worker; /* BEGIN SOURCE */
7*9880d681SAndroid Build Coastguard Worker; int __attribute__((always_inline)) foo()
8*9880d681SAndroid Build Coastguard Worker; {
9*9880d681SAndroid Build Coastguard Worker;    int arr[10];
10*9880d681SAndroid Build Coastguard Worker;    arr[0] = 5;
11*9880d681SAndroid Build Coastguard Worker;    int sum = 4;
12*9880d681SAndroid Build Coastguard Worker;    return sum;
13*9880d681SAndroid Build Coastguard Worker; }
14*9880d681SAndroid Build Coastguard Worker;
15*9880d681SAndroid Build Coastguard Worker; extern void bar();
16*9880d681SAndroid Build Coastguard Worker;
17*9880d681SAndroid Build Coastguard Worker; int main()
18*9880d681SAndroid Build Coastguard Worker; {
19*9880d681SAndroid Build Coastguard Worker;   bar();
20*9880d681SAndroid Build Coastguard Worker;   int i = foo();
21*9880d681SAndroid Build Coastguard Worker;   return i;
22*9880d681SAndroid Build Coastguard Worker; }
23*9880d681SAndroid Build Coastguard Worker; /* END SOURCE */
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; The patch that includes this test case, is addressing the following issue:
26*9880d681SAndroid Build Coastguard Worker;
27*9880d681SAndroid Build Coastguard Worker; When functions are inlined, instructions without debug information
28*9880d681SAndroid Build Coastguard Worker; are attributed with the call site's DebugLoc. After inlining, inlined static
29*9880d681SAndroid Build Coastguard Worker; allocas are moved to the caller's entry block, adjacent to the caller's original
30*9880d681SAndroid Build Coastguard Worker; static alloca instructions. By retaining the call site's DebugLoc, these instructions
31*9880d681SAndroid Build Coastguard Worker; may cause instructions that are subsequently inserted at the entry block to pick
32*9880d681SAndroid Build Coastguard Worker; up the same DebugLoc.
33*9880d681SAndroid Build Coastguard Worker;
34*9880d681SAndroid Build Coastguard Worker; In the offending case stack protection inserts an instruction at the caller's
35*9880d681SAndroid Build Coastguard Worker; entry block, which inadvertently picks up the inlined call's DebugLoc, because
36*9880d681SAndroid Build Coastguard Worker; the entry block's first instruction is the recently moved inlined alloca instruction.
37*9880d681SAndroid Build Coastguard Worker;
38*9880d681SAndroid Build Coastguard Worker; The stack protection instruction then becomes part of the function prologue, with the
39*9880d681SAndroid Build Coastguard Worker; result that the line number that is associated with the stack protection instruction
40*9880d681SAndroid Build Coastguard Worker; is deemed to be the end of the function prologue. Since this line number is the
41*9880d681SAndroid Build Coastguard Worker; call site's line number, setting a breakpoint at the function in the debugger
42*9880d681SAndroid Build Coastguard Worker; will make the user stop at the line of the inlined call.
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker; Note that without the stack protection instruction this effect would not occur
45*9880d681SAndroid Build Coastguard Worker; because the allocas all get collapsed into a single instruction that reserves
46*9880d681SAndroid Build Coastguard Worker; stack space and have no further influence on the prologue's line number information.
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker; The selected solution is to not attribute static allocas with the call site's
50*9880d681SAndroid Build Coastguard Worker; DebugLoc.
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker; At some point in the future, it may be desirable to describe the inlining
53*9880d681SAndroid Build Coastguard Worker; in the alloca instructions, but then the code that handles prologues must
54*9880d681SAndroid Build Coastguard Worker; be able to handle this correctly, including the late insertion of instructions
55*9880d681SAndroid Build Coastguard Worker; into it.
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker; In this context it is also important to distingush between functions
58*9880d681SAndroid Build Coastguard Worker; with the "nodebug" attribute and those without it. Alloca instructions from
59*9880d681SAndroid Build Coastguard Worker; nodebug functions should continue to have no DebugLoc, whereas those from
60*9880d681SAndroid Build Coastguard Worker; non-nodebug functions (i.e. functions with debug information) may want to
61*9880d681SAndroid Build Coastguard Worker; have their DebugLocs augmented with inlining information.
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker; Make sure that after inlining the call to foo() the alloca instructions for
65*9880d681SAndroid Build Coastguard Worker; arr.i and sum.i do not retain debug information.
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker; CHECK: %arr.i = alloca [10 x i32], align {{[0-9]*$}}
68*9880d681SAndroid Build Coastguard Worker; CHECK: %sum.i = alloca i32, align {{[0-9]*$}}
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker; ModuleID = 'test.cpp'
72*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
73*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu"
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Worker; Function Attrs: alwaysinline nounwind sspstrong
76*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z3foov() #0 {
77*9880d681SAndroid Build Coastguard Workerentry:
78*9880d681SAndroid Build Coastguard Worker  %arr = alloca [10 x i32], align 16
79*9880d681SAndroid Build Coastguard Worker  %sum = alloca i32, align 4
80*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata [10 x i32]* %arr, metadata !14), !dbg !18
81*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %arr, i32 0, i64 0, !dbg !19
82*9880d681SAndroid Build Coastguard Worker  store i32 5, i32* %arrayidx, align 4, !dbg !19
83*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %sum, metadata !20), !dbg !21
84*9880d681SAndroid Build Coastguard Worker  store i32 4, i32* %sum, align 4, !dbg !21
85*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %sum, align 4, !dbg !22
86*9880d681SAndroid Build Coastguard Worker  ret i32 %0, !dbg !22
87*9880d681SAndroid Build Coastguard Worker}
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
90*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata) #1
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind sspstrong
93*9880d681SAndroid Build Coastguard Workerdefine i32 @main() #2 {
94*9880d681SAndroid Build Coastguard Workerentry:
95*9880d681SAndroid Build Coastguard Worker  %retval = alloca i32, align 4
96*9880d681SAndroid Build Coastguard Worker  %i = alloca i32, align 4
97*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %retval
98*9880d681SAndroid Build Coastguard Worker  call void @_Z3barv(), !dbg !23
99*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %i, metadata !24), !dbg !25
100*9880d681SAndroid Build Coastguard Worker  %call = call i32 @_Z3foov(), !dbg !25
101*9880d681SAndroid Build Coastguard Worker  store i32 %call, i32* %i, align 4, !dbg !25
102*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %i, align 4, !dbg !26
103*9880d681SAndroid Build Coastguard Worker  ret i32 %0, !dbg !26
104*9880d681SAndroid Build Coastguard Worker}
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Workerdeclare void @_Z3barv() #3
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Workerattributes #0 = { alwaysinline nounwind sspstrong "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
109*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone }
110*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind sspstrong "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
111*9880d681SAndroid Build Coastguard Workerattributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0}
114*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!11, !12}
115*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!13}
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker!0 = !{i32 786449, !1, i32 4, !"clang version 3.6.0 (217844)", i1 false, !"", i32 0, !2, !2, !3, !2, !2, !"", i32 1} ; [ DW_TAG_compile_unit ] [/home/user/test/<stdin>] [DW_LANG_C_plus_plus]
118*9880d681SAndroid Build Coastguard Worker!1 = !{!"<stdin>", !"/home/user/test"}
119*9880d681SAndroid Build Coastguard Worker!2 = !{}
120*9880d681SAndroid Build Coastguard Worker!3 = !{!4, !10}
121*9880d681SAndroid Build Coastguard Worker!4 = !{i32 786478, !5, !6, !"foo", !"foo", !"_Z3foov", i32 1, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z3foov, null, null, !2, i32 2} ; [ DW_TAG_subprogram ] [line 1] [def] [scope 2] [foo]
122*9880d681SAndroid Build Coastguard Worker!5 = !{!"test.cpp", !"/home/user/test"}
123*9880d681SAndroid Build Coastguard Worker!6 = !{i32 786473, !5}          ; [ DW_TAG_file_type ] [/home/user/test/test.cpp]
124*9880d681SAndroid Build Coastguard Worker!7 = !{i32 786453, i32 0, null, !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, !8, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
125*9880d681SAndroid Build Coastguard Worker!8 = !{!9}
126*9880d681SAndroid Build Coastguard Worker!9 = !{i32 786468, null, null, !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
127*9880d681SAndroid Build Coastguard Worker!10 = !{i32 786478, !5, !6, !"main", !"main", !"", i32 11, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, !2, i32 12} ; [ DW_TAG_subprogram ] [line 11] [def] [scope 12] [main]
128*9880d681SAndroid Build Coastguard Worker!11 = !{i32 2, !"Dwarf Version", i32 4}
129*9880d681SAndroid Build Coastguard Worker!12 = !{i32 2, !"Debug Info Version", i32 1}
130*9880d681SAndroid Build Coastguard Worker!13 = !{!"clang version 3.6.0 (217844)"}
131*9880d681SAndroid Build Coastguard Worker!14 = !{i32 786688, !4, !"arr", !6, i32 3, !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [arr] [line 3]
132*9880d681SAndroid Build Coastguard Worker!15 = !{i32 786433, null, null, !"", i32 0, i64 320, i64 32, i32 0, i32 0, !9, !16, i32 0, null, null, null} ; [ DW_TAG_array_type ] [line 0, size 320, align 32, offset 0] [from int]
133*9880d681SAndroid Build Coastguard Worker!16 = !{!17}
134*9880d681SAndroid Build Coastguard Worker!17 = !{i32 786465, i64 0, i64 10}       ; [ DW_TAG_subrange_type ] [0, 9]
135*9880d681SAndroid Build Coastguard Worker!18 = !DILocation(line: 3, scope: !4)
136*9880d681SAndroid Build Coastguard Worker!19 = !DILocation(line: 4, scope: !4)
137*9880d681SAndroid Build Coastguard Worker!20 = !{i32 786688, !4, !"sum", !6, i32 5, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [sum] [line 5]
138*9880d681SAndroid Build Coastguard Worker!21 = !DILocation(line: 5, scope: !4)
139*9880d681SAndroid Build Coastguard Worker!22 = !DILocation(line: 6, scope: !4)
140*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 13, scope: !10)
141*9880d681SAndroid Build Coastguard Worker!24 = !{i32 786688, !10, !"i", !6, i32 14, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [i] [line 14]
142*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 14, scope: !10)
143*9880d681SAndroid Build Coastguard Worker!26 = !DILocation(line: 15, scope: !10)
144