Revert "Revert "DI: Fold constant arguments into a single MDString""
[oota-llvm.git] / test / DebugInfo / X86 / DW_AT_location-reference.ll
1 ; RUN: llc -O1 -filetype=obj -mtriple=x86_64-apple-darwin < %s > %t
2 ; RUN: llvm-dwarfdump %t  | FileCheck %s
3 ; RUN: llvm-objdump -r %t | FileCheck -check-prefix=DARWIN %s
4 ; RUN: llc -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t
5 ; RUN: llvm-dwarfdump %t  | FileCheck %s
6 ; RUN: llvm-objdump -r %t | FileCheck -check-prefix=LINUX %s
7
8 ; PR9493
9 ; Adapted from the original test case in r127757.
10 ; We use 'llc -O1' to induce variable 'x' to live in different locations.
11 ; We don't actually care where 'x' lives, or what exact optimizations get
12 ; used, as long as 'x' moves around we're fine.
13
14 ; // The variable 'x' lives in different locations, so it needs an entry in
15 ; // the .debug_loc table section, referenced by DW_AT_location.
16 ; // This ref is not relocatable on Darwin, and is relocatable elsewhere.
17 ; extern int g(int, int);
18 ; extern int a;
19
20 ; void f(void) {
21 ;   int x;
22 ;   a = g(0, 0);
23 ;   x = 1;
24 ;   while (x & 1) { x *= a; }
25 ;   a = g(x, 0);
26 ;   x = 2;
27 ;   while (x & 2) { x *= a; }
28 ;   a = g(0, x);
29 ; }
30
31 ; // The 'x' variable and its symbol reference location
32 ; CHECK: .debug_info contents:
33 ; CHECK:      DW_TAG_variable
34 ; CHECK-NEXT:   DW_AT_location [DW_FORM_sec_offset] (0x00000000)
35 ; CHECK-NEXT:   DW_AT_name {{.*}} "x"
36 ; CHECK-NEXT:   DW_AT_decl_file
37 ; CHECK-NEXT:   DW_AT_decl_line
38 ; CHECK-NEXT:   DW_AT_type
39
40 ; Check that the location contains only 4 ranges - this verifies that the 4th
41 ; and 5th ranges were successfully merged into a single range.
42 ; CHECK: .debug_loc contents:
43 ; CHECK: 0x00000000:
44 ; CHECK: Beginning address offset:
45 ; CHECK: Beginning address offset:
46 ; CHECK: Beginning address offset:
47 ; CHECK: Beginning address offset:
48 ; CHECK-NOT: Beginning address offset:
49
50 ; Check that we have no relocations in Darwin's output.
51 ; DARWIN-NOT: X86_64_RELOC{{.*}} __debug_loc
52
53 ; Check we have a relocation for the debug_loc entry in Linux output.
54 ; LINUX: RELOCATION RECORDS FOR [.rela.debug_info]
55 ; LINUX-NOT: RELOCATION RECORDS
56 ; LINUX: R_X86_64{{.*}} .debug_loc+0
57
58 ; ModuleID = 'simple.c'
59 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32"
60
61 @a = external global i32
62
63 define void @f() nounwind {
64 entry:
65   %call = tail call i32 @g(i32 0, i32 0) nounwind, !dbg !8
66   store i32 %call, i32* @a, align 4, !dbg !8
67   tail call void @llvm.dbg.value(metadata !12, i64 0, metadata !5, metadata !{metadata !"0x102"}), !dbg !13
68   br label %while.body
69
70 while.body:                                       ; preds = %entry, %while.body
71   %x.017 = phi i32 [ 1, %entry ], [ %mul, %while.body ]
72   %mul = mul nsw i32 %call, %x.017, !dbg !14
73   %and = and i32 %mul, 1, !dbg !14
74   %tobool = icmp eq i32 %and, 0, !dbg !14
75   br i1 %tobool, label %while.end, label %while.body, !dbg !14
76
77 while.end:                                        ; preds = %while.body
78   tail call void @llvm.dbg.value(metadata !{i32 %mul}, i64 0, metadata !5, metadata !{metadata !"0x102"}), !dbg !14
79   %call4 = tail call i32 @g(i32 %mul, i32 0) nounwind, !dbg !15
80   store i32 %call4, i32* @a, align 4, !dbg !15
81   tail call void @llvm.dbg.value(metadata !16, i64 0, metadata !5, metadata !{metadata !"0x102"}), !dbg !17
82   br label %while.body9
83
84 while.body9:                                      ; preds = %while.end, %while.body9
85   %x.116 = phi i32 [ 2, %while.end ], [ %mul12, %while.body9 ]
86   %mul12 = mul nsw i32 %call4, %x.116, !dbg !18
87   %and7 = and i32 %mul12, 2, !dbg !18
88   %tobool8 = icmp eq i32 %and7, 0, !dbg !18
89   br i1 %tobool8, label %while.end13, label %while.body9, !dbg !18
90
91 while.end13:                                      ; preds = %while.body9
92   tail call void @llvm.dbg.value(metadata !{i32 %mul12}, i64 0, metadata !5, metadata !{metadata !"0x102"}), !dbg !18
93   %call15 = tail call i32 @g(i32 0, i32 %mul12) nounwind, !dbg !19
94   store i32 %call15, i32* @a, align 4, !dbg !19
95   ret void, !dbg !20
96 }
97
98 declare i32 @g(i32, i32)
99
100 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone
101
102 !llvm.dbg.cu = !{!2}
103 !llvm.module.flags = !{!24}
104
105 !0 = metadata !{metadata !"0x2e\00f\00f\00\004\000\001\000\006\00256\001\004", metadata !23, metadata !1, metadata !3, null, void ()* @f, null, null, metadata !22} ; [ DW_TAG_subprogram ] [line 4] [def] [f]
106 !1 = metadata !{metadata !"0x29", metadata !23} ; [ DW_TAG_file_type ]
107 !2 = metadata !{metadata !"0x11\0012\00clang version 3.0 (trunk)\001\00\000\00\001", metadata !23, metadata !4, metadata !4, metadata !21, null,  null} ; [ DW_TAG_compile_unit ]
108 !3 = metadata !{metadata !"0x15\00\000\000\000\000\000\000", metadata !23, metadata !1, null, metadata !4, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
109 !4 = metadata !{null}
110 !5 = metadata !{metadata !"0x100\00x\005\000", metadata !6, metadata !1, metadata !7} ; [ DW_TAG_auto_variable ]
111 !6 = metadata !{metadata !"0xb\004\0014\000", metadata !23, metadata !0} ; [ DW_TAG_lexical_block ]
112 !7 = metadata !{metadata !"0x24\00int\000\0032\0032\000\000\005", null, metadata !2} ; [ DW_TAG_base_type ]
113 !8 = metadata !{i32 6, i32 3, metadata !6, null}
114 !12 = metadata !{i32 1}
115 !13 = metadata !{i32 7, i32 3, metadata !6, null}
116 !14 = metadata !{i32 8, i32 3, metadata !6, null}
117 !15 = metadata !{i32 9, i32 3, metadata !6, null}
118 !16 = metadata !{i32 2}
119 !17 = metadata !{i32 10, i32 3, metadata !6, null}
120 !18 = metadata !{i32 11, i32 3, metadata !6, null}
121 !19 = metadata !{i32 12, i32 3, metadata !6, null}
122 !20 = metadata !{i32 13, i32 1, metadata !6, null}
123 !21 = metadata !{metadata !0}
124 !22 = metadata !{metadata !5}
125 !23 = metadata !{metadata !"simple.c", metadata !"/home/rengol01/temp/tests/dwarf/relocation"}
126 !24 = metadata !{i32 1, metadata !"Debug Info Version", i32 2}