1 ; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s 2 3 ; Verify that we have correct debug info for local variables in code 4 ; instrumented with AddressSanitizer. 5 6 ; Generated from the source file test.cc: 7 ; int bar(int y) { 8 ; return y + 2; 9 ; } 10 ; with "clang++ -S -emit-llvm -fsanitize=address -O0 -g test.cc" 11 12 ; First, argument variable "y" resides in %rdi: 13 ; CHECK: DEBUG_VALUE: bar:y <- RDI 14 15 ; Then its address is stored in a location on a stack: 16 ; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp) 17 ; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]] 18 ; CHECK-NEXT: DEBUG_VALUE: bar:y <- [RSP+[[OFFSET]]] 19 ; This location should be valid until the end of the function. 20 21 ; CHECK: .Ldebug_loc{{[0-9]+}}: 22 ; We expect two location ranges for the variable. 23 24 ; First, it is stored in %rdx: 25 ; CHECK: .Lset{{[0-9]+}} = .Lfunc_begin0-.Lfunc_begin0 26 ; CHECK-NEXT: .quad .Lset{{[0-9]+}} 27 ; CHECK-NEXT: .Lset{{[0-9]+}} = [[START_LABEL]]-.Lfunc_begin0 28 ; CHECK-NEXT: .quad .Lset{{[0-9]+}} 29 ; CHECK: DW_OP_reg5 30 31 ; Then it's addressed via %rsp: 32 ; CHECK: .Lset{{[0-9]+}} = [[START_LABEL]]-.Lfunc_begin0 33 ; CHECK-NEXT: .quad .Lset{{[0-9]+}} 34 ; CHECK-NEXT: .Lset{{[0-9]+}} = .Lfunc_end0-.Lfunc_begin0 35 ; CHECK-NEXT: .quad .Lset{{[0-9]+}} 36 ; CHECK: DW_OP_breg7 37 ; CHECK-NEXT: [[OFFSET]] 38 ; CHECK: DW_OP_deref 39 40 ; ModuleID = 'test.cc' 41 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 42 target triple = "x86_64-unknown-linux-gnu" 43 44 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }] 45 @__asan_option_detect_stack_use_after_return = external global i32 46 @__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1 47 48 ; Function Attrs: nounwind sanitize_address uwtable 49 define i32 @_Z3bari(i32 %y) #0 { 50 entry: 51 %MyAlloca = alloca [64 x i8], align 32 52 %0 = ptrtoint [64 x i8]* %MyAlloca to i64 53 %1 = load i32* @__asan_option_detect_stack_use_after_return 54 %2 = icmp ne i32 %1, 0 55 br i1 %2, label %3, label %5 56 57 ; <label>:3 ; preds = %entry 58 %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0) 59 br label %5 60 61 ; <label>:5 ; preds = %entry, %3 62 %6 = phi i64 [ %0, %entry ], [ %4, %3 ] 63 %7 = add i64 %6, 32 64 %8 = inttoptr i64 %7 to i32* 65 %9 = inttoptr i64 %6 to i64* 66 store i64 1102416563, i64* %9 67 %10 = add i64 %6, 8 68 %11 = inttoptr i64 %10 to i64* 69 store i64 ptrtoint ([16 x i8]* @__asan_gen_ to i64), i64* %11 70 %12 = add i64 %6, 16 71 %13 = inttoptr i64 %12 to i64* 72 store i64 ptrtoint (i32 (i32)* @_Z3bari to i64), i64* %13 73 %14 = lshr i64 %6, 3 74 %15 = add i64 %14, 2147450880 75 %16 = add i64 %15, 0 76 %17 = inttoptr i64 %16 to i64* 77 store i64 -868083100587789839, i64* %17 78 %18 = ptrtoint i32* %8 to i64 79 %19 = lshr i64 %18, 3 80 %20 = add i64 %19, 2147450880 81 %21 = inttoptr i64 %20 to i8* 82 %22 = load i8* %21 83 %23 = icmp ne i8 %22, 0 84 call void @llvm.dbg.declare(metadata !{i32* %8}, metadata !12) 85 br i1 %23, label %24, label %30 86 87 ; <label>:24 ; preds = %5 88 %25 = and i64 %18, 7 89 %26 = add i64 %25, 3 90 %27 = trunc i64 %26 to i8 91 %28 = icmp sge i8 %27, %22 92 br i1 %28, label %29, label %30 93 94 ; <label>:29 ; preds = %24 95 call void @__asan_report_store4(i64 %18) 96 call void asm sideeffect "", ""() 97 unreachable 98 99 ; <label>:30 ; preds = %24, %5 100 store i32 %y, i32* %8, align 4 101 %31 = ptrtoint i32* %8 to i64, !dbg !13 102 %32 = lshr i64 %31, 3, !dbg !13 103 %33 = add i64 %32, 2147450880, !dbg !13 104 %34 = inttoptr i64 %33 to i8*, !dbg !13 105 %35 = load i8* %34, !dbg !13 106 %36 = icmp ne i8 %35, 0, !dbg !13 107 br i1 %36, label %37, label %43, !dbg !13 108 109 ; <label>:37 ; preds = %30 110 %38 = and i64 %31, 7, !dbg !13 111 %39 = add i64 %38, 3, !dbg !13 112 %40 = trunc i64 %39 to i8, !dbg !13 113 %41 = icmp sge i8 %40, %35, !dbg !13 114 br i1 %41, label %42, label %43 115 116 ; <label>:42 ; preds = %37 117 call void @__asan_report_load4(i64 %31), !dbg !13 118 call void asm sideeffect "", ""() 119 unreachable 120 121 ; <label>:43 ; preds = %37, %30 122 %44 = load i32* %8, align 4, !dbg !13 123 %add = add nsw i32 %44, 2, !dbg !13 124 store i64 1172321806, i64* %9, !dbg !13 125 %45 = icmp ne i64 %6, %0, !dbg !13 126 br i1 %45, label %46, label %53, !dbg !13 127 128 ; <label>:46 ; preds = %43 129 %47 = add i64 %15, 0, !dbg !13 130 %48 = inttoptr i64 %47 to i64*, !dbg !13 131 store i64 -723401728380766731, i64* %48, !dbg !13 132 %49 = add i64 %6, 56, !dbg !13 133 %50 = inttoptr i64 %49 to i64*, !dbg !13 134 %51 = load i64* %50, !dbg !13 135 %52 = inttoptr i64 %51 to i8*, !dbg !13 136 store i8 0, i8* %52, !dbg !13 137 br label %56, !dbg !13 138 139 ; <label>:53 ; preds = %43 140 %54 = add i64 %15, 0, !dbg !13 141 %55 = inttoptr i64 %54 to i64*, !dbg !13 142 store i64 0, i64* %55, !dbg !13 143 br label %56, !dbg !13 144 145 ; <label>:56 ; preds = %53, %46 146 ret i32 %add, !dbg !13 147 } 148 149 ; Function Attrs: nounwind readnone 150 declare void @llvm.dbg.declare(metadata, metadata) #1 151 152 define internal void @asan.module_ctor() { 153 call void @__asan_init_v3() 154 ret void 155 } 156 157 declare void @__asan_init_v3() 158 159 declare void @__asan_report_load4(i64) 160 161 declare void @__asan_report_store4(i64) 162 163 declare i64 @__asan_stack_malloc_0(i64, i64) 164 165 attributes #0 = { nounwind sanitize_address uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 166 attributes #1 = { nounwind readnone } 167 168 !llvm.dbg.cu = !{!0} 169 !llvm.module.flags = !{!9, !10} 170 !llvm.ident = !{!11} 171 172 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 (209308)", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/llvm_cmake_gcc/test.cc] [DW_LANG_C_plus_plus] 173 !1 = metadata !{metadata !"test.cc", metadata !"/llvm_cmake_gcc"} 174 !2 = metadata !{} 175 !3 = metadata !{metadata !4} 176 !4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"bar", metadata !"bar", metadata !"_Z3bari", i32 1, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i32)* @_Z3bari, null, null, metadata !2, i32 1} ; [ DW_TAG_subprogram ] [line 1] [def] [bar] 177 !5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/llvm_cmake_gcc/test.cc] 178 !6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] 179 !7 = metadata !{metadata !8, metadata !8} 180 !8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] 181 !9 = metadata !{i32 2, metadata !"Dwarf Version", i32 4} 182 !10 = metadata !{i32 2, metadata !"Debug Info Version", i32 1} 183 !11 = metadata !{metadata !"clang version 3.5.0 (209308)"} 184 !12 = metadata !{i32 786689, metadata !4, metadata !"y", metadata !5, i32 16777217, metadata !8, i32 0, i32 0, metadata !14} ; [ DW_TAG_arg_variable ] [y] [line 1] 185 !13 = metadata !{i32 2, i32 0, metadata !4, null} 186 !14 = metadata !{i64 2} 187