1 ; RUN: opt < %s -passes=dfsan -dfsan-event-callbacks=true -S | FileCheck %s --check-prefixes=CHECK,EVENT_CALLBACKS
2 ; RUN: opt < %s -passes=dfsan -S | FileCheck %s --check-prefixes=CHECK,FAST
3 ; RUN: opt < %s -passes=dfsan -dfsan-combine-pointer-labels-on-load=false -S | FileCheck %s --check-prefixes=CHECK,NO_COMBINE_LOAD_PTR
4 ; RUN: opt < %s -passes=dfsan -dfsan-combine-pointer-labels-on-store=true -S | FileCheck %s --check-prefixes=CHECK,COMBINE_STORE_PTR
5 ; RUN: opt < %s -passes=dfsan -dfsan-debug-nonzero-labels -S | FileCheck %s --check-prefixes=CHECK,DEBUG_NONZERO_LABELS
6 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"
7 target triple = "x86_64-unknown-linux-gnu"
9 ; CHECK: @__dfsan_arg_tls = external thread_local(initialexec) global [[TLS_ARR:\[100 x i64\]]]
10 ; CHECK: @__dfsan_retval_tls = external thread_local(initialexec) global [[TLS_ARR]]
11 define [4 x i8] @pass_array([4 x i8] %a) {
12 ; NO_COMBINE_LOAD_PTR: @pass_array.dfsan
13 ; NO_COMBINE_LOAD_PTR: %1 = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
14 ; NO_COMBINE_LOAD_PTR: store [4 x i8] %1, ptr @__dfsan_retval_tls, align [[ALIGN]]
16 ; DEBUG_NONZERO_LABELS: @pass_array.dfsan
17 ; DEBUG_NONZERO_LABELS: [[L:%.*]] = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
18 ; DEBUG_NONZERO_LABELS: [[L0:%.*]] = extractvalue [4 x i8] [[L]], 0
19 ; DEBUG_NONZERO_LABELS: [[L1:%.*]] = extractvalue [4 x i8] [[L]], 1
20 ; DEBUG_NONZERO_LABELS: [[L01:%.*]] = or i8 [[L0]], [[L1]]
21 ; DEBUG_NONZERO_LABELS: [[L2:%.*]] = extractvalue [4 x i8] [[L]], 2
22 ; DEBUG_NONZERO_LABELS: [[L012:%.*]] = or i8 [[L01]], [[L2]]
23 ; DEBUG_NONZERO_LABELS: [[L3:%.*]] = extractvalue [4 x i8] [[L]], 3
24 ; DEBUG_NONZERO_LABELS: [[L0123:%.*]] = or i8 [[L012]], [[L3]]
25 ; DEBUG_NONZERO_LABELS: {{.*}} = icmp ne i8 [[L0123]], 0
26 ; DEBUG_NONZERO_LABELS: call void @__dfsan_nonzero_label()
31 %ArrayOfStruct = type [4 x {ptr, i32}]
33 define %ArrayOfStruct @pass_array_of_struct(%ArrayOfStruct %as) {
34 ; NO_COMBINE_LOAD_PTR: @pass_array_of_struct.dfsan
35 ; NO_COMBINE_LOAD_PTR: %1 = load [4 x { i8, i8 }], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
36 ; NO_COMBINE_LOAD_PTR: store [4 x { i8, i8 }] %1, ptr @__dfsan_retval_tls, align [[ALIGN]]
38 ret %ArrayOfStruct %as
41 define ptr @alloca_ret_array() {
42 ; NO_COMBINE_LOAD_PTR: @alloca_ret_array.dfsan
43 ; NO_COMBINE_LOAD_PTR: store i8 0, ptr @__dfsan_retval_tls, align 2
48 define [4 x i1] @load_alloca_array() {
49 ; NO_COMBINE_LOAD_PTR-LABEL: @load_alloca_array.dfsan
50 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R:]] = alloca i8, align 1
51 ; NO_COMBINE_LOAD_PTR-NEXT: %p = alloca [4 x i1]
52 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R+1]] = load i8, ptr %[[#R]], align 1
53 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R+2]] = insertvalue [4 x i8] undef, i8 %[[#R+1]], 0
54 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R+3]] = insertvalue [4 x i8] %[[#R+2]], i8 %[[#R+1]], 1
55 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R+4]] = insertvalue [4 x i8] %[[#R+3]], i8 %[[#R+1]], 2
56 ; NO_COMBINE_LOAD_PTR-NEXT: %[[#R+5]] = insertvalue [4 x i8] %[[#R+4]], i8 %[[#R+1]], 3
57 ; NO_COMBINE_LOAD_PTR-NEXT: %a = load [4 x i1], ptr %p
58 ; NO_COMBINE_LOAD_PTR-NEXT: store [4 x i8] %[[#R+5]], ptr @__dfsan_retval_tls, align 2
59 ; NO_COMBINE_LOAD_PTR-NEXT: ret [4 x i1] %a
62 %a = load [4 x i1], ptr %p
66 define [0 x i1] @load_array0(ptr %p) {
67 ; NO_COMBINE_LOAD_PTR: @load_array0.dfsan
68 ; NO_COMBINE_LOAD_PTR: store [0 x i8] zeroinitializer, ptr @__dfsan_retval_tls, align 2
69 %a = load [0 x i1], ptr %p
73 define [1 x i1] @load_array1(ptr %p) {
74 ; NO_COMBINE_LOAD_PTR: @load_array1.dfsan
75 ; NO_COMBINE_LOAD_PTR: [[L:%.*]] = load i8,
76 ; NO_COMBINE_LOAD_PTR: [[S:%.*]] = insertvalue [1 x i8] undef, i8 [[L]], 0
77 ; NO_COMBINE_LOAD_PTR: store [1 x i8] [[S]], ptr @__dfsan_retval_tls, align 2
79 ; EVENT_CALLBACKS: @load_array1.dfsan
80 ; EVENT_CALLBACKS: [[L:%.*]] = or i8
81 ; EVENT_CALLBACKS: call void @__dfsan_load_callback(i8 zeroext [[L]], ptr {{.*}})
83 ; FAST: @load_array1.dfsan
84 ; FAST: [[P:%.*]] = load i8, ptr @__dfsan_arg_tls, align [[ALIGN:2]]
85 ; FAST: [[L:%.*]] = load i8, ptr {{.*}}, align 1
86 ; FAST: [[U:%.*]] = or i8 [[L]], [[P]]
87 ; FAST: [[S1:%.*]] = insertvalue [1 x i8] undef, i8 [[U]], 0
88 ; FAST: store [1 x i8] [[S1]], ptr @__dfsan_retval_tls, align [[ALIGN]]
90 %a = load [1 x i1], ptr %p
94 define [2 x i1] @load_array2(ptr %p) {
95 ; NO_COMBINE_LOAD_PTR: @load_array2.dfsan
96 ; NO_COMBINE_LOAD_PTR: [[P1:%.*]] = getelementptr i8, ptr [[P0:%.*]], i64 1
97 ; NO_COMBINE_LOAD_PTR-DAG: [[E1:%.*]] = load i8, ptr [[P1]], align 1
98 ; NO_COMBINE_LOAD_PTR-DAG: [[E0:%.*]] = load i8, ptr [[P0]], align 1
99 ; NO_COMBINE_LOAD_PTR: [[U:%.*]] = or i8 [[E0]], [[E1]]
100 ; NO_COMBINE_LOAD_PTR: [[S1:%.*]] = insertvalue [2 x i8] undef, i8 [[U]], 0
101 ; NO_COMBINE_LOAD_PTR: [[S2:%.*]] = insertvalue [2 x i8] [[S1]], i8 [[U]], 1
102 ; NO_COMBINE_LOAD_PTR: store [2 x i8] [[S2]], ptr @__dfsan_retval_tls, align [[ALIGN:2]]
104 ; EVENT_CALLBACKS: @load_array2.dfsan
105 ; EVENT_CALLBACKS: [[O1:%.*]] = or i8
106 ; EVENT_CALLBACKS: [[O2:%.*]] = or i8 [[O1]]
107 ; EVENT_CALLBACKS: call void @__dfsan_load_callback(i8 zeroext [[O2]], ptr {{.*}})
109 ; FAST: @load_array2.dfsan
110 ; FAST: [[P:%.*]] = load i8, ptr @__dfsan_arg_tls, align [[ALIGN:2]]
111 ; FAST: [[O:%.*]] = or i8
112 ; FAST: [[U:%.*]] = or i8 [[O]], [[P]]
113 ; FAST: [[S:%.*]] = insertvalue [2 x i8] undef, i8 [[U]], 0
114 ; FAST: [[S1:%.*]] = insertvalue [2 x i8] [[S]], i8 [[U]], 1
115 ; FAST: store [2 x i8] [[S1]], ptr @__dfsan_retval_tls, align [[ALIGN]]
116 %a = load [2 x i1], ptr %p
120 define [4 x i1] @load_array4(ptr %p) {
121 ; NO_COMBINE_LOAD_PTR: @load_array4.dfsan
122 ; NO_COMBINE_LOAD_PTR: [[T:%.*]] = trunc i32 {{.*}} to i8
123 ; NO_COMBINE_LOAD_PTR: [[S1:%.*]] = insertvalue [4 x i8] undef, i8 [[T]], 0
124 ; NO_COMBINE_LOAD_PTR: [[S2:%.*]] = insertvalue [4 x i8] [[S1]], i8 [[T]], 1
125 ; NO_COMBINE_LOAD_PTR: [[S3:%.*]] = insertvalue [4 x i8] [[S2]], i8 [[T]], 2
126 ; NO_COMBINE_LOAD_PTR: [[S4:%.*]] = insertvalue [4 x i8] [[S3]], i8 [[T]], 3
127 ; NO_COMBINE_LOAD_PTR: store [4 x i8] [[S4]], ptr @__dfsan_retval_tls, align 2
129 ; EVENT_CALLBACKS: @load_array4.dfsan
130 ; EVENT_CALLBACKS: [[O0:%.*]] = or i32
131 ; EVENT_CALLBACKS: [[O1:%.*]] = or i32 [[O0]]
132 ; EVENT_CALLBACKS: [[O2:%.*]] = trunc i32 [[O1]] to i8
133 ; EVENT_CALLBACKS: [[O3:%.*]] = or i8 [[O2]]
134 ; EVENT_CALLBACKS: call void @__dfsan_load_callback(i8 zeroext [[O3]], ptr {{.*}})
136 ; FAST: @load_array4.dfsan
137 ; FAST: [[T:%.*]] = trunc i32 {{.*}} to i8
138 ; FAST: [[O:%.*]] = or i8 [[T]]
139 ; FAST: [[S1:%.*]] = insertvalue [4 x i8] undef, i8 [[O]], 0
140 ; FAST: [[S2:%.*]] = insertvalue [4 x i8] [[S1]], i8 [[O]], 1
141 ; FAST: [[S3:%.*]] = insertvalue [4 x i8] [[S2]], i8 [[O]], 2
142 ; FAST: [[S4:%.*]] = insertvalue [4 x i8] [[S3]], i8 [[O]], 3
143 ; FAST: store [4 x i8] [[S4]], ptr @__dfsan_retval_tls, align 2
145 %a = load [4 x i1], ptr %p
149 define i1 @extract_array([4 x i1] %a) {
150 ; NO_COMBINE_LOAD_PTR: @extract_array.dfsan
151 ; NO_COMBINE_LOAD_PTR: [[AM:%.*]] = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
152 ; NO_COMBINE_LOAD_PTR: [[EM:%.*]] = extractvalue [4 x i8] [[AM]], 2
153 ; NO_COMBINE_LOAD_PTR: store i8 [[EM]], ptr @__dfsan_retval_tls, align 2
154 %e2 = extractvalue [4 x i1] %a, 2
158 define [4 x i1] @insert_array([4 x i1] %a, i1 %e2) {
159 ; NO_COMBINE_LOAD_PTR: @insert_array.dfsan
160 ; NO_COMBINE_LOAD_PTR: [[EM:%.*]] = load i8, ptr
161 ; NO_COMBINE_LOAD_PTR-SAME: inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 4) to ptr), align [[ALIGN:2]]
162 ; NO_COMBINE_LOAD_PTR: [[AM:%.*]] = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN]]
163 ; NO_COMBINE_LOAD_PTR: [[AM1:%.*]] = insertvalue [4 x i8] [[AM]], i8 [[EM]], 0
164 ; NO_COMBINE_LOAD_PTR: store [4 x i8] [[AM1]], ptr @__dfsan_retval_tls, align [[ALIGN]]
165 %a1 = insertvalue [4 x i1] %a, i1 %e2, 0
169 define void @store_alloca_array([4 x i1] %a) {
170 ; FAST: @store_alloca_array.dfsan
171 ; FAST: [[S:%.*]] = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
172 ; FAST: [[SP:%.*]] = alloca i8, align 1
173 ; FAST: [[E0:%.*]] = extractvalue [4 x i8] [[S]], 0
174 ; FAST: [[E1:%.*]] = extractvalue [4 x i8] [[S]], 1
175 ; FAST: [[E01:%.*]] = or i8 [[E0]], [[E1]]
176 ; FAST: [[E2:%.*]] = extractvalue [4 x i8] [[S]], 2
177 ; FAST: [[E012:%.*]] = or i8 [[E01]], [[E2]]
178 ; FAST: [[E3:%.*]] = extractvalue [4 x i8] [[S]], 3
179 ; FAST: [[E0123:%.*]] = or i8 [[E012]], [[E3]]
180 ; FAST: store i8 [[E0123]], ptr [[SP]], align 1
182 store [4 x i1] %a, ptr %p
186 define void @store_zero_array(ptr %p) {
187 ; FAST: @store_zero_array.dfsan
188 ; FAST: store i32 0, ptr {{.*}}
189 store [4 x i1] zeroinitializer, ptr %p
193 define void @store_array2([2 x i1] %a, ptr %p) {
194 ; EVENT_CALLBACKS: @store_array2.dfsan
195 ; EVENT_CALLBACKS: [[E12:%.*]] = or i8
196 ; EVENT_CALLBACKS: call void @__dfsan_store_callback(i8 zeroext [[E12]], ptr %p)
198 ; FAST: @store_array2.dfsan
199 ; FAST: [[S:%.*]] = load [2 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
200 ; FAST: [[E1:%.*]] = extractvalue [2 x i8] [[S]], 0
201 ; FAST: [[E2:%.*]] = extractvalue [2 x i8] [[S]], 1
202 ; FAST: [[E12:%.*]] = or i8 [[E1]], [[E2]]
203 ; FAST: [[SP0:%.*]] = getelementptr i8, ptr [[SP:%.*]], i32 0
204 ; FAST: store i8 [[E12]], ptr [[SP0]], align 1
205 ; FAST: [[SP1:%.*]] = getelementptr i8, ptr [[SP]], i32 1
206 ; FAST: store i8 [[E12]], ptr [[SP1]], align 1
208 ; COMBINE_STORE_PTR: @store_array2.dfsan
209 ; COMBINE_STORE_PTR: [[O:%.*]] = or i8
210 ; COMBINE_STORE_PTR: [[U:%.*]] = or i8 [[O]]
211 ; COMBINE_STORE_PTR: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 0
212 ; COMBINE_STORE_PTR: store i8 [[U]], ptr [[P1]], align 1
213 ; COMBINE_STORE_PTR: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 1
214 ; COMBINE_STORE_PTR: store i8 [[U]], ptr [[P2]], align 1
216 store [2 x i1] %a, ptr %p
220 define void @store_array17([17 x i1] %a, ptr %p) {
221 ; FAST: @store_array17.dfsan
222 ; FAST: %[[#R:]] = load [17 x i8], ptr @__dfsan_arg_tls, align 2
223 ; FAST: %[[#R+1]] = extractvalue [17 x i8] %[[#R]], 0
224 ; FAST: %[[#R+2]] = extractvalue [17 x i8] %[[#R]], 1
225 ; FAST: %[[#R+3]] = or i8 %[[#R+1]], %[[#R+2]]
226 ; FAST: %[[#R+4]] = extractvalue [17 x i8] %[[#R]], 2
227 ; FAST: %[[#R+5]] = or i8 %[[#R+3]], %[[#R+4]]
228 ; FAST: %[[#R+6]] = extractvalue [17 x i8] %[[#R]], 3
229 ; FAST: %[[#R+7]] = or i8 %[[#R+5]], %[[#R+6]]
230 ; FAST: %[[#R+8]] = extractvalue [17 x i8] %[[#R]], 4
231 ; FAST: %[[#R+9]] = or i8 %[[#R+7]], %[[#R+8]]
232 ; FAST: %[[#R+10]] = extractvalue [17 x i8] %[[#R]], 5
233 ; FAST: %[[#R+11]] = or i8 %[[#R+9]], %[[#R+10]]
234 ; FAST: %[[#R+12]] = extractvalue [17 x i8] %[[#R]], 6
235 ; FAST: %[[#R+13]] = or i8 %[[#R+11]], %[[#R+12]]
236 ; FAST: %[[#R+14]] = extractvalue [17 x i8] %[[#R]], 7
237 ; FAST: %[[#R+15]] = or i8 %[[#R+13]], %[[#R+14]]
238 ; FAST: %[[#R+16]] = extractvalue [17 x i8] %[[#R]], 8
239 ; FAST: %[[#R+17]] = or i8 %[[#R+15]], %[[#R+16]]
240 ; FAST: %[[#R+18]] = extractvalue [17 x i8] %[[#R]], 9
241 ; FAST: %[[#R+19]] = or i8 %[[#R+17]], %[[#R+18]]
242 ; FAST: %[[#R+20]] = extractvalue [17 x i8] %[[#R]], 10
243 ; FAST: %[[#R+21]] = or i8 %[[#R+19]], %[[#R+20]]
244 ; FAST: %[[#R+22]] = extractvalue [17 x i8] %[[#R]], 11
245 ; FAST: %[[#R+23]] = or i8 %[[#R+21]], %[[#R+22]]
246 ; FAST: %[[#R+24]] = extractvalue [17 x i8] %[[#R]], 12
247 ; FAST: %[[#R+25]] = or i8 %[[#R+23]], %[[#R+24]]
248 ; FAST: %[[#R+26]] = extractvalue [17 x i8] %[[#R]], 13
249 ; FAST: %[[#R+27]] = or i8 %[[#R+25]], %[[#R+26]]
250 ; FAST: %[[#R+28]] = extractvalue [17 x i8] %[[#R]], 14
251 ; FAST: %[[#R+29]] = or i8 %[[#R+27]], %[[#R+28]]
252 ; FAST: %[[#R+30]] = extractvalue [17 x i8] %[[#R]], 15
253 ; FAST: %[[#R+31]] = or i8 %[[#R+29]], %[[#R+30]]
254 ; FAST: %[[#R+32]] = extractvalue [17 x i8] %[[#R]], 16
255 ; FAST: %[[#R+33]] = or i8 %[[#R+31]], %[[#R+32]]
256 ; FAST: %[[#VREG:]] = insertelement <8 x i8> poison, i8 %[[#R+33]], i32 0
257 ; FAST: %[[#VREG+1]] = insertelement <8 x i8> %[[#VREG]], i8 %[[#R+33]], i32 1
258 ; FAST: %[[#VREG+2]] = insertelement <8 x i8> %[[#VREG+1]], i8 %[[#R+33]], i32 2
259 ; FAST: %[[#VREG+3]] = insertelement <8 x i8> %[[#VREG+2]], i8 %[[#R+33]], i32 3
260 ; FAST: %[[#VREG+4]] = insertelement <8 x i8> %[[#VREG+3]], i8 %[[#R+33]], i32 4
261 ; FAST: %[[#VREG+5]] = insertelement <8 x i8> %[[#VREG+4]], i8 %[[#R+33]], i32 5
262 ; FAST: %[[#VREG+6]] = insertelement <8 x i8> %[[#VREG+5]], i8 %[[#R+33]], i32 6
263 ; FAST: %[[#VREG+7]] = insertelement <8 x i8> %[[#VREG+6]], i8 %[[#R+33]], i32 7
264 ; FAST: %[[#VREG+8]] = getelementptr <8 x i8>, ptr %[[P:.*]], i32 0
265 ; FAST: store <8 x i8> %[[#VREG+7]], ptr %[[#VREG+8]], align 1
266 ; FAST: %[[#VREG+9]] = getelementptr <8 x i8>, ptr %[[P]], i32 1
267 ; FAST: store <8 x i8> %[[#VREG+7]], ptr %[[#VREG+9]], align 1
268 ; FAST: %[[#VREG+10]] = getelementptr i8, ptr %[[P]], i32 16
269 ; FAST: store i8 %[[#R+33]], ptr %[[#VREG+10]], align 1
270 store [17 x i1] %a, ptr %p
274 define [2 x i32] @const_array() {
275 ; FAST: @const_array.dfsan
276 ; FAST: store [2 x i8] zeroinitializer, ptr @__dfsan_retval_tls, align 2
277 ret [2 x i32] [ i32 42, i32 11 ]
280 define [4 x i8] @call_array([4 x i8] %a) {
281 ; FAST-LABEL: @call_array.dfsan
282 ; FAST: %[[#R:]] = load [4 x i8], ptr @__dfsan_arg_tls, align [[ALIGN:2]]
283 ; FAST: store [4 x i8] %[[#R]], ptr @__dfsan_arg_tls, align [[ALIGN]]
284 ; FAST: %_dfsret = load [4 x i8], ptr @__dfsan_retval_tls, align [[ALIGN]]
285 ; FAST: store [4 x i8] %_dfsret, ptr @__dfsan_retval_tls, align [[ALIGN]]
287 %r = call [4 x i8] @pass_array([4 x i8] %a)
291 %LargeArr = type [1000 x i8]
293 define i8 @fun_with_large_args(i1 %i, %LargeArr %a) {
294 ; FAST: @fun_with_large_args.dfsan
295 ; FAST: store i8 0, ptr @__dfsan_retval_tls, align 2
296 %r = extractvalue %LargeArr %a, 0
300 define %LargeArr @fun_with_large_ret() {
301 ; FAST: @fun_with_large_ret.dfsan
302 ; FAST-NEXT: ret [1000 x i8] zeroinitializer
303 ret %LargeArr zeroinitializer
306 define i8 @call_fun_with_large_ret() {
307 ; FAST: @call_fun_with_large_ret.dfsan
308 ; FAST: store i8 0, ptr @__dfsan_retval_tls, align 2
309 %r = call %LargeArr @fun_with_large_ret()
310 %e = extractvalue %LargeArr %r, 0
314 define i8 @call_fun_with_large_args(i1 %i, %LargeArr %a) {
315 ; FAST: @call_fun_with_large_args.dfsan
316 ; FAST: [[I:%.*]] = load i8, ptr @__dfsan_arg_tls, align [[ALIGN:2]]
317 ; FAST: store i8 [[I]], ptr @__dfsan_arg_tls, align [[ALIGN]]
318 ; FAST: %r = call i8 @fun_with_large_args.dfsan(i1 %i, [1000 x i8] %a)
320 %r = call i8 @fun_with_large_args(i1 %i, %LargeArr %a)