diff options
Diffstat (limited to 'test/ubsan')
19 files changed, 1634 insertions, 117 deletions
diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c b/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c new file mode 100644 index 000000000..ef06fbf83 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c @@ -0,0 +1,345 @@ +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 10111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -129 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967167 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c b/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c index d49d04385..5c1530a63 100644 --- a/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c +++ b/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c @@ -27,87 +27,87 @@ // However, not all of them should result in the check. // So here, we *only* check which should and which should not result in checks. -unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) { +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { #line 100 return x; } -unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) { +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { #line 200 return x; } -signed int convert_signed_int_to_signed_int(signed int x) { +int32_t convert_signed_int_to_signed_int(int32_t x) { #line 300 return x; } -signed char convert_signed_char_to_signed_char(signed char x) { +int8_t convert_signed_char_to_signed_char(int8_t x) { #line 400 return x; } -unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) { +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { #line 500 return x; } -unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) { +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { #line 600 return x; } -signed int convert_unsigned_char_to_signed_int(unsigned char x) { +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { #line 700 return x; } -signed int convert_signed_char_to_signed_int(signed char x) { +int32_t convert_signed_char_to_signed_int(int8_t x) { #line 800 return x; } -signed int convert_unsigned_int_to_signed_int(unsigned int x) { +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { #line 900 return x; } -unsigned int convert_signed_int_to_unsigned_int(signed int x) { +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { #line 1000 return x; } -unsigned char convert_signed_int_to_unsigned_char(signed int x) { +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { #line 1100 return x; } -unsigned char convert_signed_char_to_unsigned_char(signed char x) { +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { #line 1200 return x; } -signed char convert_unsigned_char_to_signed_char(unsigned char x) { +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { #line 1300 return x; } -unsigned int convert_signed_char_to_unsigned_int(signed char x) { +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { #line 1400 return x; } -signed char convert_unsigned_int_to_signed_char(unsigned int x) { +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { #line 1500 return x; } -signed char convert_signed_int_to_signed_char(signed int x) { +int8_t convert_signed_int_to_signed_char(int32_t x) { #line 1600 return x; } -#line 1111 // !!! +#line 10111 // !!! int main() { // No bits set. @@ -153,18 +153,24 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); convert_signed_char_to_signed_char((int8_t)UINT8_MAX); convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); -// CHECK-V0: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned +// CHECK-V0: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); convert_signed_char_to_signed_int((int8_t)UINT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); -// CHECK-V0: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V0: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); #elif defined(V1) // Source 'Sign' bit set. @@ -173,21 +179,26 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); convert_signed_char_to_signed_char((int8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'unsigned char' changed the value to 0 (8-bit, unsigned) +// CHECK-V1: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned) +// CHECK-V1: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'signed char' changed the value to 0 (8-bit, signed) +// CHECK-V1: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'signed char' changed the value to 0 (8-bit, signed) +// CHECK-V1: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) #elif defined(V2) // All bits except the source 'Sign' bit are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); @@ -195,21 +206,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); convert_signed_char_to_signed_char((int8_t)INT8_MAX); convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V2: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); convert_signed_char_to_signed_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V2: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V2: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V2: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) #elif defined(V3) // All destination bits set. convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); @@ -224,12 +235,15 @@ int main() { convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); -// CHECK-V3: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 255 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V3: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); -// CHECK-V3: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value 255 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V3: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) #elif defined(V4) // Destination 'sign' bit set. convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); @@ -244,12 +258,15 @@ int main() { convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); -// CHECK-V4: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 128 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V4: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); -// CHECK-V4: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V4: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) #elif defined(V5) // All bits except the destination 'sign' bit are set. convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); @@ -257,21 +274,26 @@ int main() { convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V5: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -129 (32-bit, signed) convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967167 (32-bit, unsigned) convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V5: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V5: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V5: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) #elif defined(V6) // Only the source and destination sign bits are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); @@ -279,21 +301,26 @@ int main() { convert_signed_int_to_signed_int((int32_t)INT32_MIN); convert_signed_char_to_signed_char((int8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); -// CHECK-V6: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'unsigned char' changed the value to 128 (8-bit, unsigned) +// CHECK-V6: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); - convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'unsigned char' changed the value to 128 (8-bit, unsigned) +// CHECK-V6: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V6: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V6: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) #elif defined(V7) // All bits except the source and destination sign bits are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); @@ -301,21 +328,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)INT32_MAX); convert_signed_char_to_signed_char((int8_t)INT8_MAX); convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V7: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); convert_signed_char_to_signed_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); - convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); -// CHECK-V7: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V7: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V7: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V7: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) #else #error Some V* needs to be defined! #endif diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c new file mode 100644 index 000000000..a3a745e5f --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c @@ -0,0 +1,28 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitSignChange" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +#include <stdint.h> + +int32_t implicitSignChange(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}integer-sign-change-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) +} + +int main(int argc, char **argv) { + return implicitSignChange(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-summary.cpp index a92e01fb4..7cdc4c5a1 100644 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-summary.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=implicit-integer-truncation %s -o %t +// RUN: %clangxx -fsanitize=implicit-integer-sign-change %s -o %t // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE // RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE // REQUIRES: !ubsan-standalone && !ubsan-standalone-static @@ -6,8 +6,8 @@ #include <stdint.h> int main() { - uint8_t t0 = (~(uint32_t(0))); + int32_t t0 = (~(uint32_t(0))); // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 - // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-sign-change {{.*}}summary.cpp:[[@LINE-2]]:16 return 0; } diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c new file mode 100644 index 000000000..192c69ade --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c @@ -0,0 +1,297 @@ +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 + +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +//============================================================================// +// Half of the cases do not need the check. // +//============================================================================// + +uint32_t negative0_convert_unsigned_int_to_unsigned_int(uint32_t x) { + return x; +} + +uint8_t negative1_convert_unsigned_char_to_unsigned_char(uint8_t x) { + return x; +} + +int32_t negative2_convert_signed_int_to_signed_int(int32_t x) { + return x; +} + +int8_t negative3_convert_signed_char_to_signed_char(int8_t x) { + return x; +} + +uint8_t negative4_convert_unsigned_int_to_unsigned_char(uint32_t x) { + return x; +} + +uint32_t negative5_convert_unsigned_char_to_unsigned_int(uint8_t x) { + return x; +} + +int32_t negative6_convert_unsigned_char_to_signed_int(uint8_t x) { + return x; +} + +int32_t negative7_convert_signed_char_to_signed_int(int8_t x) { + return x; +} + +void test_negatives() { + // No bits set. + negative0_convert_unsigned_int_to_unsigned_int(0); + negative1_convert_unsigned_char_to_unsigned_char(0); + negative2_convert_signed_int_to_signed_int(0); + negative3_convert_signed_char_to_signed_char(0); + negative4_convert_unsigned_int_to_unsigned_char(0); + negative5_convert_unsigned_char_to_unsigned_int(0); + negative6_convert_unsigned_char_to_signed_int(0); + negative7_convert_signed_char_to_signed_int(0); + + // One lowest bit set. + negative0_convert_unsigned_int_to_unsigned_int(1); + negative1_convert_unsigned_char_to_unsigned_char(1); + negative2_convert_signed_int_to_signed_int(1); + negative3_convert_signed_char_to_signed_char(1); + negative4_convert_unsigned_int_to_unsigned_char(1); + negative5_convert_unsigned_char_to_unsigned_int(1); + negative6_convert_unsigned_char_to_signed_int(1); + negative7_convert_signed_char_to_signed_int(1); + + // All source bits set. + negative0_convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + negative1_convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + negative2_convert_signed_int_to_signed_int((int32_t)INT32_MAX); + negative3_convert_signed_char_to_signed_char((int8_t)INT8_MAX); + negative4_convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + negative5_convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + negative6_convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + negative7_convert_signed_char_to_signed_int((int8_t)INT8_MAX); + + // Source 'sign' bit set. + negative0_convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + negative1_convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + negative2_convert_signed_int_to_signed_int((int32_t)INT32_MIN); + negative3_convert_signed_char_to_signed_char((int8_t)INT8_MIN); + negative4_convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + negative5_convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + negative6_convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + negative7_convert_signed_char_to_signed_int((int8_t)INT8_MIN); +} + +//============================================================================// +// The remaining 8 cases *do* need the check. // +//============================================================================// + +int32_t positive0_convert_unsigned_int_to_signed_int(uint32_t x) { +#line 100 + return x; +} + +uint32_t positive1_convert_signed_int_to_unsigned_int(int32_t x) { +#line 200 + return x; +} + +uint8_t positive2_convert_signed_int_to_unsigned_char(int32_t x) { +#line 300 + return x; +} + +uint8_t positive3_convert_signed_char_to_unsigned_char(int8_t x) { +#line 400 + return x; +} + +int8_t positive4_convert_unsigned_char_to_signed_char(uint8_t x) { +#line 500 + return x; +} + +uint32_t positive5_convert_signed_char_to_unsigned_int(int8_t x) { +#line 600 + return x; +} + +int8_t positive6_convert_unsigned_int_to_signed_char(uint32_t x) { +#line 700 + return x; +} + +int8_t positive7_convert_signed_int_to_signed_char(int32_t x) { +#line 800 + return x; +} + +#line 1120 // !!! + +void test_positives() { + // No bits set. + positive0_convert_unsigned_int_to_signed_int(0); + positive1_convert_signed_int_to_unsigned_int(0); + positive2_convert_signed_int_to_unsigned_char(0); + positive3_convert_signed_char_to_unsigned_char(0); + positive4_convert_unsigned_char_to_signed_char(0); + positive5_convert_signed_char_to_unsigned_int(0); + positive6_convert_unsigned_int_to_signed_char(0); + positive7_convert_signed_int_to_signed_char(0); + + // One lowest bit set. + positive0_convert_unsigned_int_to_signed_int(1); + positive1_convert_signed_int_to_unsigned_int(1); + positive2_convert_signed_int_to_unsigned_char(1); + positive3_convert_signed_char_to_unsigned_char(1); + positive4_convert_unsigned_char_to_signed_char(1); + positive5_convert_signed_char_to_unsigned_int(1); + positive6_convert_unsigned_int_to_signed_char(1); + positive7_convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); + positive7_convert_signed_int_to_signed_char((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); + positive2_convert_signed_int_to_unsigned_char((int32_t)INT32_MAX); + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)UINT8_MAX); + positive3_convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -128 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT32_MIN); + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967168 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)INT8_MIN); +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V5: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V5: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)(INT8_MIN)); +// CHECK-V5: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)(INT8_MIN)); +// CHECK-V5: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)(INT32_MIN)); + positive6_convert_unsigned_int_to_signed_char(~((uint32_t)(uint8_t)INT8_MIN)); + positive7_convert_signed_int_to_signed_char((int32_t)(~((uint32_t)((uint8_t)INT8_MIN)))); +// CHECK-V5: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +#else +#error Some V* needs to be defined! +#endif +} + +// CHECK-NOT: implicit conversion + +int main() { + test_negatives(); + test_positives(); + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c deleted file mode 100644 index a3650e0a9..000000000 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c +++ /dev/null @@ -1,26 +0,0 @@ -// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. -// XFAIL: android -// UNSUPPORTED: ios - -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" - -// RUN: rm -f %tmp -// RUN: echo "[implicit-integer-truncation]" >> %tmp -// RUN: echo "fun:implicitTruncation" >> %tmp -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s - -unsigned char implicitTruncation(unsigned int argc) { - return argc; // BOOM -// CHECK: {{.*}}integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) -} - -int main(int argc, char **argv) { - return implicitTruncation(~0U); -} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c index 34a0f00de..157564871 100644 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c +++ b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c @@ -27,82 +27,82 @@ // However, not all of them should result in the check. // So here, we *only* check which should and which should not result in checks. -unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) { +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { #line 100 return x; } -unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) { +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { #line 200 return x; } -signed int convert_signed_int_to_signed_int(signed int x) { +int32_t convert_signed_int_to_signed_int(int32_t x) { #line 300 return x; } -signed char convert_signed_char_to_signed_char(signed char x) { +int8_t convert_signed_char_to_signed_char(int8_t x) { #line 400 return x; } -unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) { +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { #line 500 return x; } -unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) { +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { #line 600 return x; } -signed int convert_unsigned_char_to_signed_int(unsigned char x) { +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { #line 700 return x; } -signed int convert_signed_char_to_signed_int(signed char x) { +int32_t convert_signed_char_to_signed_int(int8_t x) { #line 800 return x; } -signed int convert_unsigned_int_to_signed_int(unsigned int x) { +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { #line 900 return x; } -unsigned int convert_signed_int_to_unsigned_int(signed int x) { +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { #line 1000 return x; } -unsigned char convert_signed_int_to_unsigned_char(signed int x) { +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { #line 1100 return x; } -unsigned char convert_signed_char_to_unsigned_char(signed char x) { +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { #line 1200 return x; } -signed char convert_unsigned_char_to_signed_char(unsigned char x) { +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { #line 1300 return x; } -unsigned int convert_signed_char_to_unsigned_int(signed char x) { +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { #line 1400 return x; } -signed char convert_unsigned_int_to_signed_char(unsigned int x) { +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { #line 1500 return x; } -signed char convert_signed_int_to_signed_char(signed int x) { +int8_t convert_signed_int_to_signed_char(int32_t x) { #line 1600 return x; } @@ -153,14 +153,14 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); convert_signed_char_to_signed_char((int8_t)UINT8_MAX); convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); -// CHECK-V0: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned +// CHECK-V0: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); convert_signed_char_to_signed_int((int8_t)UINT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); -// CHECK-V0: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V0: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); @@ -173,21 +173,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); convert_signed_char_to_signed_char((int8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'unsigned char' changed the value to 0 (8-bit, unsigned) +// CHECK-V1: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned) +// CHECK-V1: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'signed char' changed the value to 0 (8-bit, signed) +// CHECK-V1: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); -// CHECK-V1: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'signed char' changed the value to 0 (8-bit, signed) +// CHECK-V1: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) #elif defined(V2) // All bits except the source 'Sign' bit are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); @@ -195,21 +195,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); convert_signed_char_to_signed_char((int8_t)INT8_MAX); convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V2: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); convert_signed_char_to_signed_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned) +// CHECK-V2: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V2: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); -// CHECK-V2: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V2: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) #elif defined(V3) // All destination bits set. convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); @@ -227,9 +227,9 @@ int main() { convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); -// CHECK-V3: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 255 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V3: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); -// CHECK-V3: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 255 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed) +// CHECK-V3: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) #elif defined(V4) // Destination 'sign' bit set. convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); @@ -247,9 +247,9 @@ int main() { convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); -// CHECK-V4: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 128 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V4: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); -// CHECK-V4: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V4: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) #elif defined(V5) // All bits except the destination 'sign' bit are set. convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); @@ -257,21 +257,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V5: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V5: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V5: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V5: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V5: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) #elif defined(V6) // Only the source and destination sign bits are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); @@ -279,21 +279,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)INT32_MIN); convert_signed_char_to_signed_char((int8_t)INT8_MIN); convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); -// CHECK-V6: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'unsigned char' changed the value to 128 (8-bit, unsigned) +// CHECK-V6: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); convert_signed_char_to_signed_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'unsigned char' changed the value to 128 (8-bit, unsigned) +// CHECK-V6: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V6: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V6: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed) +// CHECK-V6: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) #elif defined(V7) // All bits except the source and destination sign bits are set. convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); @@ -301,21 +301,21 @@ int main() { convert_signed_int_to_signed_int((int32_t)INT32_MAX); convert_signed_char_to_signed_char((int8_t)INT8_MAX); convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V7: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); convert_signed_char_to_signed_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); -// CHECK-V7: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned) +// CHECK-V7: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V7: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); -// CHECK-V7: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed) +// CHECK-V7: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) #else #error Some V* needs to be defined! #endif diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c new file mode 100644 index 000000000..229f83260 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c @@ -0,0 +1,60 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[integer]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-conversion]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <stdint.h> + +uint8_t implicitUnsignedTruncation(int32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}signed-integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}} (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) +} + +int main(int argc, char **argv) { + return implicitUnsignedTruncation(-1); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c new file mode 100644 index 000000000..0e79df0b5 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c @@ -0,0 +1,58 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// All of these don't actually silence it: + +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation,implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + + +// The only two way it works: + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +#include <stdint.h> + +int8_t implicitConversion(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}signed-integer-truncation-or-sign-change-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +} + +int main(int argc, char **argv) { + return implicitConversion(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp new file mode 100644 index 000000000..13eaef274 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + int8_t t0 = (~(uint32_t(0))); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:15 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-signed-integer-truncation-or-sign-change {{.*}}summary.cpp:[[@LINE-2]]:15 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp new file mode 100644 index 000000000..1da9e3b41 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-signed-integer-truncation %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + uint8_t t0 = int32_t(-1); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-signed-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c new file mode 100644 index 000000000..1ff67eb05 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c @@ -0,0 +1,318 @@ +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 1111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c new file mode 100644 index 000000000..938b7a8c1 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c @@ -0,0 +1,60 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[integer]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-conversion]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <stdint.h> + +uint8_t implicitUnsignedTruncation(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}unsigned-integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) +} + +int main(int argc, char **argv) { + return implicitUnsignedTruncation(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp new file mode 100644 index 000000000..5117dc2a3 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-unsigned-integer-truncation %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + uint8_t t0 = (~(uint32_t(0))); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-unsigned-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c new file mode 100644 index 000000000..49d223ccd --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c @@ -0,0 +1,304 @@ +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 1111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); +// CHECK-V6: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/Integer/no-recover.cpp b/test/ubsan/TestCases/Integer/no-recover.cpp index 515ebbd07..45aeb9e75 100644 --- a/test/ubsan/TestCases/Integer/no-recover.cpp +++ b/test/ubsan/TestCases/Integer/no-recover.cpp @@ -1,7 +1,9 @@ // RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER // RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=all -fsanitize-recover=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER // RUN: %env_ubsan_opts=silence_unsigned_overflow=1 %run %t 2>&1 | FileCheck %s --check-prefix=SILENT-RECOVER --allow-empty -// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT +// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT +// RUN: %env_ubsan_opts=silence_unsigned_overflow=1 not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT #include <stdint.h> diff --git a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp index f24d074a5..13b052386 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp @@ -4,6 +4,7 @@ // // REQUIRES: cxxabi // UNSUPPORTED: windows-msvc +// XFAIL: i386-netbsd struct X { virtual ~X() {} diff --git a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp index 09e9785b9..925373bde 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp @@ -3,6 +3,8 @@ // REQUIRES: cxxabi // UNSUPPORTED: windows-msvc +// Nested crash reported +// UNSUPPORTED: freebsd struct S { virtual int f() { return 0; } }; struct T : virtual S {}; diff --git a/test/ubsan/TestCases/TypeCheck/vptr.cpp b/test/ubsan/TestCases/TypeCheck/vptr.cpp index b4ee22747..67239e82d 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr.cpp @@ -42,6 +42,8 @@ // UNSUPPORTED: android // Compilation error // UNSUPPORTED: openbsd +// Compilation error +// UNSUPPORTED: freebsd #include <new> #include <typeinfo> #include <assert.h> |