Debug info: On ARM ensure that all __TEXT sections come before the
[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: select
259 ; CHECK: ret i32
260
261
262 ; Check that we propagate origin for "select" with vector condition.
263 ; Select condition is flattened to i1, which is then used to select one of the
264 ; argument origins.
265
266 define <8 x i16> @SelectVector(<8 x i16> %a, <8 x i16> %b, <8 x i1> %c) nounwind uwtable readnone sanitize_memory {
267 entry:
268   %cond = select <8 x i1> %c, <8 x i16> %a, <8 x i16> %b
269   ret <8 x i16> %cond
270 }
271
272 ; CHECK: @SelectVector
273 ; CHECK: select <8 x i1>
274 ; CHECK-NEXT: sext <8 x i1> {{.*}} to <8 x i16>
275 ; CHECK-NEXT: or <8 x i16>
276 ; CHECK-ORIGINS: bitcast <8 x i1> {{.*}} to i8
277 ; CHECK-ORIGINS: icmp ne i8 {{.*}}, 0
278 ; CHECK-ORIGINS: bitcast <8 x i1> {{.*}} to i8
279 ; CHECK-ORIGINS: icmp ne i8 {{.*}}, 0
280 ; CHECK-ORIGINS: select i1
281 ; CHECK-ORIGINS: select i1
282 ; CHECK: select <8 x i1>
283 ; CHECK: ret <8 x i16>
284
285
286
287 ; Check that we propagate origin for "select" with scalar condition and vector
288 ; arguments. Select condition shadow is sign-extended to the vector type and
289 ; mixed into the result shadow.
290
291 define <8 x i16> @SelectVector2(<8 x i16> %a, <8 x i16> %b, i1 %c) nounwind uwtable readnone sanitize_memory {
292 entry:
293   %cond = select i1 %c, <8 x i16> %a, <8 x i16> %b
294   ret <8 x i16> %cond
295 }
296
297 ; CHECK: @SelectVector2
298 ; CHECK: select i1
299 ; CHECK: sext i1 {{.*}} to i128
300 ; CHECK: bitcast i128 {{.*}} to <8 x i16>
301 ; CHECK: or <8 x i16>
302 ; CHECK-ORIGINS: select i1
303 ; CHECK-ORIGINS: select i1
304 ; CHECK: select i1
305 ; CHECK: ret <8 x i16>
306
307
308 define { i64, i64 } @SelectStruct(i1 zeroext %x, { i64, i64 } %a, { i64, i64 } %b) readnone sanitize_memory {
309 entry:
310   %c = select i1 %x, { i64, i64 } %a, { i64, i64 } %b
311   ret { i64, i64 } %c
312 }
313
314 ; CHECK: @SelectStruct
315 ; CHECK: select i1 {{.*}}, { i64, i64 }
316 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 }
317 ; CHECK-ORIGINS: select i1
318 ; CHECK-ORIGINS: select i1
319 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 }
320 ; CHECK: ret { i64, i64 }
321
322
323 define i8* @IntToPtr(i64 %x) nounwind uwtable readnone sanitize_memory {
324 entry:
325   %0 = inttoptr i64 %x to i8*
326   ret i8* %0
327 }
328
329 ; CHECK: @IntToPtr
330 ; CHECK: load i64*{{.*}}__msan_param_tls
331 ; CHECK-ORIGINS-NEXT: load i32*{{.*}}__msan_param_origin_tls
332 ; CHECK-NEXT: inttoptr
333 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
334 ; CHECK: ret i8*
335
336
337 define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone sanitize_memory {
338 entry:
339   %0 = inttoptr i16 %x to i8*
340   ret i8* %0
341 }
342
343 ; CHECK: @IntToPtr_ZExt
344 ; CHECK: load i16*{{.*}}__msan_param_tls
345 ; CHECK: zext
346 ; CHECK-NEXT: inttoptr
347 ; CHECK-NEXT: store i64{{.*}}__msan_retval_tls
348 ; CHECK: ret i8*
349
350
351 ; Check that we insert exactly one check on udiv
352 ; (2nd arg shadow is checked, 1st arg shadow is propagated)
353
354 define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone sanitize_memory {
355 entry:
356   %div = udiv i32 %a, %b
357   ret i32 %div
358 }
359
360 ; CHECK: @Div
361 ; CHECK: icmp
362 ; CHECK: call void @__msan_warning
363 ; CHECK-NOT: icmp
364 ; CHECK: udiv
365 ; CHECK-NOT: icmp
366 ; CHECK: ret i32
367
368
369 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
370
371 define zeroext i1 @ICmpSLT(i32 %x) nounwind uwtable readnone sanitize_memory {
372   %1 = icmp slt i32 %x, 0
373   ret i1 %1
374 }
375
376 ; CHECK: @ICmpSLT
377 ; CHECK: icmp slt
378 ; CHECK-NOT: call void @__msan_warning
379 ; CHECK: icmp slt
380 ; CHECK-NOT: call void @__msan_warning
381 ; CHECK: ret i1
382
383 define zeroext i1 @ICmpSGE(i32 %x) nounwind uwtable readnone sanitize_memory {
384   %1 = icmp sge i32 %x, 0
385   ret i1 %1
386 }
387
388 ; CHECK: @ICmpSGE
389 ; CHECK: icmp slt
390 ; CHECK-NOT: call void @__msan_warning
391 ; CHECK: icmp sge
392 ; CHECK-NOT: call void @__msan_warning
393 ; CHECK: ret i1
394
395 define zeroext i1 @ICmpSGT(i32 %x) nounwind uwtable readnone sanitize_memory {
396   %1 = icmp sgt i32 0, %x
397   ret i1 %1
398 }
399
400 ; CHECK: @ICmpSGT
401 ; CHECK: icmp slt
402 ; CHECK-NOT: call void @__msan_warning
403 ; CHECK: icmp sgt
404 ; CHECK-NOT: call void @__msan_warning
405 ; CHECK: ret i1
406
407 define zeroext i1 @ICmpSLE(i32 %x) nounwind uwtable readnone sanitize_memory {
408   %1 = icmp sle i32 0, %x
409   ret i1 %1
410 }
411
412 ; CHECK: @ICmpSLE
413 ; CHECK: icmp slt
414 ; CHECK-NOT: call void @__msan_warning
415 ; CHECK: icmp sle
416 ; CHECK-NOT: call void @__msan_warning
417 ; CHECK: ret i1
418
419
420 ; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests)
421 ; of the vector arguments.
422
423 define <2 x i1> @ICmpSLT_vector(<2 x i32*> %x) nounwind uwtable readnone sanitize_memory {
424   %1 = icmp slt <2 x i32*> %x, zeroinitializer
425   ret <2 x i1> %1
426 }
427
428 ; CHECK: @ICmpSLT_vector
429 ; CHECK: icmp slt <2 x i64>
430 ; CHECK-NOT: call void @__msan_warning
431 ; CHECK: icmp slt <2 x i32*>
432 ; CHECK-NOT: call void @__msan_warning
433 ; CHECK: ret <2 x i1>
434
435
436 ; Check that we propagate shadow for unsigned relational comparisons with
437 ; constants
438
439 define zeroext i1 @ICmpUGTConst(i32 %x) nounwind uwtable readnone sanitize_memory {
440 entry:
441   %cmp = icmp ugt i32 %x, 7
442   ret i1 %cmp
443 }
444
445 ; CHECK: @ICmpUGTConst
446 ; CHECK: icmp ugt i32
447 ; CHECK-NOT: call void @__msan_warning
448 ; CHECK: icmp ugt i32
449 ; CHECK-NOT: call void @__msan_warning
450 ; CHECK: icmp ugt i32
451 ; CHECK-NOT: call void @__msan_warning
452 ; CHECK: ret i1
453
454
455 ; Check that loads of shadow have the same aligment as the original loads.
456 ; Check that loads of origin have the aligment of max(4, original alignment).
457
458 define i32 @ShadowLoadAlignmentLarge() nounwind uwtable sanitize_memory {
459   %y = alloca i32, align 64
460   %1 = load volatile i32* %y, align 64
461   ret i32 %1
462 }
463
464 ; CHECK: @ShadowLoadAlignmentLarge
465 ; CHECK: load volatile i32* {{.*}} align 64
466 ; CHECK: load i32* {{.*}} align 64
467 ; CHECK: ret i32
468
469 define i32 @ShadowLoadAlignmentSmall() nounwind uwtable sanitize_memory {
470   %y = alloca i32, align 2
471   %1 = load volatile i32* %y, align 2
472   ret i32 %1
473 }
474
475 ; CHECK: @ShadowLoadAlignmentSmall
476 ; CHECK: load volatile i32* {{.*}} align 2
477 ; CHECK: load i32* {{.*}} align 2
478 ; CHECK-ORIGINS: load i32* {{.*}} align 4
479 ; CHECK: ret i32
480
481
482 ; Test vector manipulation instructions.
483 ; Check that the same bit manipulation is applied to the shadow values.
484 ; Check that there is a zero test of the shadow of %idx argument, where present.
485
486 define i32 @ExtractElement(<4 x i32> %vec, i32 %idx) sanitize_memory {
487   %x = extractelement <4 x i32> %vec, i32 %idx
488   ret i32 %x
489 }
490
491 ; CHECK: @ExtractElement
492 ; CHECK: extractelement
493 ; CHECK: call void @__msan_warning
494 ; CHECK: extractelement
495 ; CHECK: ret i32
496
497 define <4 x i32> @InsertElement(<4 x i32> %vec, i32 %idx, i32 %x) sanitize_memory {
498   %vec1 = insertelement <4 x i32> %vec, i32 %x, i32 %idx
499   ret <4 x i32> %vec1
500 }
501
502 ; CHECK: @InsertElement
503 ; CHECK: insertelement
504 ; CHECK: call void @__msan_warning
505 ; CHECK: insertelement
506 ; CHECK: ret <4 x i32>
507
508 define <4 x i32> @ShuffleVector(<4 x i32> %vec, <4 x i32> %vec1) sanitize_memory {
509   %vec2 = shufflevector <4 x i32> %vec, <4 x i32> %vec1,
510                         <4 x i32> <i32 0, i32 4, i32 1, i32 5>
511   ret <4 x i32> %vec2
512 }
513
514 ; CHECK: @ShuffleVector
515 ; CHECK: shufflevector
516 ; CHECK-NOT: call void @__msan_warning
517 ; CHECK: shufflevector
518 ; CHECK: ret <4 x i32>
519
520
521 ; Test bswap intrinsic instrumentation
522 define i32 @BSwap(i32 %x) nounwind uwtable readnone sanitize_memory {
523   %y = tail call i32 @llvm.bswap.i32(i32 %x)
524   ret i32 %y
525 }
526
527 declare i32 @llvm.bswap.i32(i32) nounwind readnone
528
529 ; CHECK: @BSwap
530 ; CHECK-NOT: call void @__msan_warning
531 ; CHECK: @llvm.bswap.i32
532 ; CHECK-NOT: call void @__msan_warning
533 ; CHECK: @llvm.bswap.i32
534 ; CHECK-NOT: call void @__msan_warning
535 ; CHECK: ret i32
536
537
538 ; Store intrinsic.
539
540 define void @StoreIntrinsic(i8* %p, <4 x float> %x) nounwind uwtable sanitize_memory {
541   call void @llvm.x86.sse.storeu.ps(i8* %p, <4 x float> %x)
542   ret void
543 }
544
545 declare void @llvm.x86.sse.storeu.ps(i8*, <4 x float>) nounwind
546
547 ; CHECK: @StoreIntrinsic
548 ; CHECK-NOT: br
549 ; CHECK-NOT: = or
550 ; CHECK: store <4 x i32> {{.*}} align 1
551 ; CHECK: call void @llvm.x86.sse.storeu.ps
552 ; CHECK: ret void
553
554
555 ; Load intrinsic.
556
557 define <16 x i8> @LoadIntrinsic(i8* %p) nounwind uwtable sanitize_memory {
558   %call = call <16 x i8> @llvm.x86.sse3.ldu.dq(i8* %p)
559   ret <16 x i8> %call
560 }
561
562 declare <16 x i8> @llvm.x86.sse3.ldu.dq(i8* %p) nounwind
563
564 ; CHECK: @LoadIntrinsic
565 ; CHECK: load <16 x i8>* {{.*}} align 1
566 ; CHECK-ORIGINS: [[ORIGIN:%[01-9a-z]+]] = load i32* {{.*}}
567 ; CHECK-NOT: br
568 ; CHECK-NOT: = or
569 ; CHECK: call <16 x i8> @llvm.x86.sse3.ldu.dq
570 ; CHECK: store <16 x i8> {{.*}} @__msan_retval_tls
571 ; CHECK-ORIGINS: store i32 {{.*}}[[ORIGIN]], i32* @__msan_retval_origin_tls
572 ; CHECK: ret <16 x i8>
573
574
575 ; Simple NoMem intrinsic
576 ; Check that shadow is OR'ed, and origin is Select'ed
577 ; And no shadow checks!
578
579 define <8 x i16> @Paddsw128(<8 x i16> %a, <8 x i16> %b) nounwind uwtable sanitize_memory {
580   %call = call <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %a, <8 x i16> %b)
581   ret <8 x i16> %call
582 }
583
584 declare <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %a, <8 x i16> %b) nounwind
585
586 ; CHECK: @Paddsw128
587 ; CHECK-NEXT: load <8 x i16>* {{.*}} @__msan_param_tls
588 ; CHECK-ORIGINS: load i32* {{.*}} @__msan_param_origin_tls
589 ; CHECK-NEXT: load <8 x i16>* {{.*}} @__msan_param_tls
590 ; CHECK-ORIGINS: load i32* {{.*}} @__msan_param_origin_tls
591 ; CHECK-NEXT: = or <8 x i16>
592 ; CHECK-ORIGINS: = bitcast <8 x i16> {{.*}} to i128
593 ; CHECK-ORIGINS-NEXT: = icmp ne i128 {{.*}}, 0
594 ; CHECK-ORIGINS-NEXT: = select i1 {{.*}}, i32 {{.*}}, i32
595 ; CHECK-NEXT: call <8 x i16> @llvm.x86.sse2.padds.w
596 ; CHECK-NEXT: store <8 x i16> {{.*}} @__msan_retval_tls
597 ; CHECK-ORIGINS: store i32 {{.*}} @__msan_retval_origin_tls
598 ; CHECK-NEXT: ret <8 x i16>
599
600
601 ; Test handling of vectors of pointers.
602 ; Check that shadow of such vector is a vector of integers.
603
604 define <8 x i8*> @VectorOfPointers(<8 x i8*>* %p) nounwind uwtable sanitize_memory {
605   %x = load <8 x i8*>* %p
606   ret <8 x i8*> %x
607 }
608
609 ; CHECK: @VectorOfPointers
610 ; CHECK: load <8 x i8*>*
611 ; CHECK: load <8 x i64>*
612 ; CHECK: store <8 x i64> {{.*}} @__msan_retval_tls
613 ; CHECK: ret <8 x i8*>
614
615 ; Test handling of va_copy.
616
617 declare void @llvm.va_copy(i8*, i8*) nounwind
618
619 define void @VACopy(i8* %p1, i8* %p2) nounwind uwtable sanitize_memory {
620   call void @llvm.va_copy(i8* %p1, i8* %p2) nounwind
621   ret void
622 }
623
624 ; CHECK: @VACopy
625 ; CHECK: call void @llvm.memset.p0i8.i64({{.*}}, i8 0, i64 24, i32 8, i1 false)
626 ; CHECK: ret void
627
628
629 ; Test that va_start instrumentation does not use va_arg_tls*.
630 ; It should work with a local stack copy instead.
631
632 %struct.__va_list_tag = type { i32, i32, i8*, i8* }
633 declare void @llvm.va_start(i8*) nounwind
634
635 ; Function Attrs: nounwind uwtable
636 define void @VAStart(i32 %x, ...) {
637 entry:
638   %x.addr = alloca i32, align 4
639   %va = alloca [1 x %struct.__va_list_tag], align 16
640   store i32 %x, i32* %x.addr, align 4
641   %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag]* %va, i32 0, i32 0
642   %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8*
643   call void @llvm.va_start(i8* %arraydecay1)
644   ret void
645 }
646
647 ; CHECK: @VAStart
648 ; CHECK: call void @llvm.va_start
649 ; CHECK-NOT: @__msan_va_arg_tls
650 ; CHECK-NOT: @__msan_va_arg_overflow_size_tls
651 ; CHECK: ret void
652
653
654 ; Test handling of volatile stores.
655 ; Check that MemorySanitizer does not add a check of the value being stored.
656
657 define void @VolatileStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory {
658 entry:
659   store volatile i32 %x, i32* %p, align 4
660   ret void
661 }
662
663 ; CHECK: @VolatileStore
664 ; CHECK-NOT: @__msan_warning
665 ; CHECK: ret void
666
667
668 ; Test that checks are omitted but shadow propagation is kept if
669 ; sanitize_memory attribute is missing.
670
671 define i32 @NoSanitizeMemory(i32 %x) uwtable {
672 entry:
673   %tobool = icmp eq i32 %x, 0
674   br i1 %tobool, label %if.end, label %if.then
675
676 if.then:                                          ; preds = %entry
677   tail call void @bar()
678   br label %if.end
679
680 if.end:                                           ; preds = %entry, %if.then
681   ret i32 %x
682 }
683
684 declare void @bar()
685
686 ; CHECK: @NoSanitizeMemory
687 ; CHECK-NOT: @__msan_warning
688 ; CHECK: load i32* {{.*}} @__msan_param_tls
689 ; CHECK-NOT: @__msan_warning
690 ; CHECK: store {{.*}} @__msan_retval_tls
691 ; CHECK-NOT: @__msan_warning
692 ; CHECK: ret i32
693
694
695 ; Test that stack allocations are unpoisoned in functions missing
696 ; sanitize_memory attribute
697
698 define i32 @NoSanitizeMemoryAlloca() {
699 entry:
700   %p = alloca i32, align 4
701   %x = call i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
702   ret i32 %x
703 }
704
705 declare i32 @NoSanitizeMemoryAllocaHelper(i32* %p)
706
707 ; CHECK: @NoSanitizeMemoryAlloca
708 ; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 4, i32 4, i1 false)
709 ; CHECK: call i32 @NoSanitizeMemoryAllocaHelper(i32*
710 ; CHECK: ret i32
711
712
713 ; Test that undef is unpoisoned in functions missing
714 ; sanitize_memory attribute
715
716 define i32 @NoSanitizeMemoryUndef() {
717 entry:
718   %x = call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
719   ret i32 %x
720 }
721
722 declare i32 @NoSanitizeMemoryUndefHelper(i32 %x)
723
724 ; CHECK: @NoSanitizeMemoryAlloca
725 ; CHECK: store i32 0, i32* {{.*}} @__msan_param_tls
726 ; CHECK: call i32 @NoSanitizeMemoryUndefHelper(i32 undef)
727 ; CHECK: ret i32
728
729
730 ; Test argument shadow alignment
731
732 define <2 x i64> @ArgumentShadowAlignment(i64 %a, <2 x i64> %b) sanitize_memory {
733 entry:
734   ret <2 x i64> %b
735 }
736
737 ; CHECK: @ArgumentShadowAlignment
738 ; CHECK: load <2 x i64>* {{.*}} @__msan_param_tls {{.*}}, align 8
739 ; CHECK: store <2 x i64> {{.*}} @__msan_retval_tls {{.*}}, align 8
740 ; CHECK: ret <2 x i64>
741
742
743 ; Test origin propagation for insertvalue
744
745 define { i64, i32 } @make_pair_64_32(i64 %x, i32 %y) sanitize_memory {
746 entry:
747   %a = insertvalue { i64, i32 } undef, i64 %x, 0
748   %b = insertvalue { i64, i32 } %a, i32 %y, 1
749   ret { i64, i32 } %b
750 }
751
752 ; CHECK-ORIGINS: @make_pair_64_32
753 ; First element shadow
754 ; CHECK-ORIGINS: insertvalue { i64, i32 } { i64 -1, i32 -1 }, i64 {{.*}}, 0
755 ; First element origin
756 ; CHECK-ORIGINS: icmp ne i64
757 ; CHECK-ORIGINS: select i1
758 ; First element app value
759 ; CHECK-ORIGINS: insertvalue { i64, i32 } undef, i64 {{.*}}, 0
760 ; Second element shadow
761 ; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1
762 ; Second element origin
763 ; CHECK-ORIGINS: icmp ne i32
764 ; CHECK-ORIGINS: select i1
765 ; Second element app value
766 ; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1
767 ; CHECK-ORIGINS: ret { i64, i32 }