1 ; RUN: opt < %s -passes=dfsan -dfsan-track-origins=1 -dfsan-abilist=%S/Inputs/abilist.txt -S | FileCheck %s
2 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"
3 target triple = "x86_64-unknown-linux-gnu"
5 ; CHECK: @__dfsan_arg_tls = external thread_local(initialexec) global [[TLS_ARR:\[100 x i64\]]]
6 define i32 @discard(i32 %a, i32 %b) {
10 define i32 @call_discard(i32 %a, i32 %b) {
11 ; CHECK: @call_discard.dfsan
12 ; CHECK: %r = call i32 @discard(i32 %a, i32 %b)
13 ; CHECK: store i32 0, ptr @__dfsan_retval_origin_tls, align 4
16 %r = call i32 @discard(i32 %a, i32 %b)
20 ; CHECK: i32 @functional(i32 %a, i32 %b)
21 define i32 @functional(i32 %a, i32 %b) {
26 define i32 @call_functional(i32 %a, i32 %b) {
27 ; CHECK-LABEL: @call_functional.dfsan
28 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
29 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls
30 ; CHECK: [[RO:%.*]] = select i1 {{.*}}, i32 [[BO]], i32 [[AO]]
31 ; CHECK: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
33 %r = call i32 @functional(i32 %a, i32 %b)
37 define i32 @uninstrumented(i32 %a, i32 %b) {
42 define i32 @call_uninstrumented(i32 %a, i32 %b) {
43 ; CHECK-LABEL: @call_uninstrumented.dfsan
44 ; CHECK: %r = call i32 @uninstrumented(i32 %a, i32 %b)
45 ; CHECK: store i32 0, ptr @__dfsan_retval_origin_tls, align 4
48 %r = call i32 @uninstrumented(i32 %a, i32 %b)
52 define i32 @g(i32 %a, i32 %b) {
57 @discardg = alias i32 (i32, i32), ptr @g
59 define i32 @call_discardg(i32 %a, i32 %b) {
60 ; CHECK: @call_discardg.dfsan
61 ; CHECK: %r = call i32 @discardg(i32 %a, i32 %b)
62 ; CHECK: store i32 0, ptr @__dfsan_retval_origin_tls, align 4
65 %r = call i32 @discardg(i32 %a, i32 %b)
69 define void @custom_without_ret(i32 %a, i32 %b) {
73 define i32 @custom_with_ret(i32 %a, i32 %b) {
78 define void @custom_varg_without_ret(i32 %a, i32 %b, ...) {
82 define i32 @custom_varg_with_ret(i32 %a, i32 %b, ...) {
87 define i32 @custom_cb_with_ret(ptr %cb, i32 %a, i32 %b) {
88 %r = call i32 %cb(i32 %a, i32 %b)
92 define i32 @cb_with_ret(i32 %a, i32 %b) {
97 define void @custom_cb_without_ret(ptr %cb, i32 %a, i32 %b) {
98 call void %cb(i32 %a, i32 %b)
102 define void @cb_without_ret(i32 %a, i32 %b) {
106 define ptr @ret_custom() {
107 ; CHECK: @ret_custom.dfsan
108 ; CHECK: store i32 0, ptr @__dfsan_retval_origin_tls, align 4
110 ret ptr @custom_with_ret
113 define void @call_custom_without_ret(i32 %a, i32 %b) {
114 ; CHECK: @call_custom_without_ret.dfsan
115 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
116 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
117 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
118 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
119 ; CHECK: call void @__dfso_custom_without_ret(i32 %a, i32 %b, i8 zeroext [[AS]], i8 zeroext [[BS]], i32 zeroext [[AO]], i32 zeroext [[BO]])
120 ; CHECK-NEXT: ret void
122 call void @custom_without_ret(i32 %a, i32 %b)
126 define i32 @call_custom_with_ret(i32 %a, i32 %b) {
127 ; CHECK: @call_custom_with_ret.dfsan
128 ; CHECK: %originreturn = alloca i32, align 4
129 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
130 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
131 ; CHECK: %labelreturn = alloca i8, align 1
132 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
133 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
134 ; CHECK: {{.*}} = call i32 @__dfso_custom_with_ret(i32 %a, i32 %b, i8 zeroext [[AS]], i8 zeroext [[BS]], ptr %labelreturn, i32 zeroext [[AO]], i32 zeroext [[BO]], ptr %originreturn)
135 ; CHECK: [[RS:%.*]] = load i8, ptr %labelreturn, align 1
136 ; CHECK: [[RO:%.*]] = load i32, ptr %originreturn, align 4
137 ; CHECK: store i8 [[RS]], ptr @__dfsan_retval_tls, align 2
138 ; CHECK: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
140 %r = call i32 @custom_with_ret(i32 %a, i32 %b)
144 define void @call_custom_varg_without_ret(i32 %a, i32 %b) {
145 ; CHECK: @call_custom_varg_without_ret.dfsan
146 ; CHECK: %originva = alloca [1 x i32], align 4
147 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
148 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
149 ; CHECK: %labelva = alloca [1 x i8], align 1
150 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
151 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
152 ; CHECK: [[VS0:%.*]] = getelementptr inbounds nuw [1 x i8], ptr %labelva, i32 0, i32 0
153 ; CHECK: store i8 [[AS]], ptr [[VS0]], align 1
154 ; CHECK: [[VS0:%.*]] = getelementptr inbounds nuw [1 x i8], ptr %labelva, i32 0, i32 0
155 ; CHECK: [[VO0:%.*]] = getelementptr inbounds nuw [1 x i32], ptr %originva, i32 0, i32 0
156 ; CHECK: store i32 [[AO]], ptr [[VO0]], align 4
157 ; CHECK: [[VO0:%.*]] = getelementptr inbounds nuw [1 x i32], ptr %originva, i32 0, i32 0
158 ; CHECK: call void (i32, i32, i8, i8, ptr, i32, i32, ptr, ...) @__dfso_custom_varg_without_ret(i32 %a, i32 %b, i8 zeroext [[AS]], i8 zeroext [[BS]], ptr [[VS0]], i32 zeroext [[AO]], i32 zeroext [[BO]], ptr [[VO0]], i32 %a)
159 ; CHECK-NEXT: ret void
161 call void (i32, i32, ...) @custom_varg_without_ret(i32 %a, i32 %b, i32 %a)
165 define i32 @call_custom_varg_with_ret(i32 %a, i32 %b) {
166 ; CHECK: @call_custom_varg_with_ret.dfsan
167 ; CHECK: %originreturn = alloca i32, align 4
168 ; CHECK: %originva = alloca [1 x i32], align 4
169 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
170 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls
171 ; CHECK: %labelreturn = alloca i8, align 1
172 ; CHECK: %labelva = alloca [1 x i8], align 1
173 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
174 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
175 ; CHECK: [[VS0:%.*]] = getelementptr inbounds nuw [1 x i8], ptr %labelva, i32 0, i32 0
176 ; CHECK: store i8 [[BS]], ptr [[VS0]], align 1
177 ; CHECK: [[VS0:%.*]] = getelementptr inbounds nuw [1 x i8], ptr %labelva, i32 0, i32 0
178 ; CHECK: [[VO0:%.*]] = getelementptr inbounds nuw [1 x i32], ptr %originva, i32 0, i32 0
179 ; CHECK: store i32 [[BO]], ptr [[VO0]], align 4
180 ; CHECK: [[VO0:%.*]] = getelementptr inbounds nuw [1 x i32], ptr %originva, i32 0, i32 0
181 ; CHECK: {{.*}} = call i32 (i32, i32, i8, i8, ptr, ptr, i32, i32, ptr, ptr, ...) @__dfso_custom_varg_with_ret(i32 %a, i32 %b, i8 zeroext [[AS]], i8 zeroext [[BS]], ptr [[VS0]], ptr %labelreturn, i32 zeroext [[AO]], i32 zeroext [[BO]], ptr [[VO0]], ptr %originreturn, i32 %b)
182 ; CHECK: [[RS:%.*]] = load i8, ptr %labelreturn, align 1
183 ; CHECK: [[RO:%.*]] = load i32, ptr %originreturn, align 4
184 ; CHECK: store i8 [[RS]], ptr @__dfsan_retval_tls, align 2
185 ; CHECK: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
187 %r = call i32 (i32, i32, ...) @custom_varg_with_ret(i32 %a, i32 %b, i32 %b)
191 define i32 @call_custom_cb_with_ret(i32 %a, i32 %b) {
192 ; CHECK: @call_custom_cb_with_ret.dfsan
193 ; CHECK: %originreturn = alloca i32, align 4
194 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
195 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
196 ; CHECK: %labelreturn = alloca i8, align 1
197 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
198 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
199 ; CHECK: {{.*}} = call i32 @__dfso_custom_cb_with_ret(ptr @cb_with_ret.dfsan, i32 %a, i32 %b, i8 zeroext 0, i8 zeroext [[AS]], i8 zeroext [[BS]], ptr %labelreturn, i32 zeroext 0, i32 zeroext [[AO]], i32 zeroext [[BO]], ptr %originreturn)
200 ; CHECK: [[RS:%.*]] = load i8, ptr %labelreturn, align 1
201 ; CHECK: [[RO:%.*]] = load i32, ptr %originreturn, align 4
202 ; CHECK: store i8 [[RS]], ptr @__dfsan_retval_tls, align 2
203 ; CHECK: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
205 %r = call i32 @custom_cb_with_ret(ptr @cb_with_ret, i32 %a, i32 %b)
209 define void @call_custom_cb_without_ret(i32 %a, i32 %b) {
210 ; CHECK-LABEL: @call_custom_cb_without_ret.dfsan
211 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
212 ; CHECK: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
213 ; CHECK: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
214 ; CHECK: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
215 ; CHECK: call void @__dfso_custom_cb_without_ret(ptr @cb_without_ret.dfsan, i32 %a, i32 %b, i8 zeroext 0, i8 zeroext [[AS]], i8 zeroext [[BS]], i32 zeroext 0, i32 zeroext [[AO]], i32 zeroext [[BO]])
216 ; CHECK-NEXT: ret void
218 call void @custom_cb_without_ret(ptr @cb_without_ret, i32 %a, i32 %b)
222 ; CHECK: define i32 @discardg(i32 %0, i32 %1)
223 ; CHECK: [[R:%.*]] = call i32 @g.dfsan
224 ; CHECK-NEXT: %_dfsret = load i8, ptr @__dfsan_retval_tls, align 2
225 ; CHECK-NEXT: %_dfsret_o = load i32, ptr @__dfsan_retval_origin_tls, align 4
226 ; CHECK-NEXT: ret i32 [[R]]
228 ; CHECK: define linkonce_odr void @"dfso$custom_without_ret"(i32 %0, i32 %1)
229 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
230 ; CHECK-NEXT: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
231 ; CHECK-NEXT: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
232 ; CHECK-NEXT: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
233 ; CHECK-NEXT: call void @__dfso_custom_without_ret(i32 %0, i32 %1, i8 zeroext [[AS]], i8 zeroext [[BS]], i32 zeroext [[AO]], i32 zeroext [[BO]])
234 ; CHECK-NEXT: ret void
236 ; CHECK: define linkonce_odr i32 @"dfso$custom_with_ret"(i32 %0, i32 %1)
237 ; CHECK: %originreturn = alloca i32, align 4
238 ; CHECK-NEXT: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
239 ; CHECK-NEXT: [[AO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
240 ; CHECK-NEXT: %labelreturn = alloca i8, align 1
241 ; CHECK-NEXT: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
242 ; CHECK-NEXT: [[AS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
243 ; CHECK-NEXT: [[R:%.*]] = call i32 @__dfso_custom_with_ret(i32 %0, i32 %1, i8 zeroext [[AS]], i8 zeroext [[BS]], ptr %labelreturn, i32 zeroext [[AO]], i32 zeroext [[BO]], ptr %originreturn)
244 ; CHECK-NEXT: [[RS:%.*]] = load i8, ptr %labelreturn, align 1
245 ; CHECK-NEXT: [[RO:%.*]] = load i32, ptr %originreturn, align 4
246 ; CHECK-NEXT: store i8 [[RS]], ptr @__dfsan_retval_tls, align 2
247 ; CHECK-NEXT: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
248 ; CHECK-NEXT: ret i32 [[R]]
250 ; CHECK: define linkonce_odr void @"dfso$custom_varg_without_ret"(i32 %0, i32 %1, ...)
251 ; CHECK: call void @__dfsan_vararg_wrapper(ptr @0)
252 ; CHECK-NEXT: unreachable
254 ; CHECK: define linkonce_odr i32 @"dfso$custom_varg_with_ret"(i32 %0, i32 %1, ...)
255 ; CHECK: call void @__dfsan_vararg_wrapper(ptr @1)
256 ; CHECK-NEXT: unreachable
258 ; CHECK: define linkonce_odr i32 @"dfso$custom_cb_with_ret"(ptr %0, i32 %1, i32 %2)
259 ; CHECK: %originreturn = alloca i32, align 4
260 ; CHECK-NEXT: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 2), align 4
261 ; CHECK-NEXT: [[AO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
262 ; CHECK-NEXT: [[CO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
263 ; CHECK-NEXT: %labelreturn = alloca i8, align 1
264 ; CHECK-NEXT: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 4) to ptr), align 2
265 ; CHECK-NEXT: [[AS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
266 ; CHECK-NEXT: [[CS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
267 ; CHECK-NEXT: [[R:%.*]] = call i32 @__dfso_custom_cb_with_ret(ptr %0, i32 %1, i32 %2, i8 zeroext [[CS]], i8 zeroext [[AS]], i8 zeroext [[BS]], ptr %labelreturn, i32 zeroext [[CO]], i32 zeroext [[AO]], i32 zeroext [[BO]], ptr %originreturn)
268 ; CHECK-NEXT: [[RS:%.*]] = load i8, ptr %labelreturn, align 1
269 ; CHECK-NEXT: [[RO:%.*]] = load i32, ptr %originreturn, align 4
270 ; CHECK-NEXT: store i8 [[RS]], ptr @__dfsan_retval_tls, align 2
271 ; CHECK-NEXT: store i32 [[RO]], ptr @__dfsan_retval_origin_tls, align 4
272 ; CHECK-NEXT: ret i32 [[R]]
274 ; CHECK: define linkonce_odr void @"dfso$custom_cb_without_ret"(ptr %0, i32 %1, i32 %2)
275 ; CHECK: [[BO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 2), align 4
276 ; CHECK-NEXT: [[AO:%.*]] = load i32, ptr getelementptr inbounds ([200 x i32], ptr @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
277 ; CHECK-NEXT: [[CO:%.*]] = load i32, ptr @__dfsan_arg_origin_tls, align 4
278 ; CHECK-NEXT: [[BS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 4) to ptr), align 2
279 ; CHECK-NEXT: [[AS:%.*]] = load i8, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__dfsan_arg_tls to i64), i64 2) to ptr), align 2
280 ; CHECK-NEXT: [[CS:%.*]] = load i8, ptr @__dfsan_arg_tls, align 2
281 ; CHECK-NEXT: call void @__dfso_custom_cb_without_ret(ptr %0, i32 %1, i32 %2, i8 zeroext [[CS]], i8 zeroext [[AS]], i8 zeroext [[BS]], i32 zeroext [[CO]], i32 zeroext [[AO]], i32 zeroext [[BO]])
282 ; CHECK-NEXT: ret void
284 ; CHECK: declare void @__dfso_custom_without_ret(i32, i32, i8, i8, i32, i32)
286 ; CHECK: declare i32 @__dfso_custom_with_ret(i32, i32, i8, i8, ptr, i32, i32, ptr)
288 ; CHECK: declare i32 @__dfso_custom_cb_with_ret(ptr, i32, i32, i8, i8, i8, ptr, i32, i32, i32, ptr)
290 ; CHECK: declare void @__dfso_custom_cb_without_ret(ptr, i32, i32, i8, i8, i8, i32, i32, i32)
292 ; CHECK: declare void @__dfso_custom_varg_without_ret(i32, i32, i8, i8, ptr, i32, i32, ptr, ...)
294 ; CHECK: declare i32 @__dfso_custom_varg_with_ret(i32, i32, i8, i8, ptr, ptr, i32, i32, ptr, ptr, ...)