1 ; RUN: opt < %s -msan -S | FileCheck %s
2 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"
4 ; Check the presence of __msan_init
5 ; CHECK: @llvm.global_ctors {{.*}} @__msan_init
7 ; load followed by cmp: check that we load the shadow and call __msan_warning.
8 define void @LoadAndCmp(i32* nocapture %a) nounwind uwtable {
10 %0 = load i32* %a, align 4
11 %tobool = icmp eq i32 %0, 0
12 br i1 %tobool, label %if.end, label %if.then
14 if.then: ; preds = %entry
15 tail call void (...)* @foo() nounwind
18 if.end: ; preds = %entry, %if.then
22 declare void @foo(...)
24 ; CHECK: define void @LoadAndCmp
27 ; CHECK: call void @__msan_warning_noreturn()
30 ; Check that we store the shadow for the retval.
31 define i32 @ReturnInt() nounwind uwtable readnone {
36 ; CHECK: define i32 @ReturnInt()
37 ; CHECK: store i32 0,{{.*}}__msan_retval_tls
40 ; Check that we get the shadow for the retval.
41 define void @CopyRetVal(i32* nocapture %a) nounwind uwtable {
43 %call = tail call i32 @ReturnInt() nounwind
44 store i32 %call, i32* %a, align 4
48 ; CHECK: define void @CopyRetVal
49 ; CHECK: load{{.*}}__msan_retval_tls
55 ; Check that we generate PHIs for shadow.
56 define void @FuncWithPhi(i32* nocapture %a, i32* %b, i32* nocapture %c) nounwind uwtable {
58 %tobool = icmp eq i32* %b, null
59 br i1 %tobool, label %if.else, label %if.then
61 if.then: ; preds = %entry
62 %0 = load i32* %b, align 4
65 if.else: ; preds = %entry
66 %1 = load i32* %c, align 4
69 if.end: ; preds = %if.else, %if.then
70 %t.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
71 store i32 %t.0, i32* %a, align 4
75 ; CHECK: define void @FuncWithPhi
82 ; Compute shadow for "x << 10"
83 define void @ShlConst(i32* nocapture %x) nounwind uwtable {
85 %0 = load i32* %x, align 4
87 store i32 %1, i32* %x, align 4
91 ; CHECK: define void @ShlConst
100 ; Compute shadow for "10 << x": it should have 'sext i1'.
101 define void @ShlNonConst(i32* nocapture %x) nounwind uwtable {
103 %0 = load i32* %x, align 4
105 store i32 %1, i32* %x, align 4
109 ; CHECK: define void @ShlNonConst
118 define void @SExt(i32* nocapture %a, i16* nocapture %b) nounwind uwtable {
120 %0 = load i16* %b, align 2
121 %1 = sext i16 %0 to i32
122 store i32 %1, i32* %a, align 4
126 ; CHECK: define void @SExt
137 define void @MemSet(i8* nocapture %x) nounwind uwtable {
139 call void @llvm.memset.p0i8.i64(i8* %x, i8 42, i64 10, i32 1, i1 false)
143 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
145 ; CHECK: define void @MemSet
146 ; CHECK: call i8* @__msan_memset
151 define void @MemCpy(i8* nocapture %x, i8* nocapture %y) nounwind uwtable {
153 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
157 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
159 ; CHECK: define void @MemCpy
160 ; CHECK: call i8* @__msan_memcpy
164 ; memmove is lowered to a call
165 define void @MemMove(i8* nocapture %x, i8* nocapture %y) nounwind uwtable {
167 call void @llvm.memmove.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
171 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
173 ; CHECK: define void @MemMove
174 ; CHECK: call i8* @__msan_memmove
178 ; Check that we propagate shadow for "select"
180 define i32 @Select(i32 %a, i32 %b, i32 %c) nounwind uwtable readnone {
182 %tobool = icmp ne i32 %c, 0
183 %cond = select i1 %tobool, i32 %a, i32 %b
187 ; CHECK: define i32 @Select
193 define i8* @IntToPtr(i64 %x) nounwind uwtable readnone {
195 %0 = inttoptr i64 %x to i8*
199 ; CHECK: define i8* @IntToPtr
200 ; CHECK: load i64*{{.*}}__msan_param_tls
201 ; CHECK-NEXT: inttoptr
202 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
206 define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone {
208 %0 = inttoptr i16 %x to i8*
212 ; CHECK: define i8* @IntToPtr_ZExt
214 ; CHECK-NEXT: inttoptr
218 ; Check that we insert exactly one check on udiv
219 ; (2nd arg shadow is checked, 1st arg shadow is propagated)
221 define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone {
223 %div = udiv i32 %a, %b
227 ; CHECK: define i32 @Div