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