1 // RUN: %clang_cc1 -x c -S -emit-llvm -o - -triple x86_64-apple-darwin10 %s \
2 // RUN: -w -fsanitize=signed-integer-overflow,unsigned-integer-overflow,integer-divide-by-zero,float-divide-by-zero \
5 // CHECK-LABEL: define{{.*}} void @foo
6 // CHECK-NOT: !nosanitize
7 void foo(const int *p
) {
8 // __builtin_prefetch expects its optional arguments to be constant integers.
9 // Check that ubsan does not instrument any safe arithmetic performed in
10 // operands to __builtin_prefetch. (A clang frontend check should reject
11 // unsafe arithmetic in these operands.)
13 __builtin_prefetch(p
, 0 + 1, 0 + 3);
14 __builtin_prefetch(p
, 1 - 0, 3 - 0);
15 __builtin_prefetch(p
, 1 * 1, 1 * 3);
16 __builtin_prefetch(p
, 1 / 1, 3 / 1);
17 __builtin_prefetch(p
, 3 % 2, 3 % 1);
19 __builtin_prefetch(p
, 0U + 1U, 0U + 3U);
20 __builtin_prefetch(p
, 1U - 0U, 3U - 0U);
21 __builtin_prefetch(p
, 1U * 1U, 1U * 3U);
22 __builtin_prefetch(p
, 1U / 1U, 3U / 1U);
23 __builtin_prefetch(p
, 3U % 2U, 3U % 1U);
26 // CHECK-LABEL: define{{.*}} void @ub_constant_arithmetic
27 void ub_constant_arithmetic(void) {
28 // Check that we still instrument unsafe arithmetic, even if it is known to
29 // be unsafe at compile time.
31 int INT_MIN
= 0xffffffff;
32 int INT_MAX
= 0x7fffffff;
34 // CHECK: call void @__ubsan_handle_add_overflow
35 // CHECK: call void @__ubsan_handle_add_overflow
39 // CHECK: call void @__ubsan_handle_negate_overflow
40 // CHECK: call void @__ubsan_handle_sub_overflow
44 // CHECK: call void @__ubsan_handle_mul_overflow
45 // CHECK: call void @__ubsan_handle_mul_overflow
49 // CHECK: call void @__ubsan_handle_divrem_overflow
50 // CHECK: call void @__ubsan_handle_divrem_overflow
54 // CHECK: call void @__ubsan_handle_divrem_overflow
55 // CHECK: call void @__ubsan_handle_divrem_overflow
59 // CHECK: call void @__ubsan_handle_divrem_overflow