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