blob: 5dea31f7705cb4feecee9cb2f4977d983538fca4 [file] [log] [blame]
David Blaikie1ea9db22014-05-21 23:14:12 +00001; REQUIRES: object-emission
2
Paul Robinson43d1e452016-04-18 22:41:41 +00003; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
4; RUN: %llc_dwarf -dwarf-accel-tables=Enable -dwarf-linkage-names=All -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
David Blaikie1ea9db22014-05-21 23:14:12 +00005
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
David Blaikief7221ad2014-05-27 18:37:43 +000027; CHECK: DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:.*]])
Frederic Riss3a6b3542014-11-12 23:48:14 +000028; CHECK: 0x[[INLINED:[0-9a-f]*]]:{{.*}}DW_TAG_inlined_subroutine
Frederic Rissd1cfc3c2014-10-06 03:36:31 +000029; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
David Blaikie1ea9db22014-05-21 23:14:12 +000030; CHECK: DW_TAG_formal_parameter
Frederic Rissd4de1802014-10-10 15:51:02 +000031; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]] "x"
David Blaikie1ea9db22014-05-21 23:14:12 +000032
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
David Blaikie96fb9022014-05-23 04:23:06 +000040; CHECK-NOT: DW_AT_location
David Blaikief7221ad2014-05-27 18:37:43 +000041; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} {0x[[INT]]}
David Blaikie1ea9db22014-05-21 23:14:12 +000042; CHECK-NOT: DW_AT_location
43
David Blaikief7221ad2014-05-27 18:37:43 +000044; CHECK: 0x[[INT]]: DW_TAG_base_type
David Blaikief7221ad2014-05-27 18:37:43 +000045; CHECK: DW_AT_name {{.*}} "int"
46
David Blaikie1ea9db22014-05-21 23:14:12 +000047; Check the concrete out of line definition references the abstract and
48; provides the address range and variable location
Frederic Riss3a6b3542014-11-12 23:48:14 +000049; CHECK: 0x[[FUNC:[0-9a-f]*]]{{.*}}DW_TAG_subprogram
David Blaikie1ea9db22014-05-21 23:14:12 +000050; CHECK: DW_AT_low_pc
Frederic Rissd1cfc3c2014-10-06 03:36:31 +000051; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_FUNC]]} "_Z4funci"
David Blaikie1ea9db22014-05-21 23:14:12 +000052; CHECK: DW_TAG_formal_parameter
David Blaikie1ea9db22014-05-21 23:14:12 +000053; CHECK: DW_AT_location
Frederic Rissd4de1802014-10-10 15:51:02 +000054; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]} "x"
David Blaikie1ea9db22014-05-21 23:14:12 +000055
Frederic Risse837ec22014-11-14 16:15:53 +000056; 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: Name{{.*}}"func"
61; CHECK-ACCEL-NOT: Name
62; CHECK-ACCEL: Atom[0]{{.*}}[[INLINED]]
63; CHECK-ACCEL-NOT: Name
64; CHECK-ACCEL: Atom[0]{{.*}}[[FUNC]]
65
David Blaikie1ea9db22014-05-21 23:14:12 +000066@i = external global i32
67
68; Function Attrs: uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000069define i32 @main() #0 !dbg !4 {
David Blaikie1ea9db22014-05-21 23:14:12 +000070entry:
71 %x.addr.i = alloca i32, align 4
72 %retval = alloca i32, align 4
73 store i32 0, i32* %retval
David Blaikiea79ac142015-02-27 21:17:42 +000074 %0 = load i32, i32* @i, align 4, !dbg !19
David Blaikie1ea9db22014-05-21 23:14:12 +000075 %1 = bitcast i32* %x.addr.i to i8*
76 call void @llvm.lifetime.start(i64 4, i8* %1)
77 store i32 %0, i32* %x.addr.i, align 4
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000078 call void @llvm.dbg.declare(metadata i32* %x.addr.i, metadata !120, metadata !DIExpression()), !dbg !21
David Blaikiea79ac142015-02-27 21:17:42 +000079 %2 = load i32, i32* %x.addr.i, align 4, !dbg !22
David Blaikie1ea9db22014-05-21 23:14:12 +000080 %mul.i = mul nsw i32 %2, 2, !dbg !22
81 %3 = bitcast i32* %x.addr.i to i8*, !dbg !22
82 call void @llvm.lifetime.end(i64 4, i8* %3), !dbg !22
83 ret i32 %mul.i, !dbg !19
84}
85
86; Function Attrs: alwaysinline nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000087define i32 @_Z4funci(i32 %x) #1 !dbg !12 {
David Blaikie1ea9db22014-05-21 23:14:12 +000088entry:
89 %x.addr = alloca i32, align 4
90 store i32 %x, i32* %x.addr, align 4
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000091 call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !20, metadata !DIExpression()), !dbg !23
David Blaikiea79ac142015-02-27 21:17:42 +000092 %0 = load i32, i32* %x.addr, align 4, !dbg !24
David Blaikie1ea9db22014-05-21 23:14:12 +000093 %mul = mul nsw i32 %0, 2, !dbg !24
94 ret i32 %mul, !dbg !24
95}
96
97; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +000098declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
David Blaikie1ea9db22014-05-21 23:14:12 +000099
100; Function Attrs: nounwind
101declare void @llvm.lifetime.start(i64, i8* nocapture) #3
102
103; Function Attrs: nounwind
104declare void @llvm.lifetime.end(i64, i8* nocapture) #3
105
106attributes #0 = { uwtable "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" }
107attributes #1 = { alwaysinline nounwind uwtable "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" }
108attributes #2 = { nounwind readnone }
109attributes #3 = { nounwind }
110
111!llvm.dbg.cu = !{!0, !9}
112!llvm.module.flags = !{!16, !17}
113!llvm.ident = !{!18, !18}
114
Adrian Prantl75819ae2016-04-15 15:57:41 +0000115!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 +0000116!1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000117!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +0000118!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, variables: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000119!5 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
120!6 = !DISubroutineType(types: !7)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000121!7 = !{!8}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000122!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
Adrian Prantl75819ae2016-04-15 15:57:41 +0000123!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 +0000124!10 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
Adrian Prantl75819ae2016-04-15 15:57:41 +0000125!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, variables: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000126!13 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
127!14 = !DISubroutineType(types: !15)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000128!15 = !{!8, !8}
129!16 = !{i32 2, !"Dwarf Version", i32 4}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000130!17 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000131!18 = !{!"clang version 3.5.0 "}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000132!19 = !DILocation(line: 4, scope: !4)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000133!20 = !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 Smithed013cd2015-07-31 18:58:39 +0000135!120 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
Duncan P. N. Exon Smith81f522a2015-04-03 16:54:30 +0000136
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000137!21 = !DILocation(line: 1, scope: !12, inlinedAt: !19)
138!22 = !DILocation(line: 2, scope: !12, inlinedAt: !19)
139!23 = !DILocation(line: 1, scope: !12)
140!24 = !DILocation(line: 2, scope: !12)
David Blaikie1ea9db22014-05-21 23:14:12 +0000141