1 ; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck \
2 ; RUN: -allow-deprecated-dag-overlap %s
3 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck -allow-deprecated-dag-overlap %s
4 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \
5 ; RUN: -passes=msan 2>&1 | FileCheck -allow-deprecated-dag-overlap \
6 ; RUN: -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s
7 ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -allow-deprecated-dag-overlap -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s
9 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"
10 target triple = "x86_64-unknown-linux-gnu"
12 ; CHECK: @llvm.global_ctors {{.*}} { i32 0, void ()* @msan.module_ctor, i8* null }
14 ; Check the presence and the linkage type of __msan_track_origins and
15 ; other interface symbols.
16 ; CHECK-NOT: @__msan_track_origins
17 ; CHECK-ORIGINS: @__msan_track_origins = weak_odr constant i32 1
18 ; CHECK-NOT: @__msan_keep_going = weak_odr constant i32 0
19 ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [{{.*}}]
20 ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32
21 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [{{.*}}]
22 ; CHECK: @__msan_param_origin_tls = external thread_local(initialexec) global [{{.*}}]
23 ; CHECK: @__msan_va_arg_tls = external thread_local(initialexec) global [{{.*}}]
24 ; CHECK: @__msan_va_arg_overflow_size_tls = external thread_local(initialexec) global i64
25 ; CHECK: @__msan_origin_tls = external thread_local(initialexec) global i32
28 ; Check instrumentation of stores
30 define void @Store(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
32 store i32 %x, i32* %p, align 4
37 ; CHECK: load {{.*}} @__msan_param_tls
38 ; CHECK-ORIGINS: load {{.*}} @__msan_param_origin_tls
41 ; CHECK-ORIGINS: br i1
42 ; CHECK-ORIGINS: {{^[0-9]+}}:
43 ; CHECK-ORIGINS: store
44 ; CHECK-ORIGINS: br label
45 ; CHECK-ORIGINS: {{^[0-9]+}}:
50 ; Check instrumentation of aligned stores
51 ; Shadow store has the same alignment as the original store; origin store
52 ; does not specify explicit alignment.
54 define void @AlignedStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
56 store i32 %x, i32* %p, align 32
60 ; CHECK-LABEL: @AlignedStore
61 ; CHECK: load {{.*}} @__msan_param_tls
62 ; CHECK-ORIGINS: load {{.*}} @__msan_param_origin_tls
63 ; CHECK: store {{.*}} align 32
65 ; CHECK-ORIGINS: br i1
66 ; CHECK-ORIGINS: {{^[0-9]+}}:
67 ; CHECK-ORIGINS: store {{.*}} align 32
68 ; CHECK-ORIGINS: br label
69 ; CHECK-ORIGINS: {{^[0-9]+}}:
70 ; CHECK: store {{.*}} align 32
74 ; load followed by cmp: check that we load the shadow and call __msan_warning.
75 define void @LoadAndCmp(i32* nocapture %a) nounwind uwtable sanitize_memory {
77 %0 = load i32, i32* %a, align 4
78 %tobool = icmp eq i32 %0, 0
79 br i1 %tobool, label %if.end, label %if.then
81 if.then: ; preds = %entry
82 tail call void (...) @foo() nounwind
85 if.end: ; preds = %entry, %if.then
89 declare void @foo(...)
91 ; CHECK-LABEL: @LoadAndCmp
94 ; CHECK: call void @__msan_warning_noreturn()
95 ; CHECK-NEXT: call void asm sideeffect
96 ; CHECK-NEXT: unreachable
99 ; Check that we store the shadow for the retval.
100 define i32 @ReturnInt() nounwind uwtable readnone sanitize_memory {
105 ; CHECK-LABEL: @ReturnInt
106 ; CHECK: store i32 0,{{.*}}__msan_retval_tls
109 ; Check that we get the shadow for the retval.
110 define void @CopyRetVal(i32* nocapture %a) nounwind uwtable sanitize_memory {
112 %call = tail call i32 @ReturnInt() nounwind
113 store i32 %call, i32* %a, align 4
117 ; CHECK-LABEL: @CopyRetVal
118 ; CHECK: load{{.*}}__msan_retval_tls
124 ; Check that we generate PHIs for shadow.
125 define void @FuncWithPhi(i32* nocapture %a, i32* %b, i32* nocapture %c) nounwind uwtable sanitize_memory {
127 %tobool = icmp eq i32* %b, null
128 br i1 %tobool, label %if.else, label %if.then
130 if.then: ; preds = %entry
131 %0 = load i32, i32* %b, align 4
134 if.else: ; preds = %entry
135 %1 = load i32, i32* %c, align 4
138 if.end: ; preds = %if.else, %if.then
139 %t.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
140 store i32 %t.0, i32* %a, align 4
144 ; CHECK-LABEL: @FuncWithPhi
151 ; Compute shadow for "x << 10"
152 define void @ShlConst(i32* nocapture %x) nounwind uwtable sanitize_memory {
154 %0 = load i32, i32* %x, align 4
156 store i32 %1, i32* %x, align 4
160 ; CHECK-LABEL: @ShlConst
169 ; Compute shadow for "10 << x": it should have 'sext i1'.
170 define void @ShlNonConst(i32* nocapture %x) nounwind uwtable sanitize_memory {
172 %0 = load i32, i32* %x, align 4
174 store i32 %1, i32* %x, align 4
178 ; CHECK-LABEL: @ShlNonConst
187 define void @SExt(i32* nocapture %a, i16* nocapture %b) nounwind uwtable sanitize_memory {
189 %0 = load i16, i16* %b, align 2
190 %1 = sext i16 %0 to i32
191 store i32 %1, i32* %a, align 4
206 define void @MemSet(i8* nocapture %x) nounwind uwtable sanitize_memory {
208 call void @llvm.memset.p0i8.i64(i8* %x, i8 42, i64 10, i1 false)
212 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
214 ; CHECK-LABEL: @MemSet
215 ; CHECK: call i8* @__msan_memset
220 define void @MemCpy(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory {
222 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i1 false)
226 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
228 ; CHECK-LABEL: @MemCpy
229 ; CHECK: call i8* @__msan_memcpy
233 ; memmove is lowered to a call
234 define void @MemMove(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory {
236 call void @llvm.memmove.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i1 false)
240 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
242 ; CHECK-LABEL: @MemMove
243 ; CHECK: call i8* @__msan_memmove
247 ;; Placeholder tests that will fail once element atomic @llvm.mem[cpy|move|set] instrinsics have
248 ;; been added to the MemIntrinsic class hierarchy. These will act as a reminder to
249 ;; verify that MSAN handles these intrinsics properly once they have been
250 ;; added to that class hierarchy.
251 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture writeonly, i8, i64, i32) nounwind
252 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32) nounwind
253 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32) nounwind
255 define void @atomic_memcpy(i8* nocapture %x, i8* nocapture %y) nounwind {
256 ; CHECK-LABEL: atomic_memcpy
257 ; CHECK-NEXT: call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1)
258 ; CHECK-NEXT: ret void
259 call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1)
263 define void @atomic_memmove(i8* nocapture %x, i8* nocapture %y) nounwind {
264 ; CHECK-LABEL: atomic_memmove
265 ; CHECK-NEXT: call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1)
266 ; CHECK-NEXT: ret void
267 call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1)
271 define void @atomic_memset(i8* nocapture %x) nounwind {
272 ; CHECK-LABEL: atomic_memset
273 ; CHECK-NEXT: call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %x, i8 88, i64 16, i32 1)
274 ; CHECK-NEXT: ret void
275 call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %x, i8 88, i64 16, i32 1)
282 ; Check that we propagate shadow for "select"
284 define i32 @Select(i32 %a, i32 %b, i1 %c) nounwind uwtable readnone sanitize_memory {
286 %cond = select i1 %c, i32 %a, i32 %b
290 ; CHECK-LABEL: @Select
295 ; CHECK-DAG: select i1
296 ; CHECK-ORIGINS-DAG: select
297 ; CHECK-ORIGINS-DAG: select
298 ; CHECK-DAG: select i1
299 ; CHECK: store i32{{.*}}@__msan_retval_tls
300 ; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls
304 ; Check that we propagate origin for "select" with vector condition.
305 ; Select condition is flattened to i1, which is then used to select one of the
308 define <8 x i16> @SelectVector(<8 x i16> %a, <8 x i16> %b, <8 x i1> %c) nounwind uwtable readnone sanitize_memory {
310 %cond = select <8 x i1> %c, <8 x i16> %a, <8 x i16> %b
314 ; CHECK-LABEL: @SelectVector
315 ; CHECK: select <8 x i1>
316 ; CHECK-DAG: or <8 x i16>
317 ; CHECK-DAG: xor <8 x i16>
318 ; CHECK: or <8 x i16>
319 ; CHECK-DAG: select <8 x i1>
320 ; CHECK-ORIGINS-DAG: select
321 ; CHECK-ORIGINS-DAG: select
322 ; CHECK-DAG: select <8 x i1>
323 ; CHECK: store <8 x i16>{{.*}}@__msan_retval_tls
324 ; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls
325 ; CHECK: ret <8 x i16>
328 ; Check that we propagate origin for "select" with scalar condition and vector
329 ; arguments. Select condition shadow is sign-extended to the vector type and
330 ; mixed into the result shadow.
332 define <8 x i16> @SelectVector2(<8 x i16> %a, <8 x i16> %b, i1 %c) nounwind uwtable readnone sanitize_memory {
334 %cond = select i1 %c, <8 x i16> %a, <8 x i16> %b
338 ; CHECK-LABEL: @SelectVector2
340 ; CHECK-DAG: or <8 x i16>
341 ; CHECK-DAG: xor <8 x i16>
342 ; CHECK: or <8 x i16>
343 ; CHECK-DAG: select i1
344 ; CHECK-ORIGINS-DAG: select i1
345 ; CHECK-ORIGINS-DAG: select i1
346 ; CHECK-DAG: select i1
347 ; CHECK: ret <8 x i16>
350 define { i64, i64 } @SelectStruct(i1 zeroext %x, { i64, i64 } %a, { i64, i64 } %b) readnone sanitize_memory {
352 %c = select i1 %x, { i64, i64 } %a, { i64, i64 } %b
356 ; CHECK-LABEL: @SelectStruct
357 ; CHECK: select i1 {{.*}}, { i64, i64 }
358 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 }
359 ; CHECK-ORIGINS: select i1
360 ; CHECK-ORIGINS: select i1
361 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 }
362 ; CHECK: ret { i64, i64 }
365 define { i64*, double } @SelectStruct2(i1 zeroext %x, { i64*, double } %a, { i64*, double } %b) readnone sanitize_memory {
367 %c = select i1 %x, { i64*, double } %a, { i64*, double } %b
368 ret { i64*, double } %c
371 ; CHECK-LABEL: @SelectStruct2
372 ; CHECK: select i1 {{.*}}, { i64, i64 }
373 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 }
374 ; CHECK-ORIGINS: select i1
375 ; CHECK-ORIGINS: select i1
376 ; CHECK-NEXT: select i1 {{.*}}, { i64*, double }
377 ; CHECK: ret { i64*, double }
380 define i8* @IntToPtr(i64 %x) nounwind uwtable readnone sanitize_memory {
382 %0 = inttoptr i64 %x to i8*
386 ; CHECK-LABEL: @IntToPtr
387 ; CHECK: load i64, i64*{{.*}}__msan_param_tls
388 ; CHECK-ORIGINS-NEXT: load i32, i32*{{.*}}__msan_param_origin_tls
389 ; CHECK-NEXT: inttoptr
390 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
394 define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone sanitize_memory {
396 %0 = inttoptr i16 %x to i8*
400 ; CHECK-LABEL: @IntToPtr_ZExt
401 ; CHECK: load i16, i16*{{.*}}__msan_param_tls
403 ; CHECK-NEXT: inttoptr
404 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
408 ; Check that we insert exactly one check on udiv
409 ; (2nd arg shadow is checked, 1st arg shadow is propagated)
411 define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone sanitize_memory {
413 %div = udiv i32 %a, %b
419 ; CHECK: call void @__msan_warning
425 ; Check that fdiv, unlike udiv, simply propagates shadow.
427 define float @FDiv(float %a, float %b) nounwind uwtable readnone sanitize_memory {
429 %c = fdiv float %a, %b
434 ; CHECK: %[[SA:.*]] = load i32,{{.*}}@__msan_param_tls
435 ; CHECK: %[[SB:.*]] = load i32,{{.*}}@__msan_param_tls
436 ; CHECK: %[[SC:.*]] = or i32 %[[SB]], %[[SA]]
437 ; CHECK: = fdiv float
438 ; CHECK: store i32 %[[SC]], i32* {{.*}}@__msan_retval_tls
441 ; Check that fneg simply propagates shadow.
443 define float @FNeg(float %a) nounwind uwtable readnone sanitize_memory {
450 ; CHECK: %[[SA:.*]] = load i32,{{.*}}@__msan_param_tls
451 ; CHECK-ORIGINS: %[[SB:.*]] = load i32,{{.*}}@__msan_param_origin_tls
452 ; CHECK: = fneg float
453 ; CHECK: store i32 %[[SA]], i32* {{.*}}@__msan_retval_tls
454 ; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls
457 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
459 define zeroext i1 @ICmpSLTZero(i32 %x) nounwind uwtable readnone sanitize_memory {
460 %1 = icmp slt i32 %x, 0
464 ; CHECK-LABEL: @ICmpSLTZero
466 ; CHECK-NOT: call void @__msan_warning
468 ; CHECK-NOT: call void @__msan_warning
471 define zeroext i1 @ICmpSGEZero(i32 %x) nounwind uwtable readnone sanitize_memory {
472 %1 = icmp sge i32 %x, 0
476 ; CHECK-LABEL: @ICmpSGEZero
478 ; CHECK-NOT: call void @__msan_warning
480 ; CHECK-NOT: call void @__msan_warning
483 define zeroext i1 @ICmpSGTZero(i32 %x) nounwind uwtable readnone sanitize_memory {
484 %1 = icmp sgt i32 0, %x
488 ; CHECK-LABEL: @ICmpSGTZero
490 ; CHECK-NOT: call void @__msan_warning
492 ; CHECK-NOT: call void @__msan_warning
495 define zeroext i1 @ICmpSLEZero(i32 %x) nounwind uwtable readnone sanitize_memory {
496 %1 = icmp sle i32 0, %x
500 ; CHECK-LABEL: @ICmpSLEZero
502 ; CHECK-NOT: call void @__msan_warning
504 ; CHECK-NOT: call void @__msan_warning
508 ; Check that we propagate shadow for x<=-1, x>-1, etc (i.e. sign bit tests)
510 define zeroext i1 @ICmpSLTAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory {
511 %1 = icmp slt i32 -1, %x
515 ; CHECK-LABEL: @ICmpSLTAllOnes
517 ; CHECK-NOT: call void @__msan_warning
519 ; CHECK-NOT: call void @__msan_warning
522 define zeroext i1 @ICmpSGEAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory {
523 %1 = icmp sge i32 -1, %x
527 ; CHECK-LABEL: @ICmpSGEAllOnes
529 ; CHECK-NOT: call void @__msan_warning
531 ; CHECK-NOT: call void @__msan_warning
534 define zeroext i1 @ICmpSGTAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory {
535 %1 = icmp sgt i32 %x, -1
539 ; CHECK-LABEL: @ICmpSGTAllOnes
541 ; CHECK-NOT: call void @__msan_warning
543 ; CHECK-NOT: call void @__msan_warning
546 define zeroext i1 @ICmpSLEAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory {
547 %1 = icmp sle i32 %x, -1
551 ; CHECK-LABEL: @ICmpSLEAllOnes
553 ; CHECK-NOT: call void @__msan_warning
555 ; CHECK-NOT: call void @__msan_warning
559 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
560 ; of the vector arguments.
562 define <2 x i1> @ICmpSLT_vector_Zero(<2 x i32*> %x) nounwind uwtable readnone sanitize_memory {
563 %1 = icmp slt <2 x i32*> %x, zeroinitializer
567 ; CHECK-LABEL: @ICmpSLT_vector_Zero
568 ; CHECK: icmp slt <2 x i64>
569 ; CHECK-NOT: call void @__msan_warning
570 ; CHECK: icmp slt <2 x i32*>
571 ; CHECK-NOT: call void @__msan_warning
572 ; CHECK: ret <2 x i1>
574 ; Check that we propagate shadow for x<=-1, x>0, etc (i.e. sign bit tests)
575 ; of the vector arguments.
577 define <2 x i1> @ICmpSLT_vector_AllOnes(<2 x i32> %x) nounwind uwtable readnone sanitize_memory {
578 %1 = icmp slt <2 x i32> <i32 -1, i32 -1>, %x
582 ; CHECK-LABEL: @ICmpSLT_vector_AllOnes
583 ; CHECK: icmp slt <2 x i32>
584 ; CHECK-NOT: call void @__msan_warning
585 ; CHECK: icmp slt <2 x i32>
586 ; CHECK-NOT: call void @__msan_warning
587 ; CHECK: ret <2 x i1>
590 ; Check that we propagate shadow for unsigned relational comparisons with
593 define zeroext i1 @ICmpUGTConst(i32 %x) nounwind uwtable readnone sanitize_memory {
595 %cmp = icmp ugt i32 %x, 7
599 ; CHECK-LABEL: @ICmpUGTConst
600 ; CHECK: icmp ugt i32
601 ; CHECK-NOT: call void @__msan_warning
602 ; CHECK: icmp ugt i32
603 ; CHECK-NOT: call void @__msan_warning
604 ; CHECK: icmp ugt i32
605 ; CHECK-NOT: call void @__msan_warning
609 ; Check that loads of shadow have the same alignment as the original loads.
610 ; Check that loads of origin have the alignment of max(4, original alignment).
612 define i32 @ShadowLoadAlignmentLarge() nounwind uwtable sanitize_memory {
613 %y = alloca i32, align 64
614 %1 = load volatile i32, i32* %y, align 64
618 ; CHECK-LABEL: @ShadowLoadAlignmentLarge
619 ; CHECK: load volatile i32, i32* {{.*}} align 64
620 ; CHECK: load i32, i32* {{.*}} align 64
623 define i32 @ShadowLoadAlignmentSmall() nounwind uwtable sanitize_memory {
624 %y = alloca i32, align 2
625 %1 = load volatile i32, i32* %y, align 2
629 ; CHECK-LABEL: @ShadowLoadAlignmentSmall
630 ; CHECK: load volatile i32, i32* {{.*}} align 2
631 ; CHECK: load i32, i32* {{.*}} align 2
632 ; CHECK-ORIGINS: load i32, i32* {{.*}} align 4
636 ; Test vector manipulation instructions.
637 ; Check that the same bit manipulation is applied to the shadow values.
638 ; Check that there is a zero test of the shadow of %idx argument, where present.
640 define i32 @ExtractElement(<4 x i32> %vec, i32 %idx) sanitize_memory {
641 %x = extractelement <4 x i32> %vec, i32 %idx
645 ; CHECK-LABEL: @ExtractElement
646 ; CHECK: extractelement
647 ; CHECK: call void @__msan_warning
648 ; CHECK: extractelement
651 define <4 x i32> @InsertElement(<4 x i32> %vec, i32 %idx, i32 %x) sanitize_memory {
652 %vec1 = insertelement <4 x i32> %vec, i32 %x, i32 %idx
656 ; CHECK-LABEL: @InsertElement
657 ; CHECK: insertelement
658 ; CHECK: call void @__msan_warning
659 ; CHECK: insertelement
660 ; CHECK: ret <4 x i32>
662 define <4 x i32> @ShuffleVector(<4 x i32> %vec, <4 x i32> %vec1) sanitize_memory {
663 %vec2 = shufflevector <4 x i32> %vec, <4 x i32> %vec1,
664 <4 x i32> <i32 0, i32 4, i32 1, i32 5>
668 ; CHECK-LABEL: @ShuffleVector
669 ; CHECK: shufflevector
670 ; CHECK-NOT: call void @__msan_warning
671 ; CHECK: shufflevector
672 ; CHECK: ret <4 x i32>
675 ; Test bswap intrinsic instrumentation
676 define i32 @BSwap(i32 %x) nounwind uwtable readnone sanitize_memory {
677 %y = tail call i32 @llvm.bswap.i32(i32 %x)
681 declare i32 @llvm.bswap.i32(i32) nounwind readnone
683 ; CHECK-LABEL: @BSwap
684 ; CHECK-NOT: call void @__msan_warning
685 ; CHECK: @llvm.bswap.i32
686 ; CHECK-NOT: call void @__msan_warning
687 ; CHECK: @llvm.bswap.i32
688 ; CHECK-NOT: call void @__msan_warning
691 ; Test handling of vectors of pointers.
692 ; Check that shadow of such vector is a vector of integers.
694 define <8 x i8*> @VectorOfPointers(<8 x i8*>* %p) nounwind uwtable sanitize_memory {
695 %x = load <8 x i8*>, <8 x i8*>* %p
699 ; CHECK-LABEL: @VectorOfPointers
700 ; CHECK: load <8 x i8*>, <8 x i8*>*
701 ; CHECK: load <8 x i64>, <8 x i64>*
702 ; CHECK: store <8 x i64> {{.*}} @__msan_retval_tls
703 ; CHECK: ret <8 x i8*>
705 ; Test handling of va_copy.
707 declare void @llvm.va_copy(i8*, i8*) nounwind
709 define void @VACopy(i8* %p1, i8* %p2) nounwind uwtable sanitize_memory {
710 call void @llvm.va_copy(i8* %p1, i8* %p2) nounwind
714 ; CHECK-LABEL: @VACopy
715 ; CHECK: call void @llvm.memset.p0i8.i64({{.*}}, i8 0, i64 24, i1 false)
719 ; Test that va_start instrumentation does not use va_arg_tls*.
720 ; It should work with a local stack copy instead.
722 %struct.__va_list_tag = type { i32, i32, i8*, i8* }
723 declare void @llvm.va_start(i8*) nounwind
725 ; Function Attrs: nounwind uwtable
726 define void @VAStart(i32 %x, ...) sanitize_memory {
728 %x.addr = alloca i32, align 4
729 %va = alloca [1 x %struct.__va_list_tag], align 16
730 store i32 %x, i32* %x.addr, align 4
731 %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %va, i32 0, i32 0
732 %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8*
733 call void @llvm.va_start(i8* %arraydecay1)
737 ; CHECK-LABEL: @VAStart
738 ; CHECK: call void @llvm.va_start
739 ; CHECK-NOT: @__msan_va_arg_tls
740 ; CHECK-NOT: @__msan_va_arg_overflow_size_tls
744 ; Test handling of volatile stores.
745 ; Check that MemorySanitizer does not add a check of the value being stored.
747 define void @VolatileStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
749 store volatile i32 %x, i32* %p, align 4
753 ; CHECK-LABEL: @VolatileStore
754 ; CHECK-NOT: @__msan_warning
758 ; Test that checks are omitted and returned value is always initialized if
759 ; sanitize_memory attribute is missing.
761 define i32 @NoSanitizeMemory(i32 %x) uwtable {
763 %tobool = icmp eq i32 %x, 0
764 br i1 %tobool, label %if.end, label %if.then
766 if.then: ; preds = %entry
767 tail call void @bar()
770 if.end: ; preds = %entry, %if.then
776 ; CHECK-LABEL: @NoSanitizeMemory
777 ; CHECK-NOT: @__msan_warning
778 ; CHECK: store i32 0, {{.*}} @__msan_retval_tls
779 ; CHECK-NOT: @__msan_warning
783 ; Test that stack allocations are unpoisoned in functions missing
784 ; sanitize_memory attribute
786 define i32 @NoSanitizeMemoryAlloca() {
788 %p = alloca i32, align 4
789 %x = call i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
793 declare i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
795 ; CHECK-LABEL: @NoSanitizeMemoryAlloca
796 ; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 {{.*}}, i8 0, i64 4, i1 false)
797 ; CHECK: call i32 @NoSanitizeMemoryAllocaHelper(i32*
801 ; Test that undef is unpoisoned in functions missing
802 ; sanitize_memory attribute
804 define i32 @NoSanitizeMemoryUndef() {
806 %x = call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
810 declare i32 @NoSanitizeMemoryUndefHelper(i32 %x)
812 ; CHECK-LABEL: @NoSanitizeMemoryUndef
813 ; CHECK: store i32 0, i32* {{.*}} @__msan_param_tls
814 ; CHECK: call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
818 ; Test PHINode instrumentation in blacklisted functions
820 define i32 @NoSanitizeMemoryPHI(i32 %x) {
822 %tobool = icmp ne i32 %x, 0
823 br i1 %tobool, label %cond.true, label %cond.false
825 cond.true: ; preds = %entry
828 cond.false: ; preds = %entry
831 cond.end: ; preds = %cond.false, %cond.true
832 %cond = phi i32 [ undef, %cond.true ], [ undef, %cond.false ]
836 ; CHECK: [[A:%.*]] = phi i32 [ undef, %cond.true ], [ undef, %cond.false ]
837 ; CHECK: store i32 0, i32* bitcast {{.*}} @__msan_retval_tls
838 ; CHECK: ret i32 [[A]]
841 ; Test that there are no __msan_param_origin_tls stores when
842 ; argument shadow is a compile-time zero constant (which is always the case
843 ; in functions missing sanitize_memory attribute).
845 define i32 @NoSanitizeMemoryParamTLS(i32* nocapture readonly %x) {
847 %0 = load i32, i32* %x, align 4
848 %call = tail call i32 @NoSanitizeMemoryParamTLSHelper(i32 %0)
852 declare i32 @NoSanitizeMemoryParamTLSHelper(i32 %x)
854 ; CHECK-LABEL: define i32 @NoSanitizeMemoryParamTLS(
855 ; CHECK-NOT: __msan_param_origin_tls
859 ; Test argument shadow alignment
861 define <2 x i64> @ArgumentShadowAlignment(i64 %a, <2 x i64> %b) sanitize_memory {
866 ; CHECK-LABEL: @ArgumentShadowAlignment
867 ; CHECK: load <2 x i64>, <2 x i64>* {{.*}} @__msan_param_tls {{.*}}, align 8
868 ; CHECK: store <2 x i64> {{.*}} @__msan_retval_tls {{.*}}, align 8
869 ; CHECK: ret <2 x i64>
872 ; Test origin propagation for insertvalue
874 define { i64, i32 } @make_pair_64_32(i64 %x, i32 %y) sanitize_memory {
876 %a = insertvalue { i64, i32 } undef, i64 %x, 0
877 %b = insertvalue { i64, i32 } %a, i32 %y, 1
881 ; CHECK-ORIGINS: @make_pair_64_32
882 ; First element shadow
883 ; CHECK-ORIGINS: insertvalue { i64, i32 } { i64 -1, i32 -1 }, i64 {{.*}}, 0
884 ; First element origin
885 ; CHECK-ORIGINS: icmp ne i64
886 ; CHECK-ORIGINS: select i1
887 ; First element app value
888 ; CHECK-ORIGINS: insertvalue { i64, i32 } undef, i64 {{.*}}, 0
889 ; Second element shadow
890 ; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1
891 ; Second element origin
892 ; CHECK-ORIGINS: icmp ne i32
893 ; CHECK-ORIGINS: select i1
894 ; Second element app value
895 ; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1
896 ; CHECK-ORIGINS: ret { i64, i32 }
899 ; Test shadow propagation for aggregates passed through ellipsis.
901 %struct.StructByVal = type { i32, i32, i32, i32 }
903 declare void @VAArgStructFn(i32 %guard, ...)
905 define void @VAArgStruct(%struct.StructByVal* nocapture %s) sanitize_memory {
907 %agg.tmp2 = alloca %struct.StructByVal, align 8
908 %0 = bitcast %struct.StructByVal* %s to i8*
909 %agg.tmp.sroa.0.0..sroa_cast = bitcast %struct.StructByVal* %s to i64*
910 %agg.tmp.sroa.0.0.copyload = load i64, i64* %agg.tmp.sroa.0.0..sroa_cast, align 4
911 %agg.tmp.sroa.2.0..sroa_idx = getelementptr inbounds %struct.StructByVal, %struct.StructByVal* %s, i64 0, i32 2
912 %agg.tmp.sroa.2.0..sroa_cast = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx to i64*
913 %agg.tmp.sroa.2.0.copyload = load i64, i64* %agg.tmp.sroa.2.0..sroa_cast, align 4
914 %1 = bitcast %struct.StructByVal* %agg.tmp2 to i8*
915 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %0, i64 16, i1 false)
916 call void (i32, ...) @VAArgStructFn(i32 undef, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, %struct.StructByVal* byval align 8 %agg.tmp2)
920 ; "undef" and the first 2 structs go to general purpose registers;
921 ; the third struct goes to the overflow area byval
923 ; CHECK-LABEL: @VAArgStruct
924 ; undef not stored to __msan_va_arg_tls - it's a fixed argument
925 ; first struct through general purpose registers
926 ; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 8){{.*}}, align 8
927 ; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 16){{.*}}, align 8
928 ; second struct through general purpose registers
929 ; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 24){{.*}}, align 8
930 ; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 32){{.*}}, align 8
931 ; third struct through the overflow area byval
932 ; CHECK: ptrtoint %struct.StructByVal* {{.*}} to i64
933 ; CHECK: bitcast { i32, i32, i32, i32 }* {{.*}}@__msan_va_arg_tls {{.*}}, i64 176
934 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
935 ; CHECK: store i64 16, i64* @__msan_va_arg_overflow_size_tls
936 ; CHECK: call void (i32, ...) @VAArgStructFn
939 ; Same code compiled without SSE (see attributes below).
940 ; The register save area is only 48 bytes instead of 176.
941 define void @VAArgStructNoSSE(%struct.StructByVal* nocapture %s) sanitize_memory #0 {
943 %agg.tmp2 = alloca %struct.StructByVal, align 8
944 %0 = bitcast %struct.StructByVal* %s to i8*
945 %agg.tmp.sroa.0.0..sroa_cast = bitcast %struct.StructByVal* %s to i64*
946 %agg.tmp.sroa.0.0.copyload = load i64, i64* %agg.tmp.sroa.0.0..sroa_cast, align 4
947 %agg.tmp.sroa.2.0..sroa_idx = getelementptr inbounds %struct.StructByVal, %struct.StructByVal* %s, i64 0, i32 2
948 %agg.tmp.sroa.2.0..sroa_cast = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx to i64*
949 %agg.tmp.sroa.2.0.copyload = load i64, i64* %agg.tmp.sroa.2.0..sroa_cast, align 4
950 %1 = bitcast %struct.StructByVal* %agg.tmp2 to i8*
951 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %0, i64 16, i1 false)
952 call void (i32, ...) @VAArgStructFn(i32 undef, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, %struct.StructByVal* byval align 8 %agg.tmp2)
956 attributes #0 = { "target-features"="+fxsr,+x87,-sse" }
958 ; CHECK: bitcast { i32, i32, i32, i32 }* {{.*}}@__msan_va_arg_tls {{.*}}, i64 48
960 declare i32 @InnerTailCall(i32 %a)
962 define void @MismatchedReturnTypeTailCall(i32 %a) sanitize_memory {
963 %b = tail call i32 @InnerTailCall(i32 %a)
967 ; We used to strip off the 'tail' modifier, but now that we unpoison return slot
968 ; shadow before the call, we don't need to anymore.
970 ; CHECK-LABEL: define void @MismatchedReturnTypeTailCall
971 ; CHECK: tail call i32 @InnerTailCall
975 declare i32 @MustTailCall(i32 %a)
977 define i32 @CallMustTailCall(i32 %a) sanitize_memory {
978 %b = musttail call i32 @MustTailCall(i32 %a)
982 ; For "musttail" calls we can not insert any shadow manipulating code between
983 ; call and the return instruction. And we don't need to, because everything is
984 ; taken care of in the callee.
986 ; CHECK-LABEL: define i32 @CallMustTailCall
987 ; CHECK: musttail call i32 @MustTailCall
988 ; No instrumentation between call and ret.
989 ; CHECK-NEXT: ret i32
991 declare i32* @MismatchingMustTailCall(i32 %a)
993 define i8* @MismatchingCallMustTailCall(i32 %a) sanitize_memory {
994 %b = musttail call i32* @MismatchingMustTailCall(i32 %a)
995 %c = bitcast i32* %b to i8*
999 ; For "musttail" calls we can not insert any shadow manipulating code between
1000 ; call and the return instruction. And we don't need to, because everything is
1001 ; taken care of in the callee.
1003 ; CHECK-LABEL: define i8* @MismatchingCallMustTailCall
1004 ; CHECK: musttail call i32* @MismatchingMustTailCall
1005 ; No instrumentation between call and ret.
1006 ; CHECK-NEXT: bitcast i32* {{.*}} to i8*
1007 ; CHECK-NEXT: ret i8*
1010 ; CHECK-LABEL: define internal void @msan.module_ctor() {
1011 ; CHECK: call void @__msan_init()