xref: /llvm-project/llvm/test/DebugInfo/Generic/cross-cu-inlining.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; FIXME: Missing DwarfAccelNamesSection on AIX
2; XFAIL: target={{.*}}-aix{{.*}}
3; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -v -debug-info - | FileCheck -implicit-check-not=DW_TAG %s
4; RUN: %llc_dwarf -accel-tables=Apple -dwarf-linkage-names=All -O0 -filetype=obj < %s | llvm-dwarfdump -v - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
5
6; Build from source:
7; $ clang++ a.cpp b.cpp -g -c -emit-llvm
8; $ llvm-link a.bc b.bc -o ab.bc
9; $ opt -inline ab.bc -o ab-opt.bc
10; $ cat a.cpp
11; extern int i;
12; int func(int);
13; int main() {
14;   return func(i);
15; }
16; $ cat b.cpp
17; int __attribute__((always_inline)) func(int x) {
18;   return x * 2;
19; }
20
21; Ensure that func inlined into main is described and references the abstract
22; definition in b.cpp's CU.
23
24; CHECK: DW_TAG_compile_unit
25; CHECK:   DW_AT_name {{.*}}"a.cpp"
26; CHECK:   DW_TAG_subprogram
27; CHECK:     DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:[a-f0-9]+]]
28; CHECK:     0x[[INLINED:[0-9a-f]*]]:{{.*}}DW_TAG_inlined_subroutine
29; CHECK:       DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
30; CHECK:       DW_TAG_formal_parameter
31; CHECK:         DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]] "x"
32
33; Check the abstract definition is in the 'b.cpp' CU and doesn't contain any
34; concrete information (address range or variable location)
35; CHECK: DW_TAG_compile_unit
36; CHECK:   DW_AT_name {{.*}}"b.cpp"
37; CHECK: 0x[[ABS_FUNC]]: DW_TAG_subprogram
38; CHECK-NOT: DW_AT_low_pc
39; CHECK: 0x[[ABS_VAR]]: DW_TAG_formal_parameter
40; CHECK-NOT: DW_AT_location
41; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} {0x[[INT]]}
42; CHECK-NOT: DW_AT_location
43
44; CHECK: 0x[[INT]]: DW_TAG_base_type
45; CHECK:   DW_AT_name {{.*}}"int"
46
47; Check the concrete out of line definition references the abstract and
48; provides the address range and variable location
49; CHECK: 0x[[FUNC:[0-9a-f]*]]{{.*}}DW_TAG_subprogram
50; CHECK:   DW_AT_low_pc
51; CHECK:   DW_AT_abstract_origin {{.*}} {0x[[ABS_FUNC]]} "_Z4funci"
52; CHECK:   DW_TAG_formal_parameter
53; CHECK:     DW_AT_location
54; CHECK:     DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]} "x"
55
56; Check that both the inline and the non out of line version of func are
57; correctly referenced in the accelerator table. Before r221837, the one
58; in the second compilation unit had a wrong offset
59; CHECK-ACCEL: .apple_names contents:
60; CHECK-ACCEL: String{{.*}}"func"
61; CHECK-ACCEL-NOT: String
62; CHECK-ACCEL: Atom[0]{{.*}}[[INLINED]]
63; CHECK-ACCEL-NOT: String
64; CHECK-ACCEL: Atom[0]{{.*}}[[FUNC]]
65
66@i = external global i32
67
68; Function Attrs: uwtable
69define i32 @main() #0 !dbg !4 {
70entry:
71  %x.addr.i = alloca i32, align 4
72  %retval = alloca i32, align 4
73  store i32 0, ptr %retval
74  %0 = load i32, ptr @i, align 4, !dbg !19
75  call void @llvm.lifetime.start(i64 4, ptr %x.addr.i)
76  store i32 %0, ptr %x.addr.i, align 4
77  call void @llvm.dbg.declare(metadata ptr %x.addr.i, metadata !120, metadata !DIExpression()), !dbg !21
78  %1 = load i32, ptr %x.addr.i, align 4, !dbg !22
79  %mul.i = mul nsw i32 %1, 2, !dbg !22
80  call void @llvm.lifetime.end(i64 4, ptr %x.addr.i), !dbg !22
81  ret i32 %mul.i, !dbg !19
82}
83
84; Function Attrs: alwaysinline nounwind uwtable
85define i32 @_Z4funci(i32 %x) #1 !dbg !12 {
86entry:
87  %x.addr = alloca i32, align 4
88  store i32 %x, ptr %x.addr, align 4
89  call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !20, metadata !DIExpression()), !dbg !23
90  %0 = load i32, ptr %x.addr, align 4, !dbg !24
91  %mul = mul nsw i32 %0, 2, !dbg !24
92  ret i32 %mul, !dbg !24
93}
94
95; Function Attrs: nounwind readnone
96declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
97
98; Function Attrs: nounwind
99declare void @llvm.lifetime.start(i64, ptr nocapture) #3
100
101; Function Attrs: nounwind
102declare void @llvm.lifetime.end(i64, ptr nocapture) #3
103
104attributes #0 = { uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
105attributes #1 = { alwaysinline nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
106attributes #2 = { nounwind readnone }
107attributes #3 = { nounwind }
108
109!llvm.dbg.cu = !{!0, !9}
110!llvm.module.flags = !{!16, !17}
111!llvm.ident = !{!18, !18}
112
113!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
114!1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
115!2 = !{}
116!4 = distinct !DISubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
117!5 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
118!6 = !DISubroutineType(types: !7)
119!7 = !{!8}
120!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
121!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !10, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
122!10 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
123!12 = distinct !DISubprogram(name: "func", linkageName: "_Z4funci", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !9, scopeLine: 1, file: !10, scope: !13, type: !14, retainedNodes: !2)
124!13 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
125!14 = !DISubroutineType(types: !15)
126!15 = !{!8, !8}
127!16 = !{i32 2, !"Dwarf Version", i32 4}
128!17 = !{i32 2, !"Debug Info Version", i32 3}
129!18 = !{!"clang version 3.5.0 "}
130!19 = !DILocation(line: 4, scope: !4)
131!20 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
132
133!120 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
134
135!21 = !DILocation(line: 1, scope: !12, inlinedAt: !19)
136!22 = !DILocation(line: 2, scope: !12, inlinedAt: !19)
137!23 = !DILocation(line: 1, scope: !12)
138!24 = !DILocation(line: 2, scope: !12)
139
140