vararg.ll
7.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
; RUN: opt < %s -S -mcpu=z13 -passes=msan 2>&1 | FileCheck %s
; RUN: opt < %s -msan -S -mcpu=z13 | FileCheck %s
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
target triple = "s390x-unknown-linux-gnu"
%struct.__va_list = type { i64, i64, i8*, i8* }
define i64 @foo(i64 %guard, ...) {
%vl = alloca %struct.__va_list, align 8
%1 = bitcast %struct.__va_list* %vl to i8*
call void @llvm.lifetime.start.p0i8(i64 32, i8* %1)
call void @llvm.va_start(i8* %1)
call void @llvm.va_end(i8* %1)
call void @llvm.lifetime.end.p0i8(i64 32, i8* %1)
ret i64 0
}
; First check if the variadic shadow values are saved in stack with correct
; size (which is 160 - size of the register save area).
; CHECK-LABEL: @foo
; CHECK: [[A:%.*]] = load {{.*}} @__msan_va_arg_overflow_size_tls
; CHECK: [[B:%.*]] = add i64 160, [[A]]
; CHECK: alloca {{.*}} [[B]]
; We expect two memcpy operations: one for the register save area, and one for
; the overflow arg area.
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 {{%.*}}, i8* align 8 {{%.*}}, i64 160, i1 false)
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 {{%.*}}, i8* align 8 {{%.*}}, i64 [[A]], i1 false)
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
declare void @llvm.va_start(i8*) #2
declare void @llvm.va_end(i8*) #2
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
declare i32 @random_i32()
declare i64 @random_i64()
declare float @random_float()
declare double @random_double()
define i64 @bar() {
%arg2 = call i32 () @random_i32()
%arg3 = call float () @random_float()
%arg4 = call i32 () @random_i32()
%arg5 = call double () @random_double()
%arg6 = call i64 () @random_i64()
%arg9 = call i32 () @random_i32()
%arg11 = call float () @random_float()
%arg12 = call i32 () @random_i32()
%arg13 = call double () @random_double()
%arg14 = call i64 () @random_i64()
%1 = call i64 (i64, ...) @foo(i64 1, i32 zeroext %arg2, float %arg3,
i32 signext %arg4, double %arg5, i64 %arg6,
i64 7, double 8.0, i32 zeroext %arg9,
double 10.0, float %arg11, i32 signext %arg12,
double %arg13, i64 %arg14)
ret i64 %1
}
; Save the incoming shadow values from the varargs in the __msan_va_arg_tls
; array at the offsets equal to those defined by the ABI for the corresponding
; registers in the register save area, and for the corresponding overflow args
; in the overflow arg area:
; - r2@16 == i64 1 - skipped, because it's fixed
; - r3@24 == i32 zext %arg2 - shadow is zero-extended
; - f0@128 == float %arg3 - left-justified, shadow is 32-bit
; - r4@32 == i32 sext %arg4 - shadow is sign-extended
; - f2@136 == double %arg5 - straightforward
; - r5@40 == i64 %arg6 - straightforward
; - r6@48 == 7 - filler
; - f4@144 == 8.0 - filler
; - overflow@160 == i32 zext %arg9 - shadow is zero-extended
; - f6@152 == 10.0 - filler
; - overflow@(168 + 4) == float %arg11 - right-justified, shadow is 32-bit
; - overflow@176 == i32 sext %arg12 - shadow is sign-extended
; - overflow@184 == double %arg13 - straightforward
; - overflow@192 == i64 %arg14 - straightforward
; Overflow arg area size is 40.
; CHECK-LABEL: @bar
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 24
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 128
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 32
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 136
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 40
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 48
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 144
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 160
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 152
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 172
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 176
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 184
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 192
; CHECK: store {{.*}} 40, {{.*}} @__msan_va_arg_overflow_size_tls
; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are
; passed to a variadic function.
define dso_local i64 @many_args() {
entry:
%ret = call i64 (i64, ...) @sum(i64 120,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1
)
ret i64 %ret
}
; If the size of __msan_va_arg_tls changes the second argument of `add` must also be changed.
; CHECK-LABEL: @many_args
; CHECK: i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 792)
; CHECK-NOT: i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 800)
declare i64 @sum(i64 %n, ...)
; Test offset calculation for vector arguments.
; Regardless of whether or not fixed args overflow, we should copy a shadow
; for a single vector vararg to offset 160.
declare void @vr_no_overflow(<4 x float> %v24, <4 x float> %v26,
<4 x float> %v28, <4 x float> %v30,
<4 x float> %v25, <4 x float> %v27,
<4 x float> %v29, ...)
declare <4 x float> @vr_value()
define void @vr_no_overflow_caller() {
%1 = call <4 x float> () @vr_value()
call void (<4 x float>, <4 x float>, <4 x float>,
<4 x float>, <4 x float>, <4 x float>,
<4 x float>, ...) @vr_no_overflow(
<4 x float> %1, <4 x float> %1, <4 x float> %1, <4 x float> %1,
<4 x float> %1, <4 x float> %1, <4 x float> %1, <4 x float> %1)
ret void
}
; CHECK-LABEL: @vr_no_overflow_caller
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 160
; CHECK-NOT: store {{.*}} @__msan_va_arg_tls {{.*}}
; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
declare void @vr_overflow(<4 x float> %v24, <4 x float> %v26,
<4 x float> %v28, <4 x float> %v30,
<4 x float> %v25, <4 x float> %v27,
<4 x float> %v29, <4 x float> %v31,
<4 x float> %overflow, ...)
define void @vr_overflow_caller() {
%1 = call <4 x float> @vr_value()
call void (<4 x float>, <4 x float>, <4 x float>,
<4 x float>, <4 x float>, <4 x float>,
<4 x float>, <4 x float>, <4 x float>,
...) @vr_overflow(
<4 x float> %1, <4 x float> %1, <4 x float> %1, <4 x float> %1,
<4 x float> %1, <4 x float> %1, <4 x float> %1, <4 x float> %1,
<4 x float> %1, <4 x float> %1)
ret void
}
; CHECK-LABEL: @vr_overflow_caller
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 160
; CHECK-NOT: store {{.*}} @__msan_va_arg_tls {{.*}}
; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
; Test that i128 and fp128 are passed by reference.
declare i128 @random_i128()
declare fp128 @random_fp128()
define i64 @bar_128() {
%iarg = call i128 @random_i128()
%fparg = call fp128 @random_fp128()
%1 = call i64 (i64, ...) @foo(i64 1, i128 %iarg, fp128 %fparg)
ret i64 %1
}
; CHECK-LABEL: @bar_128
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 24
; CHECK: store {{.*}} @__msan_va_arg_tls {{.*}} 32
; CHECK: store {{.*}} 0, {{.*}} @__msan_va_arg_overflow_size_tls