blob: d7188a2ff6312d87a70472e264bec055babb54a0 [file] [log] [blame]
Wolfgang Piebdfad9b22016-08-15 18:18:26 +00001; REQUIRES: object-emission
2
3; Check that when variables are allocated on the stack we generate debug locations
4; for the stack location directly instead of generating a register+offset indirection.
5
Reid Klecknera7b04a52016-08-15 22:54:26 +00006; RUN: llc -O2 -filetype=obj -disable-post-ra -mtriple=x86_64-unknown-linux-gnu < %s \
Wolfgang Pieb12cd6dd2016-08-15 22:39:39 +00007; RUN: | llvm-dwarfdump - | FileCheck %s
Wolfgang Piebdfad9b22016-08-15 18:18:26 +00008;
9; int data = 17;
10; int sum = 0;
11; int zero = 0;
12; int *ptr;
13;
14; extern void foo(int i, int *p);
15;
16; int main()
17; {
18; int val;
19; val = data;
20; foo(1, &val);
21; foo(2, &data);
22; return zero;
23; }
24;
25; CHECK: .debug_info contents
26; CHECK: DW_TAG_subprogram
27; CHECK-NOT: NULL
28; CHECK: DW_TAG_variable
29; CHECK: DW_AT_location [DW_FORM_sec_offset] ([[DEBUGLOCOFFSET:0x[0-9a-f]+]]){{[[:space:]].*}}"val"
30
31; See that 'val' has at least one location entry with a DW_op_breg? operand.
32; The DWARF DW_op_breg* ops are encoded from 0x70 to 0x8f, but checking for an
33; op in the range from 0x70 to 0x7f should suffice because that range covers
34; all integer GPRs.
35;
36; CHECK: .debug_loc contents:
37; CHECK-NOT: .debug{{.*}} contents
38; CHECK: [[DEBUGLOCOFFSET]]: Beginning
39; CHECK-NOT: {{0x[0-9a-f]+}}: Beginning
40; CHECK: Location description: 7{{[0-9a-f] .*}}
41
42; ModuleID = 'frame.c'
43source_filename = "frame.c"
44
Adrian Prantl1eadba12016-12-22 00:45:21 +000045@data = global i32 17, align 4, !dbg !0
Peter Collingbourned4135bb2016-09-13 01:12:59 +000046@sum = local_unnamed_addr global i32 0, align 4, !dbg !6
Adrian Prantl1eadba12016-12-22 00:45:21 +000047@zero = local_unnamed_addr global i32 0, align 4, !dbg !9
48@ptr = common local_unnamed_addr global i32* null, align 8, !dbg !11
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000049
Adrian Prantl1eadba12016-12-22 00:45:21 +000050define i32 @main() local_unnamed_addr !dbg !17 {
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000051entry:
52 %val = alloca i32, align 4
Adrian Prantl1eadba12016-12-22 00:45:21 +000053 %0 = bitcast i32* %val to i8*, !dbg !22
54 call void @llvm.lifetime.start(i64 4, i8* %0), !dbg !22
55 %1 = load i32, i32* @data, align 4, !dbg !23, !tbaa !24
56 tail call void @llvm.dbg.value(metadata i32 %1, i64 0, metadata !21, metadata !28), !dbg !29
57 store i32 %1, i32* %val, align 4, !dbg !30, !tbaa !24
58 tail call void @llvm.dbg.value(metadata i32* %val, i64 0, metadata !21, metadata !31), !dbg !29
59 call void @foo(i32 1, i32* nonnull %val), !dbg !32
60 call void @foo(i32 2, i32* nonnull @data), !dbg !33
61 %2 = load i32, i32* @zero, align 4, !dbg !34, !tbaa !24
62 call void @llvm.lifetime.end(i64 4, i8* %0), !dbg !35
63 ret i32 %2, !dbg !36
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000064}
65
66; Function Attrs: argmemonly nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +000067declare void @llvm.lifetime.start(i64, i8* nocapture) #0
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000068
69declare void @foo(i32, i32*) local_unnamed_addr
70
71; Function Attrs: argmemonly nounwind
Adrian Prantl1eadba12016-12-22 00:45:21 +000072declare void @llvm.lifetime.end(i64, i8* nocapture) #0
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000073
74; Function Attrs: nounwind readnone
Adrian Prantl1eadba12016-12-22 00:45:21 +000075declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000076
Adrian Prantl1eadba12016-12-22 00:45:21 +000077attributes #0 = { argmemonly nounwind }
78attributes #1 = { nounwind readnone }
Wolfgang Piebdfad9b22016-08-15 18:18:26 +000079
Adrian Prantl1eadba12016-12-22 00:45:21 +000080!llvm.dbg.cu = !{!2}
81!llvm.module.flags = !{!14, !15}
82!llvm.ident = !{!16}
83
84!0 = distinct !DIGlobalVariableExpression(var: !1)
85!1 = !DIGlobalVariable(name: "data", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
86!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 3.9.0 (trunk 273961)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
87!3 = !DIFile(filename: "frame.c", directory: "/home/user/test")
88!4 = !{}
89!5 = !{!0, !6, !9, !11}
90!6 = distinct !DIGlobalVariableExpression(var: !7)
91!7 = !DIGlobalVariable(name: "sum", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
92!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
93!9 = distinct !DIGlobalVariableExpression(var: !10)
94!10 = !DIGlobalVariable(name: "zero", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true)
95!11 = distinct !DIGlobalVariableExpression(var: !12)
96!12 = !DIGlobalVariable(name: "ptr", scope: !2, file: !3, line: 4, type: !13, isLocal: false, isDefinition: true)
97!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, align: 64)
98!14 = !{i32 2, !"Dwarf Version", i32 4}
99!15 = !{i32 2, !"Debug Info Version", i32 3}
100!16 = !{!"clang version 3.9.0 (trunk 273961)"}
101!17 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 8, type: !18, isLocal: false, isDefinition: true, scopeLine: 9, isOptimized: true, unit: !2, variables: !20)
102!18 = !DISubroutineType(types: !19)
103!19 = !{!8}
104!20 = !{!21}
105!21 = !DILocalVariable(name: "val", scope: !17, file: !3, line: 10, type: !8)
106!22 = !DILocation(line: 10, column: 3, scope: !17)
107!23 = !DILocation(line: 11, column: 9, scope: !17)
108!24 = !{!25, !25, i64 0}
109!25 = !{!"int", !26, i64 0}
110!26 = !{!"omnipotent char", !27, i64 0}
111!27 = !{!"Simple C/C++ TBAA"}
112!28 = !DIExpression()
113!29 = !DILocation(line: 10, column: 7, scope: !17)
114!30 = !DILocation(line: 11, column: 7, scope: !17)
115!31 = !DIExpression(DW_OP_deref)
116!32 = !DILocation(line: 12, column: 3, scope: !17)
117!33 = !DILocation(line: 13, column: 3, scope: !17)
118!34 = !DILocation(line: 14, column: 10, scope: !17)
119!35 = !DILocation(line: 15, column: 1, scope: !17)
120!36 = !DILocation(line: 14, column: 3, scope: !17)
121