1 ; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck \
3 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
4 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \
5 ; RUN: -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN"
6 ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN
7 ; RUN: opt < %s -msan-check-access-address=1 -S -passes=msan 2>&1 | FileCheck \
8 ; RUN: %s --check-prefix=ADDR
9 ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s --check-prefix=ADDR
11 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"
12 target triple = "x86_64-unknown-linux-gnu"
14 declare void @llvm.masked.store.v4i64.p0v4i64(<4 x i64>, <4 x i64>*, i32, <4 x i1>)
15 declare <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>*, i32, <4 x i1>, <4 x double>)
17 define void @Store(<4 x i64>* %p, <4 x i64> %v, <4 x i1> %mask) sanitize_memory {
19 tail call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %v, <4 x i64>* %p, i32 1, <4 x i1> %mask)
23 ; CHECK-LABEL: @Store(
24 ; CHECK: %[[A:.*]] = load <4 x i64>, {{.*}}@__msan_param_tls to i64), i64 8)
25 ; CHECK-ORIGIN: %[[O:.*]] = load i32, {{.*}}@__msan_param_origin_tls to i64), i64 8)
26 ; CHECK: %[[B:.*]] = ptrtoint <4 x i64>* %p to i64
27 ; CHECK: %[[C:.*]] = xor i64 %[[B]], 87960930222080
28 ; CHECK: %[[D:.*]] = inttoptr i64 %[[C]] to <4 x i64>*
29 ; CHECK-ORIGIN: %[[E:.*]] = add i64 %[[C]], 17592186044416
30 ; CHECK-ORIGIN: %[[F:.*]] = and i64 %[[E]], -4
31 ; CHECK-ORIGIN: %[[G:.*]] = inttoptr i64 %[[F]] to i32*
32 ; CHECK: call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %[[A]], <4 x i64>* %[[D]], i32 1, <4 x i1> %mask)
33 ; CHECK-ORIGIN: store i32 %[[O]], i32* %[[G]], align 4
34 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 1
35 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
36 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 2
37 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
38 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 3
39 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
40 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 4
41 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
42 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 5
43 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
44 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 6
45 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
46 ; CHECK-ORIGIN: getelementptr i32, i32* %[[G]], i32 7
47 ; CHECK-ORIGIN: store i32 %[[O]], i32* {{.*}}, align 4
48 ; CHECK: tail call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %v, <4 x i64>* %p, i32 1, <4 x i1> %mask)
52 ; ADDR: %[[MASKSHADOW:.*]] = load <4 x i1>, {{.*}}@__msan_param_tls to i64), i64 40)
53 ; ADDR: %[[ADDRSHADOW:.*]] = load i64, {{.*}}[100 x i64]* @__msan_param_tls, i32 0, i32 0)
55 ; ADDR: %[[ADDRBAD:.*]] = icmp ne i64 %[[ADDRSHADOW]], 0
56 ; ADDR: br i1 %[[ADDRBAD]], label {{.*}}, label {{.*}}
57 ; ADDR: call void @__msan_warning_noreturn()
59 ; ADDR: %[[MASKSHADOWFLAT:.*]] = bitcast <4 x i1> %[[MASKSHADOW]] to i4
60 ; ADDR: %[[MASKBAD:.*]] = icmp ne i4 %[[MASKSHADOWFLAT]], 0
61 ; ADDR: br i1 %[[MASKBAD]], label {{.*}}, label {{.*}}
62 ; ADDR: call void @__msan_warning_noreturn()
64 ; ADDR: tail call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %v, <4 x i64>* %p, i32 1, <4 x i1> %mask)
68 define <4 x double> @Load(<4 x double>* %p, <4 x double> %v, <4 x i1> %mask) sanitize_memory {
70 %x = call <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>* %p, i32 1, <4 x i1> %mask, <4 x double> %v)
75 ; CHECK: %[[A:.*]] = load <4 x i64>, {{.*}}@__msan_param_tls to i64), i64 8)
76 ; CHECK-ORIGIN: %[[O:.*]] = load i32, {{.*}}@__msan_param_origin_tls to i64), i64 8)
77 ; CHECK: %[[B:.*]] = ptrtoint <4 x double>* %p to i64
78 ; CHECK: %[[C:.*]] = xor i64 %[[B]], 87960930222080
79 ; CHECK: %[[D:.*]] = inttoptr i64 %[[C]] to <4 x i64>*
80 ; CHECK-ORIGIN: %[[E:.*]] = add i64 %[[C]], 17592186044416
81 ; CHECK-ORIGIN: %[[F:.*]] = and i64 %[[E]], -4
82 ; CHECK-ORIGIN: %[[G:.*]] = inttoptr i64 %[[F]] to i32*
83 ; CHECK: %[[E:.*]] = call <4 x i64> @llvm.masked.load.v4i64.p0v4i64(<4 x i64>* %[[D]], i32 1, <4 x i1> %mask, <4 x i64> %[[A]])
84 ; CHECK-ORIGIN: %[[H:.*]] = load i32, i32* %[[G]]
85 ; CHECK-ORIGIN: %[[O2:.*]] = select i1 %{{.*}}, i32 %[[O]], i32 %[[H]]
86 ; CHECK: %[[X:.*]] = call <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>* %p, i32 1, <4 x i1> %mask, <4 x double> %v)
87 ; CHECK: store <4 x i64> %[[E]], {{.*}}@__msan_retval_tls
88 ; CHECK-ORIGIN: store i32 %[[O2]], i32* @__msan_retval_origin_tls
89 ; CHECK: ret <4 x double> %[[X]]
92 ; ADDR: %[[MASKSHADOW:.*]] = load <4 x i1>, {{.*}}@__msan_param_tls to i64), i64 40)
93 ; ADDR: %[[ADDRSHADOW:.*]] = load i64, {{.*}}[100 x i64]* @__msan_param_tls, i32 0, i32 0)
95 ; ADDR: %[[ADDRBAD:.*]] = icmp ne i64 %[[ADDRSHADOW]], 0
96 ; ADDR: br i1 %[[ADDRBAD]], label {{.*}}, label {{.*}}
97 ; ADDR: call void @__msan_warning_noreturn()
99 ; ADDR: %[[MASKSHADOWFLAT:.*]] = bitcast <4 x i1> %[[MASKSHADOW]] to i4
100 ; ADDR: %[[MASKBAD:.*]] = icmp ne i4 %[[MASKSHADOWFLAT]], 0
101 ; ADDR: br i1 %[[MASKBAD]], label {{.*}}, label {{.*}}
102 ; ADDR: call void @__msan_warning_noreturn()
104 ; ADDR: = call <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>* %p, i32 1, <4 x i1> %mask, <4 x double> %v)
105 ; ADDR: ret <4 x double>
107 define void @StoreNoSanitize(<4 x i64>* %p, <4 x i64> %v, <4 x i1> %mask) {
109 tail call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %v, <4 x i64>* %p, i32 1, <4 x i1> %mask)
113 ; CHECK-LABEL: @StoreNoSanitize(
114 ; CHECK: %[[B:.*]] = ptrtoint <4 x i64>* %p to i64
115 ; CHECK: %[[C:.*]] = xor i64 %[[B]], 87960930222080
116 ; CHECK: %[[D:.*]] = inttoptr i64 %[[C]] to <4 x i64>*
117 ; CHECK: call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> zeroinitializer, <4 x i64>* %[[D]], i32 1, <4 x i1> %mask)
118 ; CHECK: tail call void @llvm.masked.store.v4i64.p0v4i64(<4 x i64> %v, <4 x i64>* %p, i32 1, <4 x i1> %mask)
121 define <4 x double> @LoadNoSanitize(<4 x double>* %p, <4 x double> %v, <4 x i1> %mask) {
123 %x = call <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>* %p, i32 1, <4 x i1> %mask, <4 x double> %v)
127 ; CHECK-LABEL: @LoadNoSanitize(
128 ; CHECK: %[[X:.*]] = call <4 x double> @llvm.masked.load.v4f64.p0v4f64(<4 x double>* %p, i32 1, <4 x i1> %mask, <4 x double> %v)
129 ; CHECK: store <4 x i64> zeroinitializer, {{.*}}@__msan_retval_tls to <4 x i64>*)
130 ; CHECK: ret <4 x double> %[[X]]