2016-07-23 06:04:38 +08:00
|
|
|
; Test handling of llvm.lifetime intrinsics.
|
2016-09-16 09:38:46 +08:00
|
|
|
; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT
|
|
|
|
; RUN: opt < %s -asan -asan-module -asan-use-after-scope -asan-use-after-return=0 -asan-instrument-dynamic-allocas=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-NO-DYNAMIC
|
2012-12-04 09:34:23 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind
|
|
|
|
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) nounwind
|
2012-12-04 09:34:23 +08:00
|
|
|
|
2013-02-26 14:58:09 +08:00
|
|
|
define void @lifetime_no_size() sanitize_address {
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK-LABEL: define void @lifetime_no_size()
|
2012-12-04 09:34:23 +08:00
|
|
|
entry:
|
|
|
|
%i = alloca i32, align 4
|
|
|
|
%i.ptr = bitcast i32* %i to i8*
|
2016-08-30 03:28:34 +08:00
|
|
|
|
|
|
|
; Poison memory in prologue: F1F1F1F104F3F3F3
|
|
|
|
; CHECK: store i64 -868083100587789839, i64* %{{[0-9]+}}
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; Check that lifetime with no size are ignored.
|
|
|
|
; CHECK-NOT: store
|
|
|
|
; CHECK: call void @llvm.lifetime.start
|
|
|
|
|
2015-02-27 11:12:36 +08:00
|
|
|
store volatile i8 0, i8* %i.ptr
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store volatile
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; Check that lifetime with no size are ignored.
|
|
|
|
; CHECK-NOT: store
|
|
|
|
; CHECK: call void @llvm.lifetime.end
|
2012-12-04 09:34:23 +08:00
|
|
|
|
2016-08-30 03:28:34 +08:00
|
|
|
; Unpoison stack frame on exit.
|
|
|
|
; CHECK: store i64 0, i64* %{{[0-9]+}}
|
|
|
|
; CHECK: ret void
|
2012-12-04 09:34:23 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Generic case of lifetime analysis.
|
2013-02-26 14:58:09 +08:00
|
|
|
define void @lifetime() sanitize_address {
|
2013-11-18 22:53:55 +08:00
|
|
|
; CHECK-LABEL: define void @lifetime()
|
2012-12-04 09:34:23 +08:00
|
|
|
|
|
|
|
; Regular variable lifetime intrinsics.
|
|
|
|
%i = alloca i32, align 4
|
|
|
|
%i.ptr = bitcast i32* %i to i8*
|
2016-08-30 03:28:34 +08:00
|
|
|
|
|
|
|
; Poison memory in prologue: F1F1F1F1F8F3F3F3
|
|
|
|
; CHECK: store i64 -868082052615769615, i64* %{{[0-9]+}}
|
|
|
|
|
|
|
|
; Memory is unpoisoned at llvm.lifetime.start
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 3, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 4, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: llvm.lifetime.start
|
|
|
|
|
2015-02-27 11:12:36 +08:00
|
|
|
store volatile i8 0, i8* %i.ptr
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store volatile
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 4, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 -8, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.end
|
|
|
|
|
2012-12-04 09:34:23 +08:00
|
|
|
; Memory is poisoned at every call to llvm.lifetime.end
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 2, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 -8, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.end
|
2012-12-04 09:34:23 +08:00
|
|
|
|
|
|
|
; Lifetime intrinsics for array.
|
|
|
|
%arr = alloca [10 x i32], align 16
|
|
|
|
%arr.ptr = bitcast [10 x i32]* %arr to i8*
|
2016-08-30 03:28:34 +08:00
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 40, i8* %arr.ptr)
|
2016-09-16 09:38:46 +08:00
|
|
|
; CHECK-DEFAULT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
|
2016-06-10 07:31:59 +08:00
|
|
|
; CHECK-NO-DYNAMIC-NOT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
|
2016-08-30 03:28:34 +08:00
|
|
|
|
|
|
|
store volatile i8 0, i8* %arr.ptr
|
|
|
|
; CHECK: store volatile
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 40, i8* %arr.ptr)
|
2016-09-16 09:38:46 +08:00
|
|
|
; CHECK-DEFAULT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
|
2016-06-10 07:31:59 +08:00
|
|
|
; CHECK-NO-DYNAMIC-NOT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
|
2012-12-04 09:34:23 +08:00
|
|
|
|
|
|
|
; One more lifetime start/end for the same variable %i.
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 2, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 4, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: llvm.lifetime.start
|
|
|
|
|
2015-02-27 11:12:36 +08:00
|
|
|
store volatile i8 0, i8* %i.ptr
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store volatile
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 4, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 -8, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: llvm.lifetime.end
|
2012-12-04 09:34:23 +08:00
|
|
|
|
|
|
|
; Memory is unpoisoned at function exit (only once).
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i64 0, i64* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: ret void
|
2012-12-04 09:34:23 +08:00
|
|
|
ret void
|
|
|
|
}
|
2012-12-27 16:50:58 +08:00
|
|
|
|
|
|
|
; Check that arguments of lifetime may come from phi nodes.
|
2013-02-26 14:58:09 +08:00
|
|
|
define void @phi_args(i1 %x) sanitize_address {
|
2013-11-18 22:53:55 +08:00
|
|
|
; CHECK-LABEL: define void @phi_args(i1 %x)
|
2012-12-27 16:50:58 +08:00
|
|
|
|
|
|
|
entry:
|
|
|
|
%i = alloca i64, align 4
|
|
|
|
%i.ptr = bitcast i64* %i to i8*
|
2016-08-30 03:28:34 +08:00
|
|
|
|
|
|
|
; Poison memory in prologue: F1F1F1F1F8F3F3F3
|
|
|
|
; CHECK: store i64 -868082052615769615, i64* %{{[0-9]+}}
|
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 8, i8* %i.ptr)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 0, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: llvm.lifetime.start
|
|
|
|
|
2015-02-27 11:12:36 +08:00
|
|
|
store volatile i8 0, i8* %i.ptr
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store volatile
|
|
|
|
|
2012-12-27 16:50:58 +08:00
|
|
|
br i1 %x, label %bb0, label %bb1
|
|
|
|
|
|
|
|
bb0:
|
|
|
|
%i.ptr2 = bitcast i64* %i to i8*
|
|
|
|
br label %bb1
|
|
|
|
|
|
|
|
bb1:
|
|
|
|
%i.phi = phi i8* [ %i.ptr, %entry ], [ %i.ptr2, %bb0 ]
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 8, i8* %i.phi)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8 -8, i8* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: llvm.lifetime.end
|
|
|
|
|
2012-12-27 16:50:58 +08:00
|
|
|
ret void
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i64 0, i64* %{{[0-9]+}}
|
|
|
|
; CHECK-NEXT: ret void
|
2012-12-27 16:50:58 +08:00
|
|
|
}
|
2016-06-10 07:31:59 +08:00
|
|
|
|
2016-07-22 08:56:17 +08:00
|
|
|
; Check that arguments of lifetime may come from getelementptr nodes.
|
|
|
|
define void @getelementptr_args() sanitize_address{
|
|
|
|
; CHECK-LABEL: define void @getelementptr_args
|
|
|
|
entry:
|
|
|
|
%x = alloca [1024 x i8], align 16
|
|
|
|
%d = alloca i8*, align 8
|
|
|
|
|
2016-08-30 03:28:34 +08:00
|
|
|
; F1F1F1F1
|
|
|
|
; CHECK: store i32 -235802127, i32* %{{[0-9]+}}
|
|
|
|
; F3F3F3F3F3F3F3F3
|
|
|
|
; CHECK: store i64 -868082074056920077, i64* %{{[0-9]+}}
|
|
|
|
; F3F3F3F3F3F3F3F3
|
|
|
|
; CHECK: store i64 -868082074056920077, i64* %{{[0-9]+}}
|
|
|
|
|
2016-07-22 08:56:17 +08:00
|
|
|
%0 = getelementptr inbounds [1024 x i8], [1024 x i8]* %x, i64 0, i64 0
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 1024, i8* %0)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 128)
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.start
|
2016-07-22 08:56:17 +08:00
|
|
|
|
|
|
|
store i8* %0, i8** %d, align 8
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: store i8
|
2016-07-22 08:56:17 +08:00
|
|
|
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 1024, i8* %0)
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: call void @__asan_set_shadow_f8(i64 %{{[0-9]+}}, i64 128)
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.end
|
2016-07-22 08:56:17 +08:00
|
|
|
|
|
|
|
ret void
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 148)
|
|
|
|
; CHECK-NEXT: ret void
|
2016-07-22 08:56:17 +08:00
|
|
|
}
|
|
|
|
|
2016-06-10 07:31:59 +08:00
|
|
|
define void @zero_sized(i64 %a) #0 {
|
|
|
|
; CHECK-LABEL: define void @zero_sized(i64 %a)
|
|
|
|
|
|
|
|
entry:
|
|
|
|
%a.addr = alloca i64, align 8
|
|
|
|
%b = alloca [0 x i8], align 1
|
|
|
|
store i64 %a, i64* %a.addr, align 8
|
2016-08-30 03:28:34 +08:00
|
|
|
|
2016-06-10 07:31:59 +08:00
|
|
|
%0 = bitcast [0 x i8]* %b to i8*
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.start.p0i8(i64 0, i8* %0) #2
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK: %{{[0-9]+}} = bitcast
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.start
|
|
|
|
|
2016-06-10 07:31:59 +08:00
|
|
|
%1 = bitcast [0 x i8]* %b to i8*
|
2017-04-11 04:18:21 +08:00
|
|
|
call void @llvm.lifetime.end.p0i8(i64 0, i8* %1) #2
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK-NEXT: %{{[0-9]+}} = bitcast
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.end
|
2016-06-10 07:31:59 +08:00
|
|
|
|
|
|
|
ret void
|
2016-08-30 03:28:34 +08:00
|
|
|
; CHECK-NEXT: ret void
|
2016-06-10 07:31:59 +08:00
|
|
|
}
|