1 ; RUN: llc -O1 -filetype=obj -mtriple=x86_64-apple-darwin < %s > %t
2 ; RUN: llvm-dwarfdump -v %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 -v %t | FileCheck %s
6 ; RUN: llvm-objdump -r %t | FileCheck -check-prefix=LINUX %s
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.
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);
24 ; while (x & 1) { x *= a; }
27 ; while (x & 2) { x *= a; }
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 that the location contains only 2 ranges.
36 ; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}):
37 ; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}): {{.*}})
38 ; CHECK-NEXT: DW_AT_name {{.*}} "x"
39 ; CHECK-NEXT: DW_AT_decl_file
40 ; CHECK-NEXT: DW_AT_decl_line
41 ; CHECK-NEXT: DW_AT_type
43 ; Check that we have no relocations in Darwin's output.
44 ; DARWIN-NOT: X86_64_RELOC{{.*}} __debug_loc
46 ; Check we have a relocation for the debug_loc entry in Linux output.
47 ; LINUX: RELOCATION RECORDS FOR [.debug_info]
48 ; LINUX-NOT: RELOCATION RECORDS
49 ; LINUX: R_X86_64{{.*}} .debug_loc
51 ; ModuleID = 'simple.c'
52 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"
54 @a = external global i32
56 define void @f() nounwind !dbg !0 {
58 %call = tail call i32 @g(i32 0, i32 0) nounwind, !dbg !8
59 store i32 %call, i32* @a, align 4, !dbg !8
60 tail call void @llvm.dbg.value(metadata i32 1, metadata !5, metadata !DIExpression()), !dbg !13
63 while.body: ; preds = %entry, %while.body
64 %x.017 = phi i32 [ 1, %entry ], [ %mul, %while.body ]
65 %mul = mul nsw i32 %call, %x.017, !dbg !14
66 %and = and i32 %mul, 1, !dbg !14
67 %tobool = icmp eq i32 %and, 0, !dbg !14
68 br i1 %tobool, label %while.end, label %while.body, !dbg !14
70 while.end: ; preds = %while.body
71 tail call void @llvm.dbg.value(metadata i32 %mul, metadata !5, metadata !DIExpression()), !dbg !14
72 %call4 = tail call i32 @g(i32 %mul, i32 0) nounwind, !dbg !15
73 store i32 %call4, i32* @a, align 4, !dbg !15
74 tail call void @llvm.dbg.value(metadata i32 2, metadata !5, metadata !DIExpression()), !dbg !17
77 while.body9: ; preds = %while.end, %while.body9
78 %x.116 = phi i32 [ 2, %while.end ], [ %mul12, %while.body9 ]
79 %mul12 = mul nsw i32 %call4, %x.116, !dbg !18
80 %and7 = and i32 %mul12, 2, !dbg !18
81 %tobool8 = icmp eq i32 %and7, 0, !dbg !18
82 br i1 %tobool8, label %while.end13, label %while.body9, !dbg !18
84 while.end13: ; preds = %while.body9
85 tail call void @llvm.dbg.value(metadata i32 %mul12, metadata !5, metadata !DIExpression()), !dbg !18
86 %call15 = tail call i32 @g(i32 0, i32 %mul12) nounwind, !dbg !19
87 store i32 %call15, i32* @a, align 4, !dbg !19
91 declare i32 @g(i32, i32)
93 declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
96 !llvm.module.flags = !{!24}
98 !0 = distinct !DISubprogram(name: "f", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, scopeLine: 4, file: !23, scope: !1, type: !3, retainedNodes: !22)
99 !1 = !DIFile(filename: "simple.c", directory: "/home/rengol01/temp/tests/dwarf/relocation")
100 !2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk)", isOptimized: true, emissionKind: FullDebug, file: !23, enums: !{}, retainedTypes: !{}, imports: null)
101 !3 = !DISubroutineType(types: !4)
103 !5 = !DILocalVariable(name: "x", line: 5, scope: !6, file: !1, type: !7)
104 !6 = distinct !DILexicalBlock(line: 4, column: 14, file: !23, scope: !0)
105 !7 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
106 !8 = !DILocation(line: 6, column: 3, scope: !6)
108 !13 = !DILocation(line: 7, column: 3, scope: !6)
109 !14 = !DILocation(line: 8, column: 3, scope: !6)
110 !15 = !DILocation(line: 9, column: 3, scope: !6)
112 !17 = !DILocation(line: 10, column: 3, scope: !6)
113 !18 = !DILocation(line: 11, column: 3, scope: !6)
114 !19 = !DILocation(line: 12, column: 3, scope: !6)
115 !20 = !DILocation(line: 13, column: 1, scope: !6)
117 !23 = !DIFile(filename: "simple.c", directory: "/home/rengol01/temp/tests/dwarf/relocation")
118 !24 = !{i32 1, !"Debug Info Version", i32 3}