xref: /aosp_15_r20/external/llvm/test/DebugInfo/Generic/inline-debug-info.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -inline -S < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; Created from source
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker;
6*9880d681SAndroid Build Coastguard Worker;  1 // test.cpp
7*9880d681SAndroid Build Coastguard Worker;  2 extern int global_var;
8*9880d681SAndroid Build Coastguard Worker;  3 extern int test_ext(int k);
9*9880d681SAndroid Build Coastguard Worker;  4 int test (int k) {
10*9880d681SAndroid Build Coastguard Worker;  5   int k2 = test_ext(k);
11*9880d681SAndroid Build Coastguard Worker;  6   if (k2 > 100)
12*9880d681SAndroid Build Coastguard Worker;  7     return k2;
13*9880d681SAndroid Build Coastguard Worker;  8   return 0;
14*9880d681SAndroid Build Coastguard Worker;  9 }
15*9880d681SAndroid Build Coastguard Worker; 10
16*9880d681SAndroid Build Coastguard Worker; 11 int test2() {
17*9880d681SAndroid Build Coastguard Worker; 12   try
18*9880d681SAndroid Build Coastguard Worker; 13   {
19*9880d681SAndroid Build Coastguard Worker; 14     test(global_var);
20*9880d681SAndroid Build Coastguard Worker; 15   }
21*9880d681SAndroid Build Coastguard Worker; 16   catch (int e) {
22*9880d681SAndroid Build Coastguard Worker; 17     global_var = 0;
23*9880d681SAndroid Build Coastguard Worker; 18   }
24*9880d681SAndroid Build Coastguard Worker; 19   global_var = 1;
25*9880d681SAndroid Build Coastguard Worker; 20   return 0;
26*9880d681SAndroid Build Coastguard Worker; 21 }
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker; CHECK: _Z4testi.exit:
29*9880d681SAndroid Build Coastguard Worker; Make sure the branch instruction created during inlining has a debug location,
30*9880d681SAndroid Build Coastguard Worker; so the range of the inlined function is correct.
31*9880d681SAndroid Build Coastguard Worker; CHECK: br label %invoke.cont, !dbg [[MD:![0-9]+]]
32*9880d681SAndroid Build Coastguard Worker; The branch instruction has the source location of line 9 and its inlined location
33*9880d681SAndroid Build Coastguard Worker; has the source location of line 14.
34*9880d681SAndroid Build Coastguard Worker; CHECK: [[INL:![0-9]*]] = distinct !DILocation(line: 14, scope: {{.*}})
35*9880d681SAndroid Build Coastguard Worker; CHECK: [[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: [[INL]])
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; ModuleID = 'test.cpp'
38*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
39*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-darwin12.0.0"
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker@_ZTIi = external constant i8*
42*9880d681SAndroid Build Coastguard Worker@global_var = external global i32
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z4testi(i32 %k)  !dbg !4 {
45*9880d681SAndroid Build Coastguard Workerentry:
46*9880d681SAndroid Build Coastguard Worker  %retval = alloca i32, align 4
47*9880d681SAndroid Build Coastguard Worker  %k.addr = alloca i32, align 4
48*9880d681SAndroid Build Coastguard Worker  %k2 = alloca i32, align 4
49*9880d681SAndroid Build Coastguard Worker  store i32 %k, i32* %k.addr, align 4
50*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %k.addr, metadata !13, metadata !DIExpression()), !dbg !14
51*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %k2, metadata !15, metadata !DIExpression()), !dbg !16
52*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %k.addr, align 4, !dbg !16
53*9880d681SAndroid Build Coastguard Worker  %call = call i32 @_Z8test_exti(i32 %0), !dbg !16
54*9880d681SAndroid Build Coastguard Worker  store i32 %call, i32* %k2, align 4, !dbg !16
55*9880d681SAndroid Build Coastguard Worker  %1 = load i32, i32* %k2, align 4, !dbg !17
56*9880d681SAndroid Build Coastguard Worker  %cmp = icmp sgt i32 %1, 100, !dbg !17
57*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %if.then, label %if.end, !dbg !17
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
60*9880d681SAndroid Build Coastguard Worker  %2 = load i32, i32* %k2, align 4, !dbg !18
61*9880d681SAndroid Build Coastguard Worker  store i32 %2, i32* %retval, !dbg !18
62*9880d681SAndroid Build Coastguard Worker  br label %return, !dbg !18
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Workerif.end:                                           ; preds = %entry
65*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %retval, !dbg !19
66*9880d681SAndroid Build Coastguard Worker  br label %return, !dbg !19
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Workerreturn:                                           ; preds = %if.end, %if.then
69*9880d681SAndroid Build Coastguard Worker  %3 = load i32, i32* %retval, !dbg !20
70*9880d681SAndroid Build Coastguard Worker  ret i32 %3, !dbg !20
71*9880d681SAndroid Build Coastguard Worker}
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
74*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Workerdeclare i32 @_Z8test_exti(i32)
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z5test2v() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !10 {
79*9880d681SAndroid Build Coastguard Workerentry:
80*9880d681SAndroid Build Coastguard Worker  %exn.slot = alloca i8*
81*9880d681SAndroid Build Coastguard Worker  %ehselector.slot = alloca i32
82*9880d681SAndroid Build Coastguard Worker  %e = alloca i32, align 4
83*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* @global_var, align 4, !dbg !21
84*9880d681SAndroid Build Coastguard Worker  %call = invoke i32 @_Z4testi(i32 %0)
85*9880d681SAndroid Build Coastguard Worker          to label %invoke.cont unwind label %lpad, !dbg !21
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Workerinvoke.cont:                                      ; preds = %entry
88*9880d681SAndroid Build Coastguard Worker  br label %try.cont, !dbg !23
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Workerlpad:                                             ; preds = %entry
91*9880d681SAndroid Build Coastguard Worker  %1 = landingpad { i8*, i32 }
92*9880d681SAndroid Build Coastguard Worker          catch i8* bitcast (i8** @_ZTIi to i8*), !dbg !21
93*9880d681SAndroid Build Coastguard Worker  %2 = extractvalue { i8*, i32 } %1, 0, !dbg !21
94*9880d681SAndroid Build Coastguard Worker  store i8* %2, i8** %exn.slot, !dbg !21
95*9880d681SAndroid Build Coastguard Worker  %3 = extractvalue { i8*, i32 } %1, 1, !dbg !21
96*9880d681SAndroid Build Coastguard Worker  store i32 %3, i32* %ehselector.slot, !dbg !21
97*9880d681SAndroid Build Coastguard Worker  br label %catch.dispatch, !dbg !21
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Workercatch.dispatch:                                   ; preds = %lpad
100*9880d681SAndroid Build Coastguard Worker  %sel = load i32, i32* %ehselector.slot, !dbg !23
101*9880d681SAndroid Build Coastguard Worker  %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2, !dbg !23
102*9880d681SAndroid Build Coastguard Worker  %matches = icmp eq i32 %sel, %4, !dbg !23
103*9880d681SAndroid Build Coastguard Worker  br i1 %matches, label %catch, label %eh.resume, !dbg !23
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Workercatch:                                            ; preds = %catch.dispatch
106*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %e, metadata !24, metadata !DIExpression()), !dbg !25
107*9880d681SAndroid Build Coastguard Worker  %exn = load i8*, i8** %exn.slot, !dbg !23
108*9880d681SAndroid Build Coastguard Worker  %5 = call i8* @__cxa_begin_catch(i8* %exn) #2, !dbg !23
109*9880d681SAndroid Build Coastguard Worker  %6 = bitcast i8* %5 to i32*, !dbg !23
110*9880d681SAndroid Build Coastguard Worker  %7 = load i32, i32* %6, align 4, !dbg !23
111*9880d681SAndroid Build Coastguard Worker  store i32 %7, i32* %e, align 4, !dbg !23
112*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* @global_var, align 4, !dbg !26
113*9880d681SAndroid Build Coastguard Worker  call void @__cxa_end_catch() #2, !dbg !28
114*9880d681SAndroid Build Coastguard Worker  br label %try.cont, !dbg !28
115*9880d681SAndroid Build Coastguard Worker
116*9880d681SAndroid Build Coastguard Workertry.cont:                                         ; preds = %catch, %invoke.cont
117*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* @global_var, align 4, !dbg !29
118*9880d681SAndroid Build Coastguard Worker  ret i32 0, !dbg !30
119*9880d681SAndroid Build Coastguard Worker
120*9880d681SAndroid Build Coastguard Workereh.resume:                                        ; preds = %catch.dispatch
121*9880d681SAndroid Build Coastguard Worker  %exn1 = load i8*, i8** %exn.slot, !dbg !23
122*9880d681SAndroid Build Coastguard Worker  %sel2 = load i32, i32* %ehselector.slot, !dbg !23
123*9880d681SAndroid Build Coastguard Worker  %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn1, 0, !dbg !23
124*9880d681SAndroid Build Coastguard Worker  %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel2, 1, !dbg !23
125*9880d681SAndroid Build Coastguard Worker  resume { i8*, i32 } %lpad.val3, !dbg !23
126*9880d681SAndroid Build Coastguard Worker}
127*9880d681SAndroid Build Coastguard Worker
128*9880d681SAndroid Build Coastguard Workerdeclare i32 @__gxx_personality_v0(...)
129*9880d681SAndroid Build Coastguard Worker
130*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
131*9880d681SAndroid Build Coastguard Workerdeclare i32 @llvm.eh.typeid.for(i8*) #1
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Workerdeclare i8* @__cxa_begin_catch(i8*)
134*9880d681SAndroid Build Coastguard Worker
135*9880d681SAndroid Build Coastguard Workerdeclare void @__cxa_end_catch()
136*9880d681SAndroid Build Coastguard Worker
137*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone }
138*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind }
139*9880d681SAndroid Build Coastguard Worker
140*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0}
141*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!31}
142*9880d681SAndroid Build Coastguard Worker
143*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
144*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "<unknown>", directory: "")
145*9880d681SAndroid Build Coastguard Worker!2 = !{}
146*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "test", linkageName: "_Z4testi", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !5, scope: !6, type: !7, variables: !2)
147*9880d681SAndroid Build Coastguard Worker!5 = !DIFile(filename: "test.cpp", directory: "")
148*9880d681SAndroid Build Coastguard Worker!6 = !DIFile(filename: "test.cpp", directory: "")
149*9880d681SAndroid Build Coastguard Worker!7 = !DISubroutineType(types: !8)
150*9880d681SAndroid Build Coastguard Worker!8 = !{!9, !9}
151*9880d681SAndroid Build Coastguard Worker!9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
152*9880d681SAndroid Build Coastguard Worker!10 = distinct !DISubprogram(name: "test2", linkageName: "_Z5test2v", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 11, file: !5, scope: !6, type: !11, variables: !2)
153*9880d681SAndroid Build Coastguard Worker!11 = !DISubroutineType(types: !12)
154*9880d681SAndroid Build Coastguard Worker!12 = !{!9}
155*9880d681SAndroid Build Coastguard Worker!13 = !DILocalVariable(name: "k", line: 4, arg: 1, scope: !4, file: !6, type: !9)
156*9880d681SAndroid Build Coastguard Worker!14 = !DILocation(line: 4, scope: !4)
157*9880d681SAndroid Build Coastguard Worker!15 = !DILocalVariable(name: "k2", line: 5, scope: !4, file: !6, type: !9)
158*9880d681SAndroid Build Coastguard Worker!16 = !DILocation(line: 5, scope: !4)
159*9880d681SAndroid Build Coastguard Worker!17 = !DILocation(line: 6, scope: !4)
160*9880d681SAndroid Build Coastguard Worker!18 = !DILocation(line: 7, scope: !4)
161*9880d681SAndroid Build Coastguard Worker!19 = !DILocation(line: 8, scope: !4)
162*9880d681SAndroid Build Coastguard Worker!20 = !DILocation(line: 9, scope: !4)
163*9880d681SAndroid Build Coastguard Worker!21 = !DILocation(line: 14, scope: !22)
164*9880d681SAndroid Build Coastguard Worker!22 = distinct !DILexicalBlock(line: 13, column: 0, file: !5, scope: !10)
165*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 15, scope: !22)
166*9880d681SAndroid Build Coastguard Worker!24 = !DILocalVariable(name: "e", line: 16, scope: !10, file: !6, type: !9)
167*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 16, scope: !10)
168*9880d681SAndroid Build Coastguard Worker!26 = !DILocation(line: 17, scope: !27)
169*9880d681SAndroid Build Coastguard Worker!27 = distinct !DILexicalBlock(line: 16, column: 0, file: !5, scope: !10)
170*9880d681SAndroid Build Coastguard Worker!28 = !DILocation(line: 18, scope: !27)
171*9880d681SAndroid Build Coastguard Worker!29 = !DILocation(line: 19, scope: !10)
172*9880d681SAndroid Build Coastguard Worker!30 = !DILocation(line: 20, scope: !10)
173*9880d681SAndroid Build Coastguard Worker!31 = !{i32 1, !"Debug Info Version", i32 3}
174