1 ; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck %s
3 target datalayout = "E-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128"
4 target triple = "mips64--linux"
6 define i32 @foo(i32 %guard, ...) {
7 %vl = alloca ptr, align 8
8 call void @llvm.lifetime.start.p0(i64 32, ptr %vl)
9 call void @llvm.va_start(ptr %vl)
10 call void @llvm.va_end(ptr %vl)
11 call void @llvm.lifetime.end.p0(i64 32, ptr %vl)
15 ; First, check allocation of the save area.
18 ; CHECK: [[A:%.*]] = load {{.*}} @__msan_va_arg_overflow_size_tls
19 ; CHECK: [[C:%.*]] = alloca {{.*}} [[A]]
21 ; CHECK: call void @llvm.memset.p0.i64(ptr align 8 [[C]], i8 0, i64 [[A]], i1 false)
23 ; CHECK: [[D:%.*]] = call i64 @llvm.umin.i64(i64 [[A]], i64 800)
24 ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[C]], ptr align 8 @__msan_va_arg_tls, i64 [[D]], i1 false)
26 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
27 declare void @llvm.va_start(ptr) #2
28 declare void @llvm.va_end(ptr) #2
29 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
32 %1 = call i32 (i32, ...) @foo(i32 0, i32 1, i64 2, double 3.000000e+00)
36 ; Save the incoming shadow value from the arguments in the __msan_va_arg_tls
37 ; array. The first argument is stored at position 4, since it's right
40 ; CHECK: store i32 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 4) to ptr), align 8
41 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
42 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 16) to ptr), align 8
43 ; CHECK: store {{.*}} 24, {{.*}} @__msan_va_arg_overflow_size_tls
45 ; Check multiple fixed arguments.
46 declare i32 @foo2(i32 %g1, i32 %g2, ...)
48 %1 = call i32 (i32, i32, ...) @foo2(i32 0, i32 1, i64 2, double 3.000000e+00)
53 ; CHECK: store i64 0, ptr @__msan_va_arg_tls, align 8
54 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
55 ; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
57 ; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are
58 ; passed to a variadic function.
59 define dso_local i64 @many_args() {
61 %ret = call i64 (i64, ...) @sum(i64 120,
62 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
63 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
64 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
65 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
66 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
67 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
68 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
69 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
70 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
71 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
72 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
73 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1
78 ; If the size of __msan_va_arg_tls changes the second argument of `add` must also be changed.
79 ; CHECK-LABEL: @many_args
80 ; CHECK: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 792)
81 ; CHECK-NOT: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 800)
82 declare i64 @sum(i64 %n, ...)
84 ; CHECK: declare void @__msan_maybe_warning_1(i8 signext, i32 signext)
85 ; CHECK: declare void @__msan_maybe_store_origin_1(i8 signext, ptr, i32 signext)
86 ; CHECK: declare void @__msan_maybe_warning_2(i16 signext, i32 signext)
87 ; CHECK: declare void @__msan_maybe_store_origin_2(i16 signext, ptr, i32 signext)
88 ; CHECK: declare void @__msan_maybe_warning_4(i32 signext, i32 signext)
89 ; CHECK: declare void @__msan_maybe_store_origin_4(i32 signext, ptr, i32 signext)
90 ; CHECK: declare void @__msan_maybe_warning_8(i64 signext, i32 signext)
91 ; CHECK: declare void @__msan_maybe_store_origin_8(i64 signext, ptr, i32 signext)