Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 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 | |
Louis Gerbarg | 343f5cd | 2014-06-17 23:22:41 +0000 | [diff] [blame] | 12 | ; First, argument variable "y" resides in %rdi: |
| 13 | ; CHECK: DEBUG_VALUE: bar:y <- RDI |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 14 | |
| 15 | ; Then its address is stored in a location on a stack: |
Louis Gerbarg | 343f5cd | 2014-06-17 23:22:41 +0000 | [diff] [blame] | 16 | ; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp) |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 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 | |
Adrian Prantl | 092d948 | 2015-01-13 23:39:11 +0000 | [diff] [blame] | 24 | ; First, its address is stored in %rdi: |
Rafael Espindola | c606bfe | 2014-10-21 01:17:30 +0000 | [diff] [blame] | 25 | ; CHECK: .quad .Lfunc_begin0-.Lfunc_begin0 |
| 26 | ; CHECK-NEXT: .quad [[START_LABEL]]-.Lfunc_begin0 |
Adrian Prantl | 092d948 | 2015-01-13 23:39:11 +0000 | [diff] [blame] | 27 | ; CHECK: DW_OP_breg5 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 28 | |
| 29 | ; Then it's addressed via %rsp: |
Rafael Espindola | c606bfe | 2014-10-21 01:17:30 +0000 | [diff] [blame] | 30 | ; CHECK: .quad [[START_LABEL]]-.Lfunc_begin0 |
| 31 | ; CHECK-NEXT: .Lfunc_end0-.Lfunc_begin0 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 32 | ; CHECK: DW_OP_breg7 |
| 33 | ; CHECK-NEXT: [[OFFSET]] |
| 34 | ; CHECK: DW_OP_deref |
| 35 | |
| 36 | ; ModuleID = 'test.cc' |
| 37 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 38 | target triple = "x86_64-unknown-linux-gnu" |
| 39 | |
| 40 | @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }] |
| 41 | @__asan_option_detect_stack_use_after_return = external global i32 |
| 42 | @__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1 |
| 43 | |
| 44 | ; Function Attrs: nounwind sanitize_address uwtable |
| 45 | define i32 @_Z3bari(i32 %y) #0 { |
| 46 | entry: |
| 47 | %MyAlloca = alloca [64 x i8], align 32 |
| 48 | %0 = ptrtoint [64 x i8]* %MyAlloca to i64 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 49 | %1 = load i32, i32* @__asan_option_detect_stack_use_after_return |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 50 | %2 = icmp ne i32 %1, 0 |
| 51 | br i1 %2, label %3, label %5 |
| 52 | |
| 53 | ; <label>:3 ; preds = %entry |
| 54 | %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0) |
| 55 | br label %5 |
| 56 | |
| 57 | ; <label>:5 ; preds = %entry, %3 |
| 58 | %6 = phi i64 [ %0, %entry ], [ %4, %3 ] |
| 59 | %7 = add i64 %6, 32 |
| 60 | %8 = inttoptr i64 %7 to i32* |
| 61 | %9 = inttoptr i64 %6 to i64* |
| 62 | store i64 1102416563, i64* %9 |
| 63 | %10 = add i64 %6, 8 |
| 64 | %11 = inttoptr i64 %10 to i64* |
| 65 | store i64 ptrtoint ([16 x i8]* @__asan_gen_ to i64), i64* %11 |
| 66 | %12 = add i64 %6, 16 |
| 67 | %13 = inttoptr i64 %12 to i64* |
| 68 | store i64 ptrtoint (i32 (i32)* @_Z3bari to i64), i64* %13 |
| 69 | %14 = lshr i64 %6, 3 |
| 70 | %15 = add i64 %14, 2147450880 |
| 71 | %16 = add i64 %15, 0 |
| 72 | %17 = inttoptr i64 %16 to i64* |
| 73 | store i64 -868083100587789839, i64* %17 |
| 74 | %18 = ptrtoint i32* %8 to i64 |
| 75 | %19 = lshr i64 %18, 3 |
| 76 | %20 = add i64 %19, 2147450880 |
| 77 | %21 = inttoptr i64 %20 to i8* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 78 | %22 = load i8, i8* %21 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 79 | %23 = icmp ne i8 %22, 0 |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 80 | call void @llvm.dbg.declare(metadata i32* %8, metadata !12, metadata !14) |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 81 | br i1 %23, label %24, label %30 |
| 82 | |
| 83 | ; <label>:24 ; preds = %5 |
| 84 | %25 = and i64 %18, 7 |
| 85 | %26 = add i64 %25, 3 |
| 86 | %27 = trunc i64 %26 to i8 |
| 87 | %28 = icmp sge i8 %27, %22 |
| 88 | br i1 %28, label %29, label %30 |
| 89 | |
| 90 | ; <label>:29 ; preds = %24 |
| 91 | call void @__asan_report_store4(i64 %18) |
| 92 | call void asm sideeffect "", ""() |
| 93 | unreachable |
| 94 | |
| 95 | ; <label>:30 ; preds = %24, %5 |
| 96 | store i32 %y, i32* %8, align 4 |
| 97 | %31 = ptrtoint i32* %8 to i64, !dbg !13 |
| 98 | %32 = lshr i64 %31, 3, !dbg !13 |
| 99 | %33 = add i64 %32, 2147450880, !dbg !13 |
| 100 | %34 = inttoptr i64 %33 to i8*, !dbg !13 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 101 | %35 = load i8, i8* %34, !dbg !13 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 102 | %36 = icmp ne i8 %35, 0, !dbg !13 |
| 103 | br i1 %36, label %37, label %43, !dbg !13 |
| 104 | |
| 105 | ; <label>:37 ; preds = %30 |
| 106 | %38 = and i64 %31, 7, !dbg !13 |
| 107 | %39 = add i64 %38, 3, !dbg !13 |
| 108 | %40 = trunc i64 %39 to i8, !dbg !13 |
| 109 | %41 = icmp sge i8 %40, %35, !dbg !13 |
| 110 | br i1 %41, label %42, label %43 |
| 111 | |
| 112 | ; <label>:42 ; preds = %37 |
| 113 | call void @__asan_report_load4(i64 %31), !dbg !13 |
| 114 | call void asm sideeffect "", ""() |
| 115 | unreachable |
| 116 | |
| 117 | ; <label>:43 ; preds = %37, %30 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 118 | %44 = load i32, i32* %8, align 4, !dbg !13 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 119 | %add = add nsw i32 %44, 2, !dbg !13 |
| 120 | store i64 1172321806, i64* %9, !dbg !13 |
| 121 | %45 = icmp ne i64 %6, %0, !dbg !13 |
| 122 | br i1 %45, label %46, label %53, !dbg !13 |
| 123 | |
| 124 | ; <label>:46 ; preds = %43 |
| 125 | %47 = add i64 %15, 0, !dbg !13 |
| 126 | %48 = inttoptr i64 %47 to i64*, !dbg !13 |
| 127 | store i64 -723401728380766731, i64* %48, !dbg !13 |
| 128 | %49 = add i64 %6, 56, !dbg !13 |
| 129 | %50 = inttoptr i64 %49 to i64*, !dbg !13 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 130 | %51 = load i64, i64* %50, !dbg !13 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 131 | %52 = inttoptr i64 %51 to i8*, !dbg !13 |
| 132 | store i8 0, i8* %52, !dbg !13 |
| 133 | br label %56, !dbg !13 |
| 134 | |
| 135 | ; <label>:53 ; preds = %43 |
| 136 | %54 = add i64 %15, 0, !dbg !13 |
| 137 | %55 = inttoptr i64 %54 to i64*, !dbg !13 |
| 138 | store i64 0, i64* %55, !dbg !13 |
| 139 | br label %56, !dbg !13 |
| 140 | |
| 141 | ; <label>:56 ; preds = %53, %46 |
| 142 | ret i32 %add, !dbg !13 |
| 143 | } |
| 144 | |
| 145 | ; Function Attrs: nounwind readnone |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 146 | declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 147 | |
| 148 | define internal void @asan.module_ctor() { |
| 149 | call void @__asan_init_v3() |
| 150 | ret void |
| 151 | } |
| 152 | |
| 153 | declare void @__asan_init_v3() |
| 154 | |
| 155 | declare void @__asan_report_load4(i64) |
| 156 | |
| 157 | declare void @__asan_report_store4(i64) |
| 158 | |
| 159 | declare i64 @__asan_stack_malloc_0(i64, i64) |
| 160 | |
| 161 | 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" } |
| 162 | attributes #1 = { nounwind readnone } |
| 163 | |
| 164 | !llvm.dbg.cu = !{!0} |
| 165 | !llvm.module.flags = !{!9, !10} |
| 166 | !llvm.ident = !{!11} |
| 167 | |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 168 | !0 = !{!"0x11\004\00clang version 3.5.0 (209308)\000\00\000\00\001", !1, !2, !2, !3, !2, !2} ; [ DW_TAG_compile_unit ] [/llvm_cmake_gcc/test.cc] [DW_LANG_C_plus_plus] |
| 169 | !1 = !{!"test.cc", !"/llvm_cmake_gcc"} |
| 170 | !2 = !{} |
| 171 | !3 = !{!4} |
| 172 | !4 = !{!"0x2e\00bar\00bar\00_Z3bari\001\000\001\000\006\00256\000\001", !1, !5, !6, null, i32 (i32)* @_Z3bari, null, null, !2} ; [ DW_TAG_subprogram ] [line 1] [def] [bar] |
| 173 | !5 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/llvm_cmake_gcc/test.cc] |
| 174 | !6 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] |
| 175 | !7 = !{!8, !8} |
| 176 | !8 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] |
| 177 | !9 = !{i32 2, !"Dwarf Version", i32 4} |
| 178 | !10 = !{i32 2, !"Debug Info Version", i32 2} |
| 179 | !11 = !{!"clang version 3.5.0 (209308)"} |
| 180 | !12 = !{!"0x101\00y\0016777217\000", !4, !5, !8} ; [ DW_TAG_arg_variable ] [y] [line 1] |
Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 181 | !13 = !MDLocation(line: 2, scope: !4) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 182 | !14 = !{!"0x102\006"} ; [ DW_TAG_expression ] [DW_OP_deref] |