1 ; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck %s
3 target datalayout = "E-m:e-i64:64-n32:64"
4 target triple = "powerpc64--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 vector argument.
47 %1 = call i32 (i32, ...) @foo(i32 0, <2 x i64> <i64 1, i64 2>)
51 ; The vector is at offset 16 of parameter save area, but __msan_va_arg_tls
52 ; corresponds to offset 8+ of parameter save area - so the offset from
53 ; __msan_va_arg_tls is actually misaligned.
55 ; CHECK: store <2 x i64> zeroinitializer, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
56 ; CHECK: store {{.*}} 24, {{.*}} @__msan_va_arg_overflow_size_tls
60 %1 = call i32 (i32, ...) @foo(i32 0, [2 x i64] [i64 1, i64 2])
65 ; CHECK: store [2 x i64] zeroinitializer, ptr @__msan_va_arg_tls, align 8
66 ; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
70 %1 = call i32 (i32, ...) @foo(i32 0, [2 x i128] [i128 1, i128 2])
75 ; CHECK: store [2 x i128] zeroinitializer, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
76 ; CHECK: store {{.*}} 40, {{.*}} @__msan_va_arg_overflow_size_tls
78 ; Check 8-aligned byval.
79 define i32 @bar6(ptr %arg) {
80 %1 = call i32 (i32, ...) @foo(i32 0, ptr byval([2 x i64]) align 8 %arg)
85 ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 @__msan_va_arg_tls, ptr align 8 {{.*}}, i64 16, i1 false)
86 ; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
88 ; Check 16-aligned byval.
89 define i32 @bar7(ptr %arg) {
90 %1 = call i32 (i32, ...) @foo(i32 0, ptr byval([4 x i64]) align 16 %arg)
95 ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), ptr align 8 {{.*}}, i64 32, i1 false)
96 ; CHECK: store {{.*}} 40, {{.*}} @__msan_va_arg_overflow_size_tls
99 ; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are
100 ; passed to a variadic function.
101 define dso_local i64 @many_args() {
103 %ret = call i64 (i64, ...) @sum(i64 120,
104 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
105 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
106 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
107 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
108 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
109 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
110 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
111 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
112 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
113 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
114 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
115 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1
120 ; If the size of __msan_va_arg_tls changes the second argument of `add` must also be changed.
121 ; CHECK-LABEL: @many_args
122 ; CHECK: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 792)
123 ; CHECK-NOT: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 800)
124 declare i64 @sum(i64 %n, ...)