[msan] Fix select instrumentation.
[oota-llvm.git] / test / Instrumentation / MemorySanitizer / msan_basic.ll
1 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
2 ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -check-prefix=CHECK-ORIGINS %s
3 ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s -check-prefix=CHECK-AA
4
5 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"
6 target triple = "x86_64-unknown-linux-gnu"
7
8 ; Check the presence of __msan_init
9 ; CHECK: @llvm.global_ctors {{.*}} @__msan_init
10
11 ; Check the presence and the linkage type of __msan_track_origins and
12 ; other interface symbols.
13 ; CHECK-NOT: @__msan_track_origins
14 ; CHECK-ORIGINS: @__msan_track_origins = weak_odr constant i32 1
15 ; CHECK-NOT: @__msan_keep_going = weak_odr constant i32 0
16 ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [{{.*}}]
17 ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32
18 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [{{.*}}]
19 ; CHECK: @__msan_param_origin_tls = external thread_local(initialexec) global [{{.*}}]
20 ; CHECK: @__msan_va_arg_tls = external thread_local(initialexec) global [{{.*}}]
21 ; CHECK: @__msan_va_arg_overflow_size_tls = external thread_local(initialexec) global i64
22 ; CHECK: @__msan_origin_tls = external thread_local(initialexec) global i32
23
24
25 ; Check instrumentation of stores
26
27 define void @Store(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
28 entry:
29   store i32 %x, i32* %p, align 4
30   ret void
31 }
32
33 ; CHECK: @Store
34 ; CHECK: load {{.*}} @__msan_param_tls
35 ; CHECK: store
36 ; CHECK: store
37 ; CHECK: ret void
38 ; CHECK-ORIGINS: @Store
39 ; CHECK-ORIGINS: load {{.*}} @__msan_param_tls
40 ; CHECK-ORIGINS: store
41 ; CHECK-ORIGINS: icmp
42 ; CHECK-ORIGINS: br i1
43 ; CHECK-ORIGINS: <label>
44 ; CHECK-ORIGINS: store
45 ; CHECK-ORIGINS: br label
46 ; CHECK-ORIGINS: <label>
47 ; CHECK-ORIGINS: store
48 ; CHECK-ORIGINS: ret void
49
50
51 ; Check instrumentation of aligned stores
52 ; Shadow store has the same alignment as the original store; origin store
53 ; does not specify explicit alignment.
54
55 define void @AlignedStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
56 entry:
57   store i32 %x, i32* %p, align 32
58   ret void
59 }
60
61 ; CHECK: @AlignedStore
62 ; CHECK: load {{.*}} @__msan_param_tls
63 ; CHECK: store {{.*}} align 32
64 ; CHECK: store {{.*}} align 32
65 ; CHECK: ret void
66 ; CHECK-ORIGINS: @AlignedStore
67 ; CHECK-ORIGINS: load {{.*}} @__msan_param_tls
68 ; CHECK-ORIGINS: store {{.*}} align 32
69 ; CHECK-ORIGINS: icmp
70 ; CHECK-ORIGINS: br i1
71 ; CHECK-ORIGINS: <label>
72 ; CHECK-ORIGINS: store {{.*}} align 32
73 ; CHECK-ORIGINS: br label
74 ; CHECK-ORIGINS: <label>
75 ; CHECK-ORIGINS: store {{.*}} align 32
76 ; CHECK-ORIGINS: ret void
77
78
79 ; load followed by cmp: check that we load the shadow and call __msan_warning.
80 define void @LoadAndCmp(i32* nocapture %a) nounwind uwtable sanitize_memory {
81 entry:
82   %0 = load i32* %a, align 4
83   %tobool = icmp eq i32 %0, 0
84   br i1 %tobool, label %if.end, label %if.then
85
86 if.then:                                          ; preds = %entry
87   tail call void (...)* @foo() nounwind
88   br label %if.end
89
90 if.end:                                           ; preds = %entry, %if.then
91   ret void
92 }
93
94 declare void @foo(...)
95
96 ; CHECK: @LoadAndCmp
97 ; CHECK: = load
98 ; CHECK: = load
99 ; CHECK: call void @__msan_warning_noreturn()
100 ; CHECK-NEXT: call void asm sideeffect
101 ; CHECK-NEXT: unreachable
102 ; CHECK: ret void
103
104 ; Check that we store the shadow for the retval.
105 define i32 @ReturnInt() nounwind uwtable readnone sanitize_memory {
106 entry:
107   ret i32 123
108 }
109
110 ; CHECK: @ReturnInt
111 ; CHECK: store i32 0,{{.*}}__msan_retval_tls
112 ; CHECK: ret i32
113
114 ; Check that we get the shadow for the retval.
115 define void @CopyRetVal(i32* nocapture %a) nounwind uwtable sanitize_memory {
116 entry:
117   %call = tail call i32 @ReturnInt() nounwind
118   store i32 %call, i32* %a, align 4
119   ret void
120 }
121
122 ; CHECK: @CopyRetVal
123 ; CHECK: load{{.*}}__msan_retval_tls
124 ; CHECK: store
125 ; CHECK: store
126 ; CHECK: ret void
127
128
129 ; Check that we generate PHIs for shadow.
130 define void @FuncWithPhi(i32* nocapture %a, i32* %b, i32* nocapture %c) nounwind uwtable sanitize_memory {
131 entry:
132   %tobool = icmp eq i32* %b, null
133   br i1 %tobool, label %if.else, label %if.then
134
135   if.then:                                          ; preds = %entry
136   %0 = load i32* %b, align 4
137   br label %if.end
138
139   if.else:                                          ; preds = %entry
140   %1 = load i32* %c, align 4
141   br label %if.end
142
143   if.end:                                           ; preds = %if.else, %if.then
144   %t.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
145   store i32 %t.0, i32* %a, align 4
146   ret void
147 }
148
149 ; CHECK: @FuncWithPhi
150 ; CHECK: = phi
151 ; CHECK-NEXT: = phi
152 ; CHECK: store
153 ; CHECK: store
154 ; CHECK: ret void
155
156 ; Compute shadow for "x << 10"
157 define void @ShlConst(i32* nocapture %x) nounwind uwtable sanitize_memory {
158 entry:
159   %0 = load i32* %x, align 4
160   %1 = shl i32 %0, 10
161   store i32 %1, i32* %x, align 4
162   ret void
163 }
164
165 ; CHECK: @ShlConst
166 ; CHECK: = load
167 ; CHECK: = load
168 ; CHECK: shl
169 ; CHECK: shl
170 ; CHECK: store
171 ; CHECK: store
172 ; CHECK: ret void
173
174 ; Compute shadow for "10 << x": it should have 'sext i1'.
175 define void @ShlNonConst(i32* nocapture %x) nounwind uwtable sanitize_memory {
176 entry:
177   %0 = load i32* %x, align 4
178   %1 = shl i32 10, %0
179   store i32 %1, i32* %x, align 4
180   ret void
181 }
182
183 ; CHECK: @ShlNonConst
184 ; CHECK: = load
185 ; CHECK: = load
186 ; CHECK: = sext i1
187 ; CHECK: store
188 ; CHECK: store
189 ; CHECK: ret void
190
191 ; SExt
192 define void @SExt(i32* nocapture %a, i16* nocapture %b) nounwind uwtable sanitize_memory {
193 entry:
194   %0 = load i16* %b, align 2
195   %1 = sext i16 %0 to i32
196   store i32 %1, i32* %a, align 4
197   ret void
198 }
199
200 ; CHECK: @SExt
201 ; CHECK: = load
202 ; CHECK: = load
203 ; CHECK: = sext
204 ; CHECK: = sext
205 ; CHECK: store
206 ; CHECK: store
207 ; CHECK: ret void
208
209
210 ; memset
211 define void @MemSet(i8* nocapture %x) nounwind uwtable sanitize_memory {
212 entry:
213   call void @llvm.memset.p0i8.i64(i8* %x, i8 42, i64 10, i32 1, i1 false)
214   ret void
215 }
216
217 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
218
219 ; CHECK: @MemSet
220 ; CHECK: call i8* @__msan_memset
221 ; CHECK: ret void
222
223
224 ; memcpy
225 define void @MemCpy(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory {
226 entry:
227   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
228   ret void
229 }
230
231 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
232
233 ; CHECK: @MemCpy
234 ; CHECK: call i8* @__msan_memcpy
235 ; CHECK: ret void
236
237
238 ; memmove is lowered to a call
239 define void @MemMove(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory {
240 entry:
241   call void @llvm.memmove.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i32 1, i1 false)
242   ret void
243 }
244
245 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
246
247 ; CHECK: @MemMove
248 ; CHECK: call i8* @__msan_memmove
249 ; CHECK: ret void
250
251
252 ; Check that we propagate shadow for "select"
253
254 define i32 @Select(i32 %a, i32 %b, i32 %c) nounwind uwtable readnone sanitize_memory {
255 entry:
256   %tobool = icmp ne i32 %c, 0
257   %cond = select i1 %tobool, i32 %a, i32 %b
258   ret i32 %cond
259 }
260
261 ; CHECK: @Select
262 ; CHECK: select
263 ; CHECK-NEXT: sext i1 {{.*}} to i32
264 ; CHECK-NEXT: or i32
265 ; CHECK-NEXT: select
266 ; CHECK: ret i32
267
268
269 ; Check that we propagate origin for "select" with vector condition.
270 ; Select condition is flattened to i1, which is then used to select one of the
271 ; argument origins.
272
273 define <8 x i16> @SelectVector(<8 x i16> %a, <8 x i16> %b, <8 x i1> %c) nounwind uwtable readnone sanitize_memory {
274 entry:
275   %cond = select <8 x i1> %c, <8 x i16> %a, <8 x i16> %b
276   ret <8 x i16> %cond
277 }
278
279 ; CHECK: @SelectVector
280 ; CHECK: select <8 x i1>
281 ; CHECK-NEXT: sext <8 x i1> {{.*}} to <8 x i16>
282 ; CHECK-NEXT: or <8 x i16>
283 ; CHECK-NEXT: select <8 x i1>
284 ; CHECK: ret <8 x i16>
285
286 ; CHECK-ORIGINS: @SelectVector
287 ; CHECK-ORIGINS: bitcast <8 x i1> {{.*}} to i8
288 ; CHECK-ORIGINS: icmp ne i8
289 ; CHECK-ORIGINS: select i1
290 ; CHECK-ORIGINS: ret <8 x i16>
291
292
293 define i8* @IntToPtr(i64 %x) nounwind uwtable readnone sanitize_memory {
294 entry:
295   %0 = inttoptr i64 %x to i8*
296   ret i8* %0
297 }
298
299 ; CHECK: @IntToPtr
300 ; CHECK: load i64*{{.*}}__msan_param_tls
301 ; CHECK-NEXT: inttoptr
302 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
303 ; CHECK: ret i8
304
305
306 define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone sanitize_memory {
307 entry:
308   %0 = inttoptr i16 %x to i8*
309   ret i8* %0
310 }
311
312 ; CHECK: @IntToPtr_ZExt
313 ; CHECK: zext
314 ; CHECK-NEXT: inttoptr
315 ; CHECK: ret i8
316
317
318 ; Check that we insert exactly one check on udiv
319 ; (2nd arg shadow is checked, 1st arg shadow is propagated)
320
321 define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone sanitize_memory {
322 entry:
323   %div = udiv i32 %a, %b
324   ret i32 %div
325 }
326
327 ; CHECK: @Div
328 ; CHECK: icmp
329 ; CHECK: call void @__msan_warning
330 ; CHECK-NOT: icmp
331 ; CHECK: udiv
332 ; CHECK-NOT: icmp
333 ; CHECK: ret i32
334
335
336 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
337
338 define zeroext i1 @ICmpSLT(i32 %x) nounwind uwtable readnone sanitize_memory {
339   %1 = icmp slt i32 %x, 0
340   ret i1 %1
341 }
342
343 ; CHECK: @ICmpSLT
344 ; CHECK: icmp slt
345 ; CHECK-NOT: call void @__msan_warning
346 ; CHECK: icmp slt
347 ; CHECK-NOT: call void @__msan_warning
348 ; CHECK: ret i1
349
350 define zeroext i1 @ICmpSGE(i32 %x) nounwind uwtable readnone sanitize_memory {
351   %1 = icmp sge i32 %x, 0
352   ret i1 %1
353 }
354
355 ; CHECK: @ICmpSGE
356 ; CHECK: icmp slt
357 ; CHECK-NOT: call void @__msan_warning
358 ; CHECK: icmp sge
359 ; CHECK-NOT: call void @__msan_warning
360 ; CHECK: ret i1
361
362 define zeroext i1 @ICmpSGT(i32 %x) nounwind uwtable readnone sanitize_memory {
363   %1 = icmp sgt i32 0, %x
364   ret i1 %1
365 }
366
367 ; CHECK: @ICmpSGT
368 ; CHECK: icmp slt
369 ; CHECK-NOT: call void @__msan_warning
370 ; CHECK: icmp sgt
371 ; CHECK-NOT: call void @__msan_warning
372 ; CHECK: ret i1
373
374 define zeroext i1 @ICmpSLE(i32 %x) nounwind uwtable readnone sanitize_memory {
375   %1 = icmp sle i32 0, %x
376   ret i1 %1
377 }
378
379 ; CHECK: @ICmpSLE
380 ; CHECK: icmp slt
381 ; CHECK-NOT: call void @__msan_warning
382 ; CHECK: icmp sle
383 ; CHECK-NOT: call void @__msan_warning
384 ; CHECK: ret i1
385
386
387 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
388 ; of the vector arguments.
389
390 define <2 x i1> @ICmpSLT_vector(<2 x i32*> %x) nounwind uwtable readnone sanitize_memory {
391   %1 = icmp slt <2 x i32*> %x, zeroinitializer
392   ret <2 x i1> %1
393 }
394
395 ; CHECK: @ICmpSLT_vector
396 ; CHECK: icmp slt <2 x i64>
397 ; CHECK-NOT: call void @__msan_warning
398 ; CHECK: icmp slt <2 x i32*>
399 ; CHECK-NOT: call void @__msan_warning
400 ; CHECK: ret <2 x i1>
401
402
403 ; Check that we propagate shadow for unsigned relational comparisons with
404 ; constants
405
406 define zeroext i1 @ICmpUGTConst(i32 %x) nounwind uwtable readnone sanitize_memory {
407 entry:
408   %cmp = icmp ugt i32 %x, 7
409   ret i1 %cmp
410 }
411
412 ; CHECK: @ICmpUGTConst
413 ; CHECK: icmp ugt i32
414 ; CHECK-NOT: call void @__msan_warning
415 ; CHECK: icmp ugt i32
416 ; CHECK-NOT: call void @__msan_warning
417 ; CHECK: icmp ugt i32
418 ; CHECK-NOT: call void @__msan_warning
419 ; CHECK: ret i1
420
421
422 ; Check that loads of shadow have the same aligment as the original loads.
423 ; Check that loads of origin have the aligment of max(4, original alignment).
424
425 define i32 @ShadowLoadAlignmentLarge() nounwind uwtable sanitize_memory {
426   %y = alloca i32, align 64
427   %1 = load volatile i32* %y, align 64
428   ret i32 %1
429 }
430
431 ; CHECK: @ShadowLoadAlignmentLarge
432 ; CHECK: load i32* {{.*}} align 64
433 ; CHECK: load volatile i32* {{.*}} align 64
434 ; CHECK: ret i32
435
436 define i32 @ShadowLoadAlignmentSmall() nounwind uwtable sanitize_memory {
437   %y = alloca i32, align 2
438   %1 = load volatile i32* %y, align 2
439   ret i32 %1
440 }
441
442 ; CHECK: @ShadowLoadAlignmentSmall
443 ; CHECK: load i32* {{.*}} align 2
444 ; CHECK: load volatile i32* {{.*}} align 2
445 ; CHECK: ret i32
446
447 ; CHECK-ORIGINS: @ShadowLoadAlignmentSmall
448 ; CHECK-ORIGINS: load i32* {{.*}} align 2
449 ; CHECK-ORIGINS: load i32* {{.*}} align 4
450 ; CHECK-ORIGINS: load volatile i32* {{.*}} align 2
451 ; CHECK-ORIGINS: ret i32
452
453
454 ; Test vector manipulation instructions.
455 ; Check that the same bit manipulation is applied to the shadow values.
456 ; Check that there is a zero test of the shadow of %idx argument, where present.
457
458 define i32 @ExtractElement(<4 x i32> %vec, i32 %idx) sanitize_memory {
459   %x = extractelement <4 x i32> %vec, i32 %idx
460   ret i32 %x
461 }
462
463 ; CHECK: @ExtractElement
464 ; CHECK: extractelement
465 ; CHECK: call void @__msan_warning
466 ; CHECK: extractelement
467 ; CHECK: ret i32
468
469 define <4 x i32> @InsertElement(<4 x i32> %vec, i32 %idx, i32 %x) sanitize_memory {
470   %vec1 = insertelement <4 x i32> %vec, i32 %x, i32 %idx
471   ret <4 x i32> %vec1
472 }
473
474 ; CHECK: @InsertElement
475 ; CHECK: insertelement
476 ; CHECK: call void @__msan_warning
477 ; CHECK: insertelement
478 ; CHECK: ret <4 x i32>
479
480 define <4 x i32> @ShuffleVector(<4 x i32> %vec, <4 x i32> %vec1) sanitize_memory {
481   %vec2 = shufflevector <4 x i32> %vec, <4 x i32> %vec1,
482                         <4 x i32> <i32 0, i32 4, i32 1, i32 5>
483   ret <4 x i32> %vec2
484 }
485
486 ; CHECK: @ShuffleVector
487 ; CHECK: shufflevector
488 ; CHECK-NOT: call void @__msan_warning
489 ; CHECK: shufflevector
490 ; CHECK: ret <4 x i32>
491
492
493 ; Test bswap intrinsic instrumentation
494 define i32 @BSwap(i32 %x) nounwind uwtable readnone sanitize_memory {
495   %y = tail call i32 @llvm.bswap.i32(i32 %x)
496   ret i32 %y
497 }
498
499 declare i32 @llvm.bswap.i32(i32) nounwind readnone
500
501 ; CHECK: @BSwap
502 ; CHECK-NOT: call void @__msan_warning
503 ; CHECK: @llvm.bswap.i32
504 ; CHECK-NOT: call void @__msan_warning
505 ; CHECK: @llvm.bswap.i32
506 ; CHECK-NOT: call void @__msan_warning
507 ; CHECK: ret i32
508
509
510 ; Store intrinsic.
511
512 define void @StoreIntrinsic(i8* %p, <4 x float> %x) nounwind uwtable sanitize_memory {
513   call void @llvm.x86.sse.storeu.ps(i8* %p, <4 x float> %x)
514   ret void
515 }
516
517 declare void @llvm.x86.sse.storeu.ps(i8*, <4 x float>) nounwind
518
519 ; CHECK: @StoreIntrinsic
520 ; CHECK-NOT: br
521 ; CHECK-NOT: = or
522 ; CHECK: store <4 x i32> {{.*}} align 1
523 ; CHECK: call void @llvm.x86.sse.storeu.ps
524 ; CHECK: ret void
525
526
527 ; Load intrinsic.
528
529 define <16 x i8> @LoadIntrinsic(i8* %p) nounwind uwtable sanitize_memory {
530   %call = call <16 x i8> @llvm.x86.sse3.ldu.dq(i8* %p)
531   ret <16 x i8> %call
532 }
533
534 declare <16 x i8> @llvm.x86.sse3.ldu.dq(i8* %p) nounwind
535
536 ; CHECK: @LoadIntrinsic
537 ; CHECK: load <16 x i8>* {{.*}} align 1
538 ; CHECK-NOT: br
539 ; CHECK-NOT: = or
540 ; CHECK: call <16 x i8> @llvm.x86.sse3.ldu.dq
541 ; CHECK: store <16 x i8> {{.*}} @__msan_retval_tls
542 ; CHECK: ret <16 x i8>
543
544 ; CHECK-ORIGINS: @LoadIntrinsic
545 ; CHECK-ORIGINS: [[ORIGIN:%[01-9a-z]+]] = load i32* {{.*}}
546 ; CHECK-ORIGINS: call <16 x i8> @llvm.x86.sse3.ldu.dq
547 ; CHECK-ORIGINS: store i32 {{.*}}[[ORIGIN]], i32* @__msan_retval_origin_tls
548 ; CHECK-ORIGINS: ret <16 x i8>
549
550
551 ; Simple NoMem intrinsic
552 ; Check that shadow is OR'ed, and origin is Select'ed
553 ; And no shadow checks!
554
555 define <8 x i16> @Paddsw128(<8 x i16> %a, <8 x i16> %b) nounwind uwtable sanitize_memory {
556   %call = call <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %a, <8 x i16> %b)
557   ret <8 x i16> %call
558 }
559
560 declare <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %a, <8 x i16> %b) nounwind
561
562 ; CHECK: @Paddsw128
563 ; CHECK-NEXT: load <8 x i16>* {{.*}} @__msan_param_tls
564 ; CHECK-NEXT: load <8 x i16>* {{.*}} @__msan_param_tls
565 ; CHECK-NEXT: = or <8 x i16>
566 ; CHECK-NEXT: call <8 x i16> @llvm.x86.sse2.padds.w
567 ; CHECK-NEXT: store <8 x i16> {{.*}} @__msan_retval_tls
568 ; CHECK-NEXT: ret <8 x i16>
569
570 ; CHECK-ORIGINS: @Paddsw128
571 ; CHECK-ORIGINS: load i32* {{.*}} @__msan_param_origin_tls
572 ; CHECK-ORIGINS: load i32* {{.*}} @__msan_param_origin_tls
573 ; CHECK-ORIGINS: = bitcast <8 x i16> {{.*}} to i128
574 ; CHECK-ORIGINS-NEXT: = icmp ne i128 {{.*}}, 0
575 ; CHECK-ORIGINS-NEXT: = select i1 {{.*}}, i32 {{.*}}, i32
576 ; CHECK-ORIGINS: call <8 x i16> @llvm.x86.sse2.padds.w
577 ; CHECK-ORIGINS: store i32 {{.*}} @__msan_retval_origin_tls
578 ; CHECK-ORIGINS: ret <8 x i16>
579
580
581 ; Test handling of vectors of pointers.
582 ; Check that shadow of such vector is a vector of integers.
583
584 define <8 x i8*> @VectorOfPointers(<8 x i8*>* %p) nounwind uwtable sanitize_memory {
585   %x = load <8 x i8*>* %p
586   ret <8 x i8*> %x
587 }
588
589 ; CHECK: @VectorOfPointers
590 ; CHECK: load <8 x i64>*
591 ; CHECK: load <8 x i8*>*
592 ; CHECK: store <8 x i64> {{.*}} @__msan_retval_tls
593 ; CHECK: ret <8 x i8*>
594
595 ; Test handling of va_copy.
596
597 declare void @llvm.va_copy(i8*, i8*) nounwind
598
599 define void @VACopy(i8* %p1, i8* %p2) nounwind uwtable sanitize_memory {
600   call void @llvm.va_copy(i8* %p1, i8* %p2) nounwind
601   ret void
602 }
603
604 ; CHECK: @VACopy
605 ; CHECK: call void @llvm.memset.p0i8.i64({{.*}}, i8 0, i64 24, i32 8, i1 false)
606 ; CHECK: ret void
607
608
609 ; Test that va_start instrumentation does not use va_arg_tls*.
610 ; It should work with a local stack copy instead.
611
612 %struct.__va_list_tag = type { i32, i32, i8*, i8* }
613 declare void @llvm.va_start(i8*) nounwind
614
615 ; Function Attrs: nounwind uwtable
616 define void @VAStart(i32 %x, ...) {
617 entry:
618   %x.addr = alloca i32, align 4
619   %va = alloca [1 x %struct.__va_list_tag], align 16
620   store i32 %x, i32* %x.addr, align 4
621   %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag]* %va, i32 0, i32 0
622   %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8*
623   call void @llvm.va_start(i8* %arraydecay1)
624   ret void
625 }
626
627 ; CHECK: @VAStart
628 ; CHECK: call void @llvm.va_start
629 ; CHECK-NOT: @__msan_va_arg_tls
630 ; CHECK-NOT: @__msan_va_arg_overflow_size_tls
631 ; CHECK: ret void
632
633
634 ; Test handling of volatile stores.
635 ; Check that MemorySanitizer does not add a check of the value being stored.
636
637 define void @VolatileStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
638 entry:
639   store volatile i32 %x, i32* %p, align 4
640   ret void
641 }
642
643 ; CHECK: @VolatileStore
644 ; CHECK-NOT: @__msan_warning
645 ; CHECK: ret void
646
647
648 ; Test that checks are omitted but shadow propagation is kept if
649 ; sanitize_memory attribute is missing.
650
651 define i32 @NoSanitizeMemory(i32 %x) uwtable {
652 entry:
653   %tobool = icmp eq i32 %x, 0
654   br i1 %tobool, label %if.end, label %if.then
655
656 if.then:                                          ; preds = %entry
657   tail call void @bar()
658   br label %if.end
659
660 if.end:                                           ; preds = %entry, %if.then
661   ret i32 %x
662 }
663
664 declare void @bar()
665
666 ; CHECK: @NoSanitizeMemory
667 ; CHECK-NOT: @__msan_warning
668 ; CHECK: load i32* {{.*}} @__msan_param_tls
669 ; CHECK-NOT: @__msan_warning
670 ; CHECK: store {{.*}} @__msan_retval_tls
671 ; CHECK-NOT: @__msan_warning
672 ; CHECK: ret i32
673
674
675 ; Test that stack allocations are unpoisoned in functions missing
676 ; sanitize_memory attribute
677
678 define i32 @NoSanitizeMemoryAlloca() {
679 entry:
680   %p = alloca i32, align 4
681   %x = call i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
682   ret i32 %x
683 }
684
685 declare i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
686
687 ; CHECK: @NoSanitizeMemoryAlloca
688 ; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 4, i32 4, i1 false)
689 ; CHECK: call i32 @NoSanitizeMemoryAllocaHelper(i32*
690 ; CHECK: ret i32
691
692
693 ; Test that undef is unpoisoned in functions missing
694 ; sanitize_memory attribute
695
696 define i32 @NoSanitizeMemoryUndef() {
697 entry:
698   %x = call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
699   ret i32 %x
700 }
701
702 declare i32 @NoSanitizeMemoryUndefHelper(i32 %x)
703
704 ; CHECK: @NoSanitizeMemoryAlloca
705 ; CHECK: store i32 0, i32* {{.*}} @__msan_param_tls
706 ; CHECK: call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
707 ; CHECK: ret i32
708
709
710 ; Test argument shadow alignment
711
712 define <2 x i64> @ArgumentShadowAlignment(i64 %a, <2 x i64> %b) sanitize_memory {
713 entry:
714   ret <2 x i64> %b
715 }
716
717 ; CHECK: @ArgumentShadowAlignment
718 ; CHECK: load <2 x i64>* {{.*}} @__msan_param_tls {{.*}}, align 8
719 ; CHECK: store <2 x i64> {{.*}} @__msan_retval_tls {{.*}}, align 8
720 ; CHECK: ret <2 x i64>
721
722
723 ; Test byval argument shadow alignment
724
725 define <2 x i64> @ByValArgumentShadowLargeAlignment(<2 x i64>* byval %p) sanitize_memory {
726 entry:
727   %x = load <2 x i64>* %p
728   ret <2 x i64> %x
729 }
730
731 ; CHECK-AA: @ByValArgumentShadowLargeAlignment
732 ; CHECK-AA: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 16, i32 8, i1 false)
733 ; CHECK-AA: ret <2 x i64>
734
735
736 define i16 @ByValArgumentShadowSmallAlignment(i16* byval %p) sanitize_memory {
737 entry:
738   %x = load i16* %p
739   ret i16 %x
740 }
741
742 ; CHECK-AA: @ByValArgumentShadowSmallAlignment
743 ; CHECK-AA: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 2, i32 2, i1 false)
744 ; CHECK-AA: ret i16
745