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()
28 ; CHECK-NEXT: call void asm sideeffect
29 ; CHECK-NEXT: unreachable
32 ; Check that we store the shadow for the retval.
33 define i32 @ReturnInt() nounwind uwtable readnone {
38 ; CHECK: define i32 @ReturnInt()
39 ; CHECK: store i32 0,{{.*}}__msan_retval_tls
42 ; Check that we get the shadow for the retval.
43 define void @CopyRetVal(i32* nocapture %a) nounwind uwtable {
45 %call = tail call i32 @ReturnInt() nounwind
46 store i32 %call, i32* %a, align 4
50 ; CHECK: define void @CopyRetVal
51 ; CHECK: load{{.*}}__msan_retval_tls
57 ; Check that we generate PHIs for shadow.
58 define void @FuncWithPhi(i32* nocapture %a, i32* %b, i32* nocapture %c) nounwind uwtable {
60 %tobool = icmp eq i32* %b, null
61 br i1 %tobool, label %if.else, label %if.then
63 if.then: ; preds = %entry
64 %0 = load i32* %b, align 4
67 if.else: ; preds = %entry
68 %1 = load i32* %c, align 4
71 if.end: ; preds = %if.else, %if.then
72 %t.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
73 store i32 %t.0, i32* %a, align 4
77 ; CHECK: define void @FuncWithPhi
84 ; Compute shadow for "x << 10"
85 define void @ShlConst(i32* nocapture %x) nounwind uwtable {
87 %0 = load i32* %x, align 4
89 store i32 %1, i32* %x, align 4
93 ; CHECK: define void @ShlConst
102 ; Compute shadow for "10 << x": it should have 'sext i1'.
103 define void @ShlNonConst(i32* nocapture %x) nounwind uwtable {
105 %0 = load i32* %x, align 4
107 store i32 %1, i32* %x, align 4
111 ; CHECK: define void @ShlNonConst
120 define void @SExt(i32* nocapture %a, i16* nocapture %b) nounwind uwtable {
122 %0 = load i16* %b, align 2
123 %1 = sext i16 %0 to i32
124 store i32 %1, i32* %a, align 4
128 ; CHECK: define void @SExt
139 define void @MemSet(i8* nocapture %x) nounwind uwtable {
141 call void @llvm.memset.p0i8.i64(i8* %x, i8 42, i64 10, i32 1, i1 false)
145 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
147 ; CHECK: define void @MemSet
148 ; CHECK: call i8* @__msan_memset
153 define void @MemCpy(i8* nocapture %x, i8* nocapture %y) nounwind uwtable {
155 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
159 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
161 ; CHECK: define void @MemCpy
162 ; CHECK: call i8* @__msan_memcpy
166 ; memmove is lowered to a call
167 define void @MemMove(i8* nocapture %x, i8* nocapture %y) nounwind uwtable {
169 call void @llvm.memmove.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
173 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
175 ; CHECK: define void @MemMove
176 ; CHECK: call i8* @__msan_memmove
180 ; Check that we propagate shadow for "select"
182 define i32 @Select(i32 %a, i32 %b, i32 %c) nounwind uwtable readnone {
184 %tobool = icmp ne i32 %c, 0
185 %cond = select i1 %tobool, i32 %a, i32 %b
189 ; CHECK: define i32 @Select
195 define i8* @IntToPtr(i64 %x) nounwind uwtable readnone {
197 %0 = inttoptr i64 %x to i8*
201 ; CHECK: define i8* @IntToPtr
202 ; CHECK: load i64*{{.*}}__msan_param_tls
203 ; CHECK-NEXT: inttoptr
204 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
208 define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone {
210 %0 = inttoptr i16 %x to i8*
214 ; CHECK: define i8* @IntToPtr_ZExt
216 ; CHECK-NEXT: inttoptr
220 ; Check that we insert exactly one check on udiv
221 ; (2nd arg shadow is checked, 1st arg shadow is propagated)
223 define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone {
225 %div = udiv i32 %a, %b
229 ; CHECK: define i32 @Div