comparison test/Instrumentation/AddressSanitizer/lifetime.ll @ 0:95c75e76d11b

LLVM 3.4
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Thu, 12 Dec 2013 13:56:28 +0900
parents
children 54457678186b
comparison
equal deleted inserted replaced
-1:000000000000 0:95c75e76d11b
1 ; Test hanlding of llvm.lifetime intrinsics.
2 ; RUN: opt < %s -asan -asan-check-lifetime -S | FileCheck %s
3
4 target datalayout = "e-p:64:64:64-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-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
8 declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
9
10 define void @lifetime_no_size() sanitize_address {
11 entry:
12 %i = alloca i32, align 4
13 %i.ptr = bitcast i32* %i to i8*
14 call void @llvm.lifetime.start(i64 -1, i8* %i.ptr)
15 call void @llvm.lifetime.end(i64 -1, i8* %i.ptr)
16
17 ; Check that lifetime with no size are ignored.
18 ; CHECK-LABEL: define void @lifetime_no_size()
19 ; CHECK-NOT: @__asan_poison_stack_memory
20 ; CHECK-NOT: @__asan_unpoison_stack_memory
21 ; CHECK: ret void
22 ret void
23 }
24
25 ; Generic case of lifetime analysis.
26 define void @lifetime() sanitize_address {
27 ; CHECK-LABEL: define void @lifetime()
28
29 ; Regular variable lifetime intrinsics.
30 %i = alloca i32, align 4
31 %i.ptr = bitcast i32* %i to i8*
32 call void @llvm.lifetime.start(i64 3, i8* %i.ptr)
33 ; Memory is unpoisoned at llvm.lifetime.start
34 ; CHECK: %[[VAR:[^ ]*]] = ptrtoint i32* %{{[^ ]+}} to i64
35 ; CHECK-NEXT: call void @__asan_unpoison_stack_memory(i64 %[[VAR]], i64 3)
36 call void @llvm.lifetime.end(i64 4, i8* %i.ptr)
37 call void @llvm.lifetime.end(i64 2, i8* %i.ptr)
38 ; Memory is poisoned at every call to llvm.lifetime.end
39 ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 4)
40 ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 2)
41
42 ; Lifetime intrinsics for array.
43 %arr = alloca [10 x i32], align 16
44 %arr.ptr = bitcast [10 x i32]* %arr to i8*
45 call void @llvm.lifetime.start(i64 40, i8* %arr.ptr)
46 ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
47 call void @llvm.lifetime.end(i64 40, i8* %arr.ptr)
48 ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
49
50 ; One more lifetime start/end for the same variable %i.
51 call void @llvm.lifetime.start(i64 4, i8* %i.ptr)
52 ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 4)
53 call void @llvm.lifetime.end(i64 4, i8* %i.ptr)
54 ; CHECK: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 4)
55
56 ; Memory is unpoisoned at function exit (only once).
57 ; CHECK: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 {{.*}})
58 ; CHECK-NOT: @__asan_unpoison_stack_memory
59 ; CHECK: ret void
60 ret void
61 }
62
63 ; Check that arguments of lifetime may come from phi nodes.
64 define void @phi_args(i1 %x) sanitize_address {
65 ; CHECK-LABEL: define void @phi_args(i1 %x)
66
67 entry:
68 %i = alloca i64, align 4
69 %i.ptr = bitcast i64* %i to i8*
70 call void @llvm.lifetime.start(i64 8, i8* %i.ptr)
71 ; CHECK: __asan_unpoison_stack_memory
72 br i1 %x, label %bb0, label %bb1
73
74 bb0:
75 %i.ptr2 = bitcast i64* %i to i8*
76 br label %bb1
77
78 bb1:
79 %i.phi = phi i8* [ %i.ptr, %entry ], [ %i.ptr2, %bb0 ]
80 call void @llvm.lifetime.end(i64 8, i8* %i.phi)
81 ; CHECK: __asan_poison_stack_memory
82 ; CHECK: ret void
83 ret void
84 }