1 ; RUN: llc -O1 -mtriple=x86_64-apple-darwin < %s | FileCheck -check-prefix=DARWIN %s 2 ; RUN: llc -O1 -mtriple=x86_64-pc-linux-gnu < %s | FileCheck -check-prefix=LINUX %s 3 ; PR9493 4 ; Adapted from the original test case in r127757. 5 ; We use 'llc -O1' to induce variable 'x' to live in different locations. 6 ; We don't actually care where 'x' lives, or what exact optimizations get 7 ; used, as long as 'x' moves around we're fine. 8 9 ; // The variable 'x' lives in different locations, so it needs an entry in 10 ; // the .debug_loc table section, referenced by DW_AT_location. 11 ; // This ref is not relocatable on Darwin, and is relocatable elsewhere. 12 ; extern int g(int, int); 13 ; extern int a; 14 ; 15 ; void f(void) { 16 ; int x; 17 ; a = g(0, 0); 18 ; x = 1; 19 ; while (x & 1) { x *= a; } 20 ; a = g(x, 0); 21 ; x = 2; 22 ; while (x & 2) { x *= a; } 23 ; a = g(0, x); 24 ; } 25 26 ; // The 'x' variable and its symbol reference location 27 ; DARWIN: DW_TAG_variable 28 ; DARWIN-NEXT: ## DW_AT_name 29 ; DARWIN-NEXT: .long Lset{{[0-9]+}} 30 ; DARWIN-NEXT: ## DW_AT_decl_file 31 ; DARWIN-NEXT: ## DW_AT_decl_line 32 ; DARWIN-NEXT: ## DW_AT_type 33 ; DARWIN-NEXT: Lset{{[0-9]+}} = Ldebug_loc{{[0-9]+}}-Lsection_debug_loc ## DW_AT_location 34 ; DARWIN-NEXT: .long Lset{{[0-9]+}} 35 36 ; LINUX: DW_TAG_variable 37 ; LINUX-NEXT: # DW_AT_name 38 ; LINUX-NEXT: # DW_AT_decl_file 39 ; LINUX-NEXT: # DW_AT_decl_line 40 ; LINUX-NEXT: # DW_AT_type 41 ; LINUX-NEXT: .long .Ldebug_loc{{[0-9]+}} # DW_AT_location 42 43 44 ; ModuleID = 'simple.c' 45 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" 46 47 @a = external global i32 48 49 define void @f() nounwind { 50 entry: 51 %call = tail call i32 @g(i32 0, i32 0) nounwind, !dbg !8 52 store i32 %call, i32* @a, align 4, !dbg !8 53 tail call void @llvm.dbg.value(metadata !12, i64 0, metadata !5), !dbg !13 54 br label %while.body 55 56 while.body: ; preds = %entry, %while.body 57 %x.017 = phi i32 [ 1, %entry ], [ %mul, %while.body ] 58 %mul = mul nsw i32 %call, %x.017, !dbg !14 59 %and = and i32 %mul, 1, !dbg !14 60 %tobool = icmp eq i32 %and, 0, !dbg !14 61 br i1 %tobool, label %while.end, label %while.body, !dbg !14 62 63 while.end: ; preds = %while.body 64 tail call void @llvm.dbg.value(metadata !{i32 %mul}, i64 0, metadata !5), !dbg !14 65 %call4 = tail call i32 @g(i32 %mul, i32 0) nounwind, !dbg !15 66 store i32 %call4, i32* @a, align 4, !dbg !15 67 tail call void @llvm.dbg.value(metadata !16, i64 0, metadata !5), !dbg !17 68 br label %while.body9 69 70 while.body9: ; preds = %while.end, %while.body9 71 %x.116 = phi i32 [ 2, %while.end ], [ %mul12, %while.body9 ] 72 %mul12 = mul nsw i32 %call4, %x.116, !dbg !18 73 %and7 = and i32 %mul12, 2, !dbg !18 74 %tobool8 = icmp eq i32 %and7, 0, !dbg !18 75 br i1 %tobool8, label %while.end13, label %while.body9, !dbg !18 76 77 while.end13: ; preds = %while.body9 78 tail call void @llvm.dbg.value(metadata !{i32 %mul12}, i64 0, metadata !5), !dbg !18 79 %call15 = tail call i32 @g(i32 0, i32 %mul12) nounwind, !dbg !19 80 store i32 %call15, i32* @a, align 4, !dbg !19 81 ret void, !dbg !20 82 } 83 84 declare i32 @g(i32, i32) 85 86 declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone 87 88 !llvm.dbg.cu = !{!2} 89 90 !0 = metadata !{i32 786478, metadata !23, metadata !1, metadata !"f", metadata !"f", metadata !"", i32 4, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 true, void ()* @f, null, null, metadata !22, i32 4} ; [ DW_TAG_subprogram ] 91 !1 = metadata !{i32 786473, metadata !23} ; [ DW_TAG_file_type ] 92 !2 = metadata !{i32 786449, metadata !23, i32 12, metadata !"clang version 3.0 (trunk)", i1 true, metadata !"", i32 0, metadata !4, metadata !4, metadata !21, null, null, null} ; [ DW_TAG_compile_unit ] 93 !3 = metadata !{i32 786453, metadata !23, metadata !1, metadata !"", i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] 94 !4 = metadata !{null} 95 !5 = metadata !{i32 786688, metadata !6, metadata !"x", metadata !1, i32 5, metadata !7, i32 0, null} ; [ DW_TAG_auto_variable ] 96 !6 = metadata !{i32 786443, metadata !23, metadata !0, i32 4, i32 14, i32 0} ; [ DW_TAG_lexical_block ] 97 !7 = metadata !{i32 786468, null, metadata !2, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] 98 !8 = metadata !{i32 6, i32 3, metadata !6, null} 99 !12 = metadata !{i32 1} 100 !13 = metadata !{i32 7, i32 3, metadata !6, null} 101 !14 = metadata !{i32 8, i32 3, metadata !6, null} 102 !15 = metadata !{i32 9, i32 3, metadata !6, null} 103 !16 = metadata !{i32 2} 104 !17 = metadata !{i32 10, i32 3, metadata !6, null} 105 !18 = metadata !{i32 11, i32 3, metadata !6, null} 106 !19 = metadata !{i32 12, i32 3, metadata !6, null} 107 !20 = metadata !{i32 13, i32 1, metadata !6, null} 108 !21 = metadata !{metadata !0} 109 !22 = metadata !{metadata !5} 110 !23 = metadata !{metadata !"simple.c", metadata !"/home/rengol01/temp/tests/dwarf/relocation"} 111