1; RUN: llc -fast-isel-sink-local-values -O0 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s 2; RUN: llc -fast-isel-sink-local-values -O0 -mtriple=x86_64-unknown-linux-gnu -filetype=obj < %s \ 3; RUN: | llvm-dwarfdump -debug-info - | FileCheck %s --check-prefix=DWARF 4 5; Verify that we have correct debug info for local variables in code 6; instrumented with AddressSanitizer. 7 8; Generated from the source file test.cc: 9; int bar(int y) { 10; return y + 2; 11; } 12; with "clang++ -S -emit-llvm -mllvm -asan-skip-promotable-allocas=0 -fsanitize=address -O0 -g test.cc" 13 14; The address of the (potentially now malloc'ed) alloca ends up 15; in rdi, after which it is spilled to the stack. We record the 16; spill OFFSET on the stack for checking the debug info below. 17; CHECK: #DEBUG_VALUE: bar:y <- [DW_OP_deref] [$rcx+0] 18; CHECK: movq %rcx, [[OFFSET:[0-9]+]](%rsp) 19; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]] 20; CHECK-NEXT: #DEBUG_VALUE: bar:y <- [DW_OP_plus_uconst [[OFFSET]], DW_OP_deref, DW_OP_deref] 21; This location should be valid until the end of the function. 22 23; CHECK: movq %rbp, %rsp 24; CHECK-NEXT: [[END_LABEL:.Ltmp[0-9]+]]: 25 26; CHECK: .Ldebug_loc{{[0-9]+}}: 27; We expect two location ranges for the variable. 28 29; First, its address is stored in %rcx: 30; CHECK: .quad .Lfunc_begin0-.Lfunc_begin0 31; CHECK-NEXT: .quad [[START_LABEL]]-.Lfunc_begin0 32; CHECK: DW_OP_breg2 33; DWARF: DW_TAG_formal_parameter 34; DWARF: DW_AT_location 35; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg2 RCX+0, DW_OP_deref 36 37; Then it's addressed via %rsp: 38; CHECK: .quad [[START_LABEL]]-.Lfunc_begin0 39; CHECK-NEXT: .quad [[END_LABEL]]-.Lfunc_begin0 40; CHECK: DW_OP_breg7 41; CHECK-NEXT: [[OFFSET]] 42; CHECK: DW_OP_deref 43; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg7 RSP+{{[0-9]+}}, DW_OP_deref, DW_OP_deref) 44 45; ModuleID = 'test.cc' 46target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 47target triple = "x86_64-unknown-linux-gnu" 48 49@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }] 50@__asan_option_detect_stack_use_after_return = external global i32 51@___asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1 52 53; Function Attrs: nounwind sanitize_address uwtable 54define i32 @_Z3bari(i32 %y) #0 !dbg !4 { 55entry: 56 %MyAlloca = alloca [64 x i8], align 32 57 %0 = ptrtoint [64 x i8]* %MyAlloca to i64 58 %1 = load i32, i32* @__asan_option_detect_stack_use_after_return 59 %2 = icmp ne i32 %1, 0 60 br i1 %2, label %3, label %5 61 62; <label>:3 ; preds = %entry 63 %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0) 64 br label %5 65 66; <label>:5 ; preds = %entry, %3 67 %6 = phi i64 [ %0, %entry ], [ %4, %3 ] 68 %7 = add i64 %6, 32 69 %8 = inttoptr i64 %7 to i32* 70 %9 = inttoptr i64 %6 to i64* 71 store i64 1102416563, i64* %9 72 %10 = add i64 %6, 8 73 %11 = inttoptr i64 %10 to i64* 74 store i64 ptrtoint ([16 x i8]* @___asan_gen_ to i64), i64* %11 75 %12 = add i64 %6, 16 76 %13 = inttoptr i64 %12 to i64* 77 store i64 ptrtoint (i32 (i32)* @_Z3bari to i64), i64* %13 78 %14 = lshr i64 %6, 3 79 %15 = add i64 %14, 2147450880 80 %16 = add i64 %15, 0 81 %17 = inttoptr i64 %16 to i64* 82 store i64 -868083100587789839, i64* %17 83 %18 = ptrtoint i32* %8 to i64 84 %19 = lshr i64 %18, 3 85 %20 = add i64 %19, 2147450880 86 %21 = inttoptr i64 %20 to i8* 87 %22 = load i8, i8* %21 88 %23 = icmp ne i8 %22, 0 89 call void @llvm.dbg.declare(metadata i32* %8, metadata !12, metadata !14), !dbg !DILocation(scope: !4) 90 br i1 %23, label %24, label %30 91 92; <label>:24 ; preds = %5 93 %25 = and i64 %18, 7 94 %26 = add i64 %25, 3 95 %27 = trunc i64 %26 to i8 96 %28 = icmp sge i8 %27, %22 97 br i1 %28, label %29, label %30 98 99; <label>:29 ; preds = %24 100 call void @__asan_report_store4(i64 %18) 101 call void asm sideeffect "", ""() 102 unreachable 103 104; <label>:30 ; preds = %24, %5 105 store i32 %y, i32* %8, align 4 106 %31 = ptrtoint i32* %8 to i64, !dbg !13 107 %32 = lshr i64 %31, 3, !dbg !13 108 %33 = add i64 %32, 2147450880, !dbg !13 109 %34 = inttoptr i64 %33 to i8*, !dbg !13 110 %35 = load i8, i8* %34, !dbg !13 111 %36 = icmp ne i8 %35, 0, !dbg !13 112 br i1 %36, label %37, label %43, !dbg !13 113 114; <label>:37 ; preds = %30 115 %38 = and i64 %31, 7, !dbg !13 116 %39 = add i64 %38, 3, !dbg !13 117 %40 = trunc i64 %39 to i8, !dbg !13 118 %41 = icmp sge i8 %40, %35, !dbg !13 119 br i1 %41, label %42, label %43 120 121; <label>:42 ; preds = %37 122 call void @__asan_report_load4(i64 %31), !dbg !13 123 call void asm sideeffect "", ""() 124 unreachable 125 126; <label>:43 ; preds = %37, %30 127 %44 = load i32, i32* %8, align 4, !dbg !13 128 %add = add nsw i32 %44, 2, !dbg !13 129 store i64 1172321806, i64* %9, !dbg !13 130 %45 = icmp ne i64 %6, %0, !dbg !13 131 br i1 %45, label %46, label %53, !dbg !13 132 133; <label>:46 ; preds = %43 134 %47 = add i64 %15, 0, !dbg !13 135 %48 = inttoptr i64 %47 to i64*, !dbg !13 136 store i64 -723401728380766731, i64* %48, !dbg !13 137 %49 = add i64 %6, 56, !dbg !13 138 %50 = inttoptr i64 %49 to i64*, !dbg !13 139 %51 = load i64, i64* %50, !dbg !13 140 %52 = inttoptr i64 %51 to i8*, !dbg !13 141 store i8 0, i8* %52, !dbg !13 142 br label %56, !dbg !13 143 144; <label>:53 ; preds = %43 145 %54 = add i64 %15, 0, !dbg !13 146 %55 = inttoptr i64 %54 to i64*, !dbg !13 147 store i64 0, i64* %55, !dbg !13 148 br label %56, !dbg !13 149 150; <label>:56 ; preds = %53, %46 151 ret i32 %add, !dbg !13 152} 153 154; Function Attrs: nounwind readnone 155declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 156 157define internal void @asan.module_ctor() { 158 call void @__asan_init_v3() 159 ret void 160} 161 162declare void @__asan_init_v3() 163 164declare void @__asan_report_load4(i64) 165 166declare void @__asan_report_store4(i64) 167 168declare i64 @__asan_stack_malloc_0(i64, i64) 169 170attributes #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" } 171attributes #1 = { nounwind readnone } 172 173!llvm.dbg.cu = !{!0} 174!llvm.module.flags = !{!9, !10} 175!llvm.ident = !{!11} 176 177!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 (209308)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 178!1 = !DIFile(filename: "test.cc", directory: "/llvm_cmake_gcc") 179!2 = !{} 180!4 = distinct !DISubprogram(name: "bar", linkageName: "_Z3bari", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, retainedNodes: !2) 181!5 = !DIFile(filename: "test.cc", directory: "/llvm_cmake_gcc") 182!6 = !DISubroutineType(types: !7) 183!7 = !{!8, !8} 184!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 185!9 = !{i32 2, !"Dwarf Version", i32 4} 186!10 = !{i32 2, !"Debug Info Version", i32 3} 187!11 = !{!"clang version 3.5.0 (209308)"} 188!12 = !DILocalVariable(name: "y", line: 1, arg: 1, scope: !4, file: !5, type: !8) 189!13 = !DILocation(line: 2, scope: !4) 190!14 = !DIExpression(DW_OP_deref) 191