1; RUN: llc -O1 -filetype=obj -mtriple=x86_64-apple-darwin < %s > %t 2; RUN: llvm-dwarfdump -v %t | FileCheck %s --check-prefixes=CHECK,DWARFv4 3; RUN: llvm-objdump -r %t | FileCheck --check-prefix=DARWIN %s 4 5; RUN: llc -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t 6; RUN: llvm-dwarfdump -v %t | FileCheck %s --check-prefixes=CHECK,DWARFv4 7; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s 8 9; RUN: llc -dwarf-version=3 -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t 10; RUN: llvm-dwarfdump -debug-info -v %t | FileCheck %s --check-prefixes=CHECK,DWARF32v3 11; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s 12 13; RUN: llc -dwarf64 -dwarf-version=3 -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t 14; RUN: llvm-dwarfdump -debug-info -v %t | FileCheck %s --check-prefixes=CHECK,DWARF64v3 15; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s 16 17; PR9493 18; Adapted from the original test case in r127757. 19; We use 'llc -O1' to induce variable 'x' to live in different locations. 20; We don't actually care where 'x' lives, or what exact optimizations get 21; used, as long as 'x' moves around we're fine. 22 23; // The variable 'x' lives in different locations, so it needs an entry in 24; // the .debug_loc table section, referenced by DW_AT_location. 25; // This ref is not relocatable on Darwin, and is relocatable elsewhere. 26; extern int g(int, int); 27; extern int a; 28; 29; void f(void) { 30; int x; 31; a = g(0, 0); 32; x = 1; 33; while (x & 1) { x *= a; } 34; a = g(x, 0); 35; x = 2; 36; while (x & 2) { x *= a; } 37; a = g(0, x); 38; } 39 40; // The 'x' variable and its symbol reference location 41; CHECK: .debug_info contents: 42; CHECK: DW_TAG_variable 43; DWARF32v3-NEXT: DW_AT_location [DW_FORM_data4] (0x00000000 44; DWARF64v3-NEXT: DW_AT_location [DW_FORM_data8] (0x00000000 45; DWARFv4-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x00000000 46; Check that the location contains only 4 ranges. 47; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}) 48; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}) 49; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}) 50; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}){{.*}}) 51; CHECK-NEXT: DW_AT_name {{.*}} "x" 52; CHECK-NEXT: DW_AT_decl_file 53; CHECK-NEXT: DW_AT_decl_line 54; CHECK-NEXT: DW_AT_type 55 56; Check that we have no relocations in Darwin's output. 57; DARWIN-NOT: X86_64_RELOC{{.*}} __debug_loc 58 59; Check we have a relocation for the debug_loc entry in Linux output. 60; LINUX: RELOCATION RECORDS FOR [.debug_info] 61; LINUX-NOT: RELOCATION RECORDS 62; LINUX: R_X86_64{{.*}} .debug_loc 63 64; ModuleID = 'simple.c' 65target 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" 66 67@a = external global i32 68 69define void @f() nounwind !dbg !0 { 70entry: 71 %call = tail call i32 @g(i32 0, i32 0) nounwind, !dbg !8 72 store i32 %call, i32* @a, align 4, !dbg !8 73 tail call void @llvm.dbg.value(metadata i32 1, metadata !5, metadata !DIExpression()), !dbg !13 74 br label %while.body 75 76while.body: ; preds = %entry, %while.body 77 %x.017 = phi i32 [ 1, %entry ], [ %mul, %while.body ] 78 %mul = mul nsw i32 %call, %x.017, !dbg !14 79 %and = and i32 %mul, 1, !dbg !14 80 %tobool = icmp eq i32 %and, 0, !dbg !14 81 br i1 %tobool, label %while.end, label %while.body, !dbg !14 82 83while.end: ; preds = %while.body 84 tail call void @llvm.dbg.value(metadata i32 %mul, metadata !5, metadata !DIExpression()), !dbg !14 85 %call4 = tail call i32 @g(i32 %mul, i32 0) nounwind, !dbg !15 86 store i32 %call4, i32* @a, align 4, !dbg !15 87 tail call void @llvm.dbg.value(metadata i32 2, metadata !5, metadata !DIExpression()), !dbg !17 88 br label %while.body9 89 90while.body9: ; preds = %while.end, %while.body9 91 %x.116 = phi i32 [ 2, %while.end ], [ %mul12, %while.body9 ] 92 %mul12 = mul nsw i32 %call4, %x.116, !dbg !18 93 %and7 = and i32 %mul12, 2, !dbg !18 94 %tobool8 = icmp eq i32 %and7, 0, !dbg !18 95 br i1 %tobool8, label %while.end13, label %while.body9, !dbg !18 96 97while.end13: ; preds = %while.body9 98 tail call void @llvm.dbg.value(metadata i32 %mul12, metadata !5, metadata !DIExpression()), !dbg !18 99 %call15 = tail call i32 @g(i32 0, i32 %mul12) nounwind, !dbg !19 100 store i32 %call15, i32* @a, align 4, !dbg !19 101 ret void, !dbg !20 102} 103 104declare i32 @g(i32, i32) 105 106declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone 107 108!llvm.dbg.cu = !{!2} 109!llvm.module.flags = !{!24} 110 111!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) 112!1 = !DIFile(filename: "simple.c", directory: "/home/rengol01/temp/tests/dwarf/relocation") 113!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk)", isOptimized: true, emissionKind: FullDebug, file: !23, enums: !{}, retainedTypes: !{}, imports: null) 114!3 = !DISubroutineType(types: !4) 115!4 = !{null} 116!5 = !DILocalVariable(name: "x", line: 5, scope: !6, file: !1, type: !7) 117!6 = distinct !DILexicalBlock(line: 4, column: 14, file: !23, scope: !0) 118!7 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 119!8 = !DILocation(line: 6, column: 3, scope: !6) 120!12 = !{i32 1} 121!13 = !DILocation(line: 7, column: 3, scope: !6) 122!14 = !DILocation(line: 8, column: 3, scope: !6) 123!15 = !DILocation(line: 9, column: 3, scope: !6) 124!16 = !{i32 2} 125!17 = !DILocation(line: 10, column: 3, scope: !6) 126!18 = !DILocation(line: 11, column: 3, scope: !6) 127!19 = !DILocation(line: 12, column: 3, scope: !6) 128!20 = !DILocation(line: 13, column: 1, scope: !6) 129!22 = !{!5} 130!23 = !DIFile(filename: "simple.c", directory: "/home/rengol01/temp/tests/dwarf/relocation") 131!24 = !{i32 1, !"Debug Info Version", i32 3} 132