xref: /aosp_15_r20/external/llvm/test/DebugInfo/X86/debug-loc-offset.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc %s -filetype=obj -O0 -mtriple=i386-unknown-linux-gnu -dwarf-version=4 -o %t
2*9880d681SAndroid Build Coastguard Worker; RUN: llvm-dwarfdump %t | FileCheck %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; From the code:
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; debug-loc-offset1.cc
7*9880d681SAndroid Build Coastguard Worker; int bar (int b) {
8*9880d681SAndroid Build Coastguard Worker;   return b+4;
9*9880d681SAndroid Build Coastguard Worker; }
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; debug-loc-offset2.cc
12*9880d681SAndroid Build Coastguard Worker; struct A {
13*9880d681SAndroid Build Coastguard Worker;   int var;
14*9880d681SAndroid Build Coastguard Worker;   virtual char foo();
15*9880d681SAndroid Build Coastguard Worker; };
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker; void baz(struct A a) {
18*9880d681SAndroid Build Coastguard Worker;   int z = 2;
19*9880d681SAndroid Build Coastguard Worker;   if (a.var > 2)
20*9880d681SAndroid Build Coastguard Worker;     z++;
21*9880d681SAndroid Build Coastguard Worker;   if (a.foo() == 'a')
22*9880d681SAndroid Build Coastguard Worker;     z++;
23*9880d681SAndroid Build Coastguard Worker; }
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; Compiled separately for i386-pc-linux-gnu and linked together.
26*9880d681SAndroid Build Coastguard Worker; This ensures that we have multiple compile units so that we can verify that
27*9880d681SAndroid Build Coastguard Worker; debug_loc entries are relative to the low_pc of the CU. The loc entry for
28*9880d681SAndroid Build Coastguard Worker; the byval argument in foo.cpp is in the second CU and so should have
29*9880d681SAndroid Build Coastguard Worker; an offset relative to that CU rather than from the beginning of the text
30*9880d681SAndroid Build Coastguard Worker; section.
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker; Checking that we have two compile units with two sets of high/lo_pc.
33*9880d681SAndroid Build Coastguard Worker; CHECK: .debug_info contents
34*9880d681SAndroid Build Coastguard Worker; CHECK: DW_TAG_compile_unit
35*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_low_pc
36*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_high_pc
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Worker; CHECK: DW_TAG_compile_unit
39*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_low_pc
40*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_high_pc
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker; CHECK: DW_TAG_subprogram
43*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: DW_TAG
44*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_linkage_name [DW_FORM_strp]{{.*}}"_Z3baz1A"
45*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: {{DW_TAG|NULL}}
46*9880d681SAndroid Build Coastguard Worker; CHECK: DW_TAG_formal_parameter
47*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: DW_TAG
48*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_location [DW_FORM_sec_offset]   (0x00000000)
49*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: DW_TAG
50*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_name [DW_FORM_strp]{{.*}}"a"
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker; CHECK: DW_TAG_variable
53*9880d681SAndroid Build Coastguard Worker; CHECK: DW_AT_location [DW_FORM_exprloc]
54*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: DW_AT_location
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker; CHECK: .debug_loc contents:
57*9880d681SAndroid Build Coastguard Worker; CHECK: 0x00000000: Beginning address offset: 0x0000000000000000
58*9880d681SAndroid Build Coastguard Worker; CHECK:                Ending address offset: 0x0000000000000017
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker%struct.A = type { i32 (...)**, i32 }
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind
63*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z3bari(i32 %b) #0 !dbg !4 {
64*9880d681SAndroid Build Coastguard Workerentry:
65*9880d681SAndroid Build Coastguard Worker  %b.addr = alloca i32, align 4
66*9880d681SAndroid Build Coastguard Worker  store i32 %b, i32* %b.addr, align 4
67*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !21, metadata !DIExpression()), !dbg !22
68*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %b.addr, align 4, !dbg !23
69*9880d681SAndroid Build Coastguard Worker  %add = add nsw i32 %0, 4, !dbg !23
70*9880d681SAndroid Build Coastguard Worker  ret i32 %add, !dbg !23
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 Workerdefine void @_Z3baz1A(%struct.A* %a) #2 !dbg !14 {
77*9880d681SAndroid Build Coastguard Workerentry:
78*9880d681SAndroid Build Coastguard Worker  %z = alloca i32, align 4
79*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata %struct.A* %a, metadata !24, metadata !DIExpression(DW_OP_deref)), !dbg !25
80*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %z, metadata !26, metadata !DIExpression()), !dbg !27
81*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* %z, align 4, !dbg !27
82*9880d681SAndroid Build Coastguard Worker  %var = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1, !dbg !28
83*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %var, align 4, !dbg !28
84*9880d681SAndroid Build Coastguard Worker  %cmp = icmp sgt i32 %0, 2, !dbg !28
85*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %if.then, label %if.end, !dbg !28
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
88*9880d681SAndroid Build Coastguard Worker  %1 = load i32, i32* %z, align 4, !dbg !30
89*9880d681SAndroid Build Coastguard Worker  %inc = add nsw i32 %1, 1, !dbg !30
90*9880d681SAndroid Build Coastguard Worker  store i32 %inc, i32* %z, align 4, !dbg !30
91*9880d681SAndroid Build Coastguard Worker  br label %if.end, !dbg !30
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Workerif.end:                                           ; preds = %if.then, %entry
94*9880d681SAndroid Build Coastguard Worker  %call = call signext i8 @_ZN1A3fooEv(%struct.A* %a), !dbg !31
95*9880d681SAndroid Build Coastguard Worker  %conv = sext i8 %call to i32, !dbg !31
96*9880d681SAndroid Build Coastguard Worker  %cmp1 = icmp eq i32 %conv, 97, !dbg !31
97*9880d681SAndroid Build Coastguard Worker  br i1 %cmp1, label %if.then2, label %if.end4, !dbg !31
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Workerif.then2:                                         ; preds = %if.end
100*9880d681SAndroid Build Coastguard Worker  %2 = load i32, i32* %z, align 4, !dbg !33
101*9880d681SAndroid Build Coastguard Worker  %inc3 = add nsw i32 %2, 1, !dbg !33
102*9880d681SAndroid Build Coastguard Worker  store i32 %inc3, i32* %z, align 4, !dbg !33
103*9880d681SAndroid Build Coastguard Worker  br label %if.end4, !dbg !33
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Workerif.end4:                                          ; preds = %if.then2, %if.end
106*9880d681SAndroid Build Coastguard Worker  ret void, !dbg !34
107*9880d681SAndroid Build Coastguard Worker}
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Workerdeclare signext i8 @_ZN1A3fooEv(%struct.A*) #2
110*9880d681SAndroid Build Coastguard Worker
111*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
112*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone }
113*9880d681SAndroid Build Coastguard Workerattributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
114*9880d681SAndroid Build Coastguard Worker
115*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0, !9}
116*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!18, !19}
117*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!20, !20}
118*9880d681SAndroid Build Coastguard Worker
119*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (210479)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
120*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "debug-loc-offset1.cc", directory: "/llvm_cmake_gcc")
121*9880d681SAndroid Build Coastguard Worker!2 = !{}
122*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "bar", linkageName: "_Z3bari", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, variables: !2)
123*9880d681SAndroid Build Coastguard Worker!5 = !DIFile(filename: "debug-loc-offset1.cc", directory: "/llvm_cmake_gcc")
124*9880d681SAndroid Build Coastguard Worker!6 = !DISubroutineType(types: !7)
125*9880d681SAndroid Build Coastguard Worker!7 = !{!8, !8}
126*9880d681SAndroid Build Coastguard Worker!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
127*9880d681SAndroid Build Coastguard Worker!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (210479)", isOptimized: false, emissionKind: FullDebug, file: !10, enums: !2, retainedTypes: !11, globals: !2, imports: !2)
128*9880d681SAndroid Build Coastguard Worker!10 = !DIFile(filename: "debug-loc-offset2.cc", directory: "/llvm_cmake_gcc")
129*9880d681SAndroid Build Coastguard Worker!11 = !{!12}
130*9880d681SAndroid Build Coastguard Worker!12 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", line: 1, flags: DIFlagFwdDecl, file: !10, identifier: "_ZTS1A")
131*9880d681SAndroid Build Coastguard Worker!14 = distinct !DISubprogram(name: "baz", linkageName: "_Z3baz1A", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !9, scopeLine: 6, file: !10, scope: !15, type: !16, variables: !2)
132*9880d681SAndroid Build Coastguard Worker!15 = !DIFile(filename: "debug-loc-offset2.cc", directory: "/llvm_cmake_gcc")
133*9880d681SAndroid Build Coastguard Worker!16 = !DISubroutineType(types: !17)
134*9880d681SAndroid Build Coastguard Worker!17 = !{null, !12}
135*9880d681SAndroid Build Coastguard Worker!18 = !{i32 2, !"Dwarf Version", i32 4}
136*9880d681SAndroid Build Coastguard Worker!19 = !{i32 2, !"Debug Info Version", i32 3}
137*9880d681SAndroid Build Coastguard Worker!20 = !{!"clang version 3.5.0 (210479)"}
138*9880d681SAndroid Build Coastguard Worker!21 = !DILocalVariable(name: "b", line: 1, arg: 1, scope: !4, file: !5, type: !8)
139*9880d681SAndroid Build Coastguard Worker!22 = !DILocation(line: 1, scope: !4)
140*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 2, scope: !4)
141*9880d681SAndroid Build Coastguard Worker!24 = !DILocalVariable(name: "a", line: 6, arg: 1, scope: !14, file: !15, type: !12)
142*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 6, scope: !14)
143*9880d681SAndroid Build Coastguard Worker!26 = !DILocalVariable(name: "z", line: 7, scope: !14, file: !15, type: !8)
144*9880d681SAndroid Build Coastguard Worker!27 = !DILocation(line: 7, scope: !14)
145*9880d681SAndroid Build Coastguard Worker!28 = !DILocation(line: 8, scope: !29)
146*9880d681SAndroid Build Coastguard Worker!29 = distinct !DILexicalBlock(line: 8, column: 0, file: !10, scope: !14)
147*9880d681SAndroid Build Coastguard Worker!30 = !DILocation(line: 9, scope: !29)
148*9880d681SAndroid Build Coastguard Worker!31 = !DILocation(line: 10, scope: !32)
149*9880d681SAndroid Build Coastguard Worker!32 = distinct !DILexicalBlock(line: 10, column: 0, file: !10, scope: !14)
150*9880d681SAndroid Build Coastguard Worker!33 = !DILocation(line: 11, scope: !32)
151*9880d681SAndroid Build Coastguard Worker!34 = !DILocation(line: 12, scope: !14)
152