Fix a miscompile introduced in r220178.
[oota-llvm.git] / test / Instrumentation / MemorySanitizer / array_types.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 define [2 x i32] @InsertValue(i32 %x, i32 %y) sanitize_memory {
8 entry:
9   %a = insertvalue [2 x i32] undef, i32 %x, 0
10   %b = insertvalue [2 x i32] %a, i32 %y, 1
11   ret [2 x i32] %b
12 }
13
14 ; CHECK-LABEL: @InsertValue(
15 ; CHECK-DAG: [[Sy:%.*]] = load i32* {{.*}}@__msan_param_tls to i64), i64 8) to i32*)
16 ; CHECK-DAG: [[Sx:%.*]] = load i32* {{.*}}@__msan_param_tls to i32*)
17 ; CHECK: [[A:%.*]] = insertvalue [2 x i32] [i32 -1, i32 -1], i32 [[Sx]], 0
18 ; CHECK: [[B:%.*]] = insertvalue [2 x i32] [[A]], i32 [[Sy]], 1
19 ; CHECK: store [2 x i32] [[B]], [2 x i32]* {{.*}}@__msan_retval_tls
20 ; CHECK: ret [2 x i32]
21
22
23 define [2 x double] @InsertValueDouble(double %x, double %y) sanitize_memory {
24 entry:
25   %a = insertvalue [2 x double] undef, double %x, 0
26   %b = insertvalue [2 x double] %a, double %y, 1
27   ret [2 x double] %b
28 }
29
30 ; CHECK-LABEL: @InsertValueDouble(
31 ; CHECK-DAG: [[Sy:%.*]] = load i64* {{.*}}@__msan_param_tls to i64), i64 8) to i64*)
32 ; CHECK-DAG: [[Sx:%.*]] = load i64* getelementptr {{.*}}@__msan_param_tls, i32 0, i32 0
33 ; CHECK: [[A:%.*]] = insertvalue [2 x i64] [i64 -1, i64 -1], i64 [[Sx]], 0
34 ; CHECK: [[B:%.*]] = insertvalue [2 x i64] [[A]], i64 [[Sy]], 1
35 ; CHECK: store [2 x i64] [[B]], [2 x i64]* {{.*}}@__msan_retval_tls
36 ; CHECK: ret [2 x double]
37
38
39 define i32 @ExtractValue([2 x i32] %a) sanitize_memory {
40 entry:
41   %x = extractvalue [2 x i32] %a, 1
42   ret i32 %x
43 }
44
45 ; CHECK-LABEL: @ExtractValue(
46 ; CHECK: [[Sa:%.*]] = load [2 x i32]* {{.*}}@__msan_param_tls to [2 x i32]*)
47 ; CHECK: [[Sx:%.*]] = extractvalue [2 x i32] [[Sa]], 1
48 ; CHECK: store i32 [[Sx]], i32* {{.*}}@__msan_retval_tls
49 ; CHECK: ret i32
50
51
52 ; Regression test for PR20493.
53
54 %MyStruct = type { i32, i32, [3 x i32] }
55
56 define i32 @ArrayInStruct(%MyStruct %s) sanitize_memory {
57   %x = extractvalue %MyStruct %s, 2, 1
58   ret i32 %x
59 }
60
61 ; CHECK-LABEL: @ArrayInStruct(
62 ; CHECK: [[Ss:%.*]] = load { i32, i32, [3 x i32] }* {{.*}}@__msan_param_tls to { i32, i32, [3 x i32] }*)
63 ; CHECK: [[Sx:%.*]] = extractvalue { i32, i32, [3 x i32] } [[Ss]], 2, 1
64 ; CHECK: store i32 [[Sx]], i32* {{.*}}@__msan_retval_tls
65 ; CHECK: ret i32
66
67
68 define i32 @ArrayOfStructs([3 x { i32, i32 }] %a) sanitize_memory {
69   %x = extractvalue [3 x { i32, i32 }] %a, 2, 1
70   ret i32 %x
71 }
72
73 ; CHECK-LABEL: @ArrayOfStructs(
74 ; CHECK: [[Ss:%.*]] = load [3 x { i32, i32 }]* {{.*}}@__msan_param_tls to [3 x { i32, i32 }]*)
75 ; CHECK: [[Sx:%.*]] = extractvalue [3 x { i32, i32 }] [[Ss]], 2, 1
76 ; CHECK: store i32 [[Sx]], i32* {{.*}}@__msan_retval_tls
77 ; CHECK: ret i32
78
79
80 define <8 x i16> @ArrayOfVectors([3 x <8 x i16>] %a) sanitize_memory {
81   %x = extractvalue [3 x <8 x i16>] %a, 1
82   ret <8 x i16> %x
83 }
84
85 ; CHECK-LABEL: @ArrayOfVectors(
86 ; CHECK: [[Ss:%.*]] = load [3 x <8 x i16>]* {{.*}}@__msan_param_tls to [3 x <8 x i16>]*)
87 ; CHECK: [[Sx:%.*]] = extractvalue [3 x <8 x i16>] [[Ss]], 1
88 ; CHECK: store <8 x i16> [[Sx]], <8 x i16>* {{.*}}@__msan_retval_tls
89 ; CHECK: ret <8 x i16>