1 // REQUIRES: x86-registered-target
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -Wno-constant-conversion -Wno-array-bounds -Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative -Wno-int-to-pointer-cast -fsanitize=array-bounds,enum,float-cast-overflow,integer-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,unsigned-integer-overflow,signed-integer-overflow,shift-base,shift-exponent -O0 -emit-llvm -o - %s | FileCheck %s
4 // The runtime test checking the _BitInt ubsan feature is located in compiler-rt/test/ubsan/TestCases/Integer/bit-int.c
6 typedef unsigned int uint32_t;
7 uint32_t float_divide_by_zero() {
9 // CHECK: constant { i16, i16, [8 x i8] } { i16 1, i16 32, [8 x i8] c"'float'\00" }
10 _BitInt(37) r
= (_BitInt(37))f
;
11 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 13, [20 x i8] c"'_BitInt(37)'\00%\00\00\00\00\00" }
15 uint32_t integer_divide_by_zero() __attribute__((no_sanitize("memory"))) {
16 _BitInt(37) x
= 1 / 0;
17 // CHECK: constant { i16, i16, [32 x i8] } { i16 0, i16 10, [32 x i8] c"'uint32_t' (aka 'unsigned int')\00" }
21 uint32_t implicit_unsigned_integer_truncation() {
22 unsigned _BitInt(37) x
= 2U;
23 x
+= float_divide_by_zero();
24 x
+= integer_divide_by_zero();
25 x
= x
+ 0xFFFFFFFFFFFFFFFFULL
;
26 // CHECK: constant { i16, i16, [23 x i8] } { i16 0, i16 12, [23 x i8] c"'unsigned _BitInt(37)'\00" }
27 uint32_t r
= x
& 0xFFFFFFFF;
31 uint32_t array_bounds() {
33 _BitInt(37) y
= x
[10];
34 // CHECK: constant { i16, i16, [17 x i8] } { i16 -1, i16 0, [17 x i8] c"'_BitInt(37)[4]'\00" }
38 uint32_t float_cast_overflow() {
39 float a
= 100000000.0f
;
40 _BitInt(7) b
= (_BitInt(7))a
;
41 // CHECK: constant { i16, i16, [19 x i8] } { i16 2, i16 7, [19 x i8] c"'_BitInt(7)'\00\07\00\00\00\00\00" }
45 _BitInt(13) implicit_signed_integer_truncation() {
46 _BitInt(73) x
= (_BitInt(73)) ~((~0UL) >> 1);
48 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 {{([[:xdigit:]]{2})}}, [20 x i8] c"'_BitInt(73)'\00I\00\00\00\00\00" }
49 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 9, [20 x i8] c"'_BitInt(13)'\00\0D\00\00\00\00\00" }
52 uint32_t negative_shift1(unsigned _BitInt(37) x
)
53 __attribute__((no_sanitize("memory"))) {
56 // CHECK: constant { i16, i16, [19 x i8] } { i16 2, i16 9, [19 x i8] c"'_BitInt(9)'\00\09\00\00\00\00\00" }
59 uint32_t negative_shift2(unsigned _BitInt(37) x
)
60 __attribute__((no_sanitize("memory"))) {
63 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 11, [20 x i8] c"'_BitInt(17)'\00\11\00\00\00\00\00" }
66 uint32_t negative_shift3(unsigned _BitInt(37) x
)
67 __attribute__((no_sanitize("memory"))) {
70 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 13, [20 x i8] c"'_BitInt(34)'\00\22\00\00\00\00\00" }
73 uint32_t negative_shift5(unsigned _BitInt(37) x
)
74 __attribute__((no_sanitize("memory"))) {
77 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 {{([[:xdigit:]]{2})}}, [20 x i8] c"'_BitInt(68)'\00D\00\00\00\00\00" }