blob: ba6559639dac1ec74bab65f22ee815cee215fdd6 [file] [log] [blame]
Adrian Prantl16aa4cf2017-09-11 23:05:20 +00001; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -v -debug-info - | FileCheck -implicit-check-not=DW_TAG %s
Pavel Labath6088c232018-04-04 14:42:14 +00002; 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
David Blaikie1ea9db22014-05-21 23:14:12 +00003
4; Build from source:
5; $ clang++ a.cpp b.cpp -g -c -emit-llvm
6; $ llvm-link a.bc b.bc -o ab.bc
7; $ opt -inline ab.bc -o ab-opt.bc
8; $ cat a.cpp
9; extern int i;
10; int func(int);
11; int main() {
12; return func(i);
13; }
14; $ cat b.cpp
15; int __attribute__((always_inline)) func(int x) {
16; return x * 2;
17; }
18
19; Ensure that func inlined into main is described and references the abstract
20; definition in b.cpp's CU.
21
22; CHECK: DW_TAG_compile_unit
23; CHECK: DW_AT_name {{.*}} "a.cpp"
24; CHECK: DW_TAG_subprogram
Jonas Devlieghereaa6be822017-10-10 14:15:25 +000025; CHECK: DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:[a-f0-9]+]]
Frederic Riss3a6b3542014-11-12 23:48:14 +000026; CHECK: 0x[[INLINED:[0-9a-f]*]]:{{.*}}DW_TAG_inlined_subroutine
Frederic Rissd1cfc3c2014-10-06 03:36:31 +000027; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
David Blaikie1ea9db22014-05-21 23:14:12 +000028; CHECK: DW_TAG_formal_parameter
Frederic Rissd4de1802014-10-10 15:51:02 +000029; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]] "x"
David Blaikie1ea9db22014-05-21 23:14:12 +000030
31; Check the abstract definition is in the 'b.cpp' CU and doesn't contain any
32; concrete information (address range or variable location)
33; CHECK: DW_TAG_compile_unit
34; CHECK: DW_AT_name {{.*}} "b.cpp"
35; CHECK: 0x[[ABS_FUNC]]: DW_TAG_subprogram
36; CHECK-NOT: DW_AT_low_pc
37; CHECK: 0x[[ABS_VAR]]: DW_TAG_formal_parameter
David Blaikie96fb9022014-05-23 04:23:06 +000038; CHECK-NOT: DW_AT_location
David Blaikief7221ad2014-05-27 18:37:43 +000039; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} {0x[[INT]]}
David Blaikie1ea9db22014-05-21 23:14:12 +000040; CHECK-NOT: DW_AT_location
41
David Blaikief7221ad2014-05-27 18:37:43 +000042; CHECK: 0x[[INT]]: DW_TAG_base_type
David Blaikief7221ad2014-05-27 18:37:43 +000043; CHECK: DW_AT_name {{.*}} "int"
44
David Blaikie1ea9db22014-05-21 23:14:12 +000045; Check the concrete out of line definition references the abstract and
46; provides the address range and variable location
Frederic Riss3a6b3542014-11-12 23:48:14 +000047; CHECK: 0x[[FUNC:[0-9a-f]*]]{{.*}}DW_TAG_subprogram
David Blaikie1ea9db22014-05-21 23:14:12 +000048; CHECK: DW_AT_low_pc
Frederic Rissd1cfc3c2014-10-06 03:36:31 +000049; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_FUNC]]} "_Z4funci"
David Blaikie1ea9db22014-05-21 23:14:12 +000050; CHECK: DW_TAG_formal_parameter
David Blaikie1ea9db22014-05-21 23:14:12 +000051; CHECK: DW_AT_location
Frederic Rissd4de1802014-10-10 15:51:02 +000052; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]} "x"
David Blaikie1ea9db22014-05-21 23:14:12 +000053
Frederic Risse837ec22014-11-14 16:15:53 +000054; Check that both the inline and the non out of line version of func are
55; correctly referenced in the accelerator table. Before r221837, the one
56; in the second compilation unit had a wrong offset
57; CHECK-ACCEL: .apple_names contents:
Pavel Labath394e8052018-01-29 11:33:17 +000058; CHECK-ACCEL: String{{.*}}"func"
59; CHECK-ACCEL-NOT: String
Frederic Risse837ec22014-11-14 16:15:53 +000060; CHECK-ACCEL: Atom[0]{{.*}}[[INLINED]]
Pavel Labath394e8052018-01-29 11:33:17 +000061; CHECK-ACCEL-NOT: String
Frederic Risse837ec22014-11-14 16:15:53 +000062; CHECK-ACCEL: Atom[0]{{.*}}[[FUNC]]
63
David Blaikie1ea9db22014-05-21 23:14:12 +000064@i = external global i32
65
66; Function Attrs: uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000067define i32 @main() #0 !dbg !4 {
David Blaikie1ea9db22014-05-21 23:14:12 +000068entry:
69 %x.addr.i = alloca i32, align 4
70 %retval = alloca i32, align 4
71 store i32 0, i32* %retval
David Blaikiea79ac142015-02-27 21:17:42 +000072 %0 = load i32, i32* @i, align 4, !dbg !19
David Blaikie1ea9db22014-05-21 23:14:12 +000073 %1 = bitcast i32* %x.addr.i to i8*
74 call void @llvm.lifetime.start(i64 4, i8* %1)
75 store i32 %0, i32* %x.addr.i, align 4
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000076 call void @llvm.dbg.declare(metadata i32* %x.addr.i, metadata !120, metadata !DIExpression()), !dbg !21
David Blaikiea79ac142015-02-27 21:17:42 +000077 %2 = load i32, i32* %x.addr.i, align 4, !dbg !22
David Blaikie1ea9db22014-05-21 23:14:12 +000078 %mul.i = mul nsw i32 %2, 2, !dbg !22
79 %3 = bitcast i32* %x.addr.i to i8*, !dbg !22
80 call void @llvm.lifetime.end(i64 4, i8* %3), !dbg !22
81 ret i32 %mul.i, !dbg !19
82}
83
84; Function Attrs: alwaysinline nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000085define i32 @_Z4funci(i32 %x) #1 !dbg !12 {
David Blaikie1ea9db22014-05-21 23:14:12 +000086entry:
87 %x.addr = alloca i32, align 4
88 store i32 %x, i32* %x.addr, align 4
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000089 call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !20, metadata !DIExpression()), !dbg !23
David Blaikiea79ac142015-02-27 21:17:42 +000090 %0 = load i32, i32* %x.addr, align 4, !dbg !24
David Blaikie1ea9db22014-05-21 23:14:12 +000091 %mul = mul nsw i32 %0, 2, !dbg !24
92 ret i32 %mul, !dbg !24
93}
94
95; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +000096declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
David Blaikie1ea9db22014-05-21 23:14:12 +000097
98; Function Attrs: nounwind
99declare void @llvm.lifetime.start(i64, i8* nocapture) #3
100
101; Function Attrs: nounwind
102declare void @llvm.lifetime.end(i64, i8* nocapture) #3
103
Fangrui Song502a77f2019-12-24 15:52:21 -0800104attributes #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" }
David Blaikie1ea9db22014-05-21 23:14:12 +0000106attributes #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
Adrian Prantl75819ae2016-04-15 15:57:41 +0000113!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000114!1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000115!2 = !{}
Shiva Chen2c864552018-05-09 02:40:45 +0000116!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000117!5 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
118!6 = !DISubroutineType(types: !7)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000119!7 = !{!8}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000120!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
Adrian Prantl75819ae2016-04-15 15:57:41 +0000121!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000122!10 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
Shiva Chen2c864552018-05-09 02:40:45 +0000123!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000124!13 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
125!14 = !DISubroutineType(types: !15)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000126!15 = !{!8, !8}
127!16 = !{i32 2, !"Dwarf Version", i32 4}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000128!17 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000129!18 = !{!"clang version 3.5.0 "}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000130!19 = !DILocation(line: 4, scope: !4)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000131!20 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
Duncan P. N. Exon Smith81f522a2015-04-03 16:54:30 +0000132
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000133!120 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
Duncan P. N. Exon Smith81f522a2015-04-03 16:54:30 +0000134
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000135!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)
David Blaikie1ea9db22014-05-21 23:14:12 +0000139