blob: e4449a29281c2015c4b598ae9beb14840fcca41c [file] [log] [blame]
Alexey Samsonov8000e272014-06-09 21:53:47 +00001; 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; }
Keno Fischer00cbf9a2015-12-19 02:02:44 +000010; with "clang++ -S -emit-llvm -mllvm -asan-skip-promotable-allocas=0 -fsanitize=address -O0 -g test.cc"
Alexey Samsonov8000e272014-06-09 21:53:47 +000011
Keno Fischer00cbf9a2015-12-19 02:02:44 +000012; The address of the (potentially now malloc'ed) alloca ends up
13; in RDI, after which it is spilled to the stack. We record the
14; spill OFFSET on the stack for checking the debug info below.
15; CHECK: #DEBUG_VALUE: bar:y <- [%RDI+0]
Louis Gerbarg343f5cd2014-06-17 23:22:41 +000016; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp)
Alexey Samsonov8000e272014-06-09 21:53:47 +000017; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]]
Reid Klecknerf6f04f82016-03-25 17:54:46 +000018; CHECK-NEXT: #DEBUG_VALUE: bar:y <- [complex expression]
Alexey Samsonov8000e272014-06-09 21:53:47 +000019; This location should be valid until the end of the function.
20
Reid Klecknerf6f04f82016-03-25 17:54:46 +000021; CHECK: movq %rbp, %rsp
22; CHECK-NEXT: [[END_LABEL:.Ltmp[0-9]+]]:
23
Alexey Samsonov8000e272014-06-09 21:53:47 +000024; CHECK: .Ldebug_loc{{[0-9]+}}:
25; We expect two location ranges for the variable.
26
Adrian Prantl092d9482015-01-13 23:39:11 +000027; First, its address is stored in %rdi:
Rafael Espindolac606bfe2014-10-21 01:17:30 +000028; CHECK: .quad .Lfunc_begin0-.Lfunc_begin0
29; CHECK-NEXT: .quad [[START_LABEL]]-.Lfunc_begin0
Adrian Prantl092d9482015-01-13 23:39:11 +000030; CHECK: DW_OP_breg5
Alexey Samsonov8000e272014-06-09 21:53:47 +000031
32; Then it's addressed via %rsp:
Rafael Espindolac606bfe2014-10-21 01:17:30 +000033; CHECK: .quad [[START_LABEL]]-.Lfunc_begin0
Reid Klecknerf6f04f82016-03-25 17:54:46 +000034; CHECK-NEXT: .quad [[END_LABEL]]-.Lfunc_begin0
Alexey Samsonov8000e272014-06-09 21:53:47 +000035; CHECK: DW_OP_breg7
36; CHECK-NEXT: [[OFFSET]]
37; CHECK: DW_OP_deref
38
39; ModuleID = 'test.cc'
40target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
41target triple = "x86_64-unknown-linux-gnu"
42
43@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
44@__asan_option_detect_stack_use_after_return = external global i32
45@__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1
46
47; Function Attrs: nounwind sanitize_address uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000048define i32 @_Z3bari(i32 %y) #0 !dbg !4 {
Alexey Samsonov8000e272014-06-09 21:53:47 +000049entry:
50 %MyAlloca = alloca [64 x i8], align 32
51 %0 = ptrtoint [64 x i8]* %MyAlloca to i64
David Blaikiea79ac142015-02-27 21:17:42 +000052 %1 = load i32, i32* @__asan_option_detect_stack_use_after_return
Alexey Samsonov8000e272014-06-09 21:53:47 +000053 %2 = icmp ne i32 %1, 0
54 br i1 %2, label %3, label %5
55
56; <label>:3 ; preds = %entry
57 %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0)
58 br label %5
59
60; <label>:5 ; preds = %entry, %3
61 %6 = phi i64 [ %0, %entry ], [ %4, %3 ]
62 %7 = add i64 %6, 32
63 %8 = inttoptr i64 %7 to i32*
64 %9 = inttoptr i64 %6 to i64*
65 store i64 1102416563, i64* %9
66 %10 = add i64 %6, 8
67 %11 = inttoptr i64 %10 to i64*
68 store i64 ptrtoint ([16 x i8]* @__asan_gen_ to i64), i64* %11
69 %12 = add i64 %6, 16
70 %13 = inttoptr i64 %12 to i64*
71 store i64 ptrtoint (i32 (i32)* @_Z3bari to i64), i64* %13
72 %14 = lshr i64 %6, 3
73 %15 = add i64 %14, 2147450880
74 %16 = add i64 %15, 0
75 %17 = inttoptr i64 %16 to i64*
76 store i64 -868083100587789839, i64* %17
77 %18 = ptrtoint i32* %8 to i64
78 %19 = lshr i64 %18, 3
79 %20 = add i64 %19, 2147450880
80 %21 = inttoptr i64 %20 to i8*
David Blaikiea79ac142015-02-27 21:17:42 +000081 %22 = load i8, i8* %21
Alexey Samsonov8000e272014-06-09 21:53:47 +000082 %23 = icmp ne i8 %22, 0
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000083 call void @llvm.dbg.declare(metadata i32* %8, metadata !12, metadata !14), !dbg !DILocation(scope: !4)
Alexey Samsonov8000e272014-06-09 21:53:47 +000084 br i1 %23, label %24, label %30
85
86; <label>:24 ; preds = %5
87 %25 = and i64 %18, 7
88 %26 = add i64 %25, 3
89 %27 = trunc i64 %26 to i8
90 %28 = icmp sge i8 %27, %22
91 br i1 %28, label %29, label %30
92
93; <label>:29 ; preds = %24
94 call void @__asan_report_store4(i64 %18)
95 call void asm sideeffect "", ""()
96 unreachable
97
98; <label>:30 ; preds = %24, %5
99 store i32 %y, i32* %8, align 4
100 %31 = ptrtoint i32* %8 to i64, !dbg !13
101 %32 = lshr i64 %31, 3, !dbg !13
102 %33 = add i64 %32, 2147450880, !dbg !13
103 %34 = inttoptr i64 %33 to i8*, !dbg !13
David Blaikiea79ac142015-02-27 21:17:42 +0000104 %35 = load i8, i8* %34, !dbg !13
Alexey Samsonov8000e272014-06-09 21:53:47 +0000105 %36 = icmp ne i8 %35, 0, !dbg !13
106 br i1 %36, label %37, label %43, !dbg !13
107
108; <label>:37 ; preds = %30
109 %38 = and i64 %31, 7, !dbg !13
110 %39 = add i64 %38, 3, !dbg !13
111 %40 = trunc i64 %39 to i8, !dbg !13
112 %41 = icmp sge i8 %40, %35, !dbg !13
113 br i1 %41, label %42, label %43
114
115; <label>:42 ; preds = %37
116 call void @__asan_report_load4(i64 %31), !dbg !13
117 call void asm sideeffect "", ""()
118 unreachable
119
120; <label>:43 ; preds = %37, %30
David Blaikiea79ac142015-02-27 21:17:42 +0000121 %44 = load i32, i32* %8, align 4, !dbg !13
Alexey Samsonov8000e272014-06-09 21:53:47 +0000122 %add = add nsw i32 %44, 2, !dbg !13
123 store i64 1172321806, i64* %9, !dbg !13
124 %45 = icmp ne i64 %6, %0, !dbg !13
125 br i1 %45, label %46, label %53, !dbg !13
126
127; <label>:46 ; preds = %43
128 %47 = add i64 %15, 0, !dbg !13
129 %48 = inttoptr i64 %47 to i64*, !dbg !13
130 store i64 -723401728380766731, i64* %48, !dbg !13
131 %49 = add i64 %6, 56, !dbg !13
132 %50 = inttoptr i64 %49 to i64*, !dbg !13
David Blaikiea79ac142015-02-27 21:17:42 +0000133 %51 = load i64, i64* %50, !dbg !13
Alexey Samsonov8000e272014-06-09 21:53:47 +0000134 %52 = inttoptr i64 %51 to i8*, !dbg !13
135 store i8 0, i8* %52, !dbg !13
136 br label %56, !dbg !13
137
138; <label>:53 ; preds = %43
139 %54 = add i64 %15, 0, !dbg !13
140 %55 = inttoptr i64 %54 to i64*, !dbg !13
141 store i64 0, i64* %55, !dbg !13
142 br label %56, !dbg !13
143
144; <label>:56 ; preds = %53, %46
145 ret i32 %add, !dbg !13
146}
147
148; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000149declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
Alexey Samsonov8000e272014-06-09 21:53:47 +0000150
151define internal void @asan.module_ctor() {
152 call void @__asan_init_v3()
153 ret void
154}
155
156declare void @__asan_init_v3()
157
158declare void @__asan_report_load4(i64)
159
160declare void @__asan_report_store4(i64)
161
162declare i64 @__asan_stack_malloc_0(i64, i64)
163
164attributes #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" }
165attributes #1 = { nounwind readnone }
166
167!llvm.dbg.cu = !{!0}
168!llvm.module.flags = !{!9, !10}
169!llvm.ident = !{!11}
170
Adrian Prantl75819ae2016-04-15 15:57:41 +0000171!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000172!1 = !DIFile(filename: "test.cc", directory: "/llvm_cmake_gcc")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000173!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +0000174!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, variables: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000175!5 = !DIFile(filename: "test.cc", directory: "/llvm_cmake_gcc")
176!6 = !DISubroutineType(types: !7)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000177!7 = !{!8, !8}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000178!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000179!9 = !{i32 2, !"Dwarf Version", i32 4}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000180!10 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000181!11 = !{!"clang version 3.5.0 (209308)"}
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000182!12 = !DILocalVariable(name: "y", line: 1, arg: 1, scope: !4, file: !5, type: !8)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000183!13 = !DILocation(line: 2, scope: !4)
184!14 = !DIExpression(DW_OP_deref)