Files
clang-p2996/compiler-rt/test/ubsan/TestCases/ImplicitConversion/integer-conversion-incdec.c
Martin Storsjö 2ce71b2c18 [compiler-rt] [test] Use %clangxx for tests that use -x c++
When instrumenting C++ code, ubsan ends up referencing
the ubsan_type_hash_* object files, which require linking against
the C++ ABI library. When building with "clang -x c++", the code
is handled as C++, but the compiler still only links as if it was
C.

Change all cases of "%clang -x c++" into "%clangxx -x c++".

This fixes a lot of ubsan tests in mingw mode.

Differential Revision: https://reviews.llvm.org/D147687
2023-04-11 00:02:33 +03:00

123 lines
3.7 KiB
C

// RUN: %clang -x c -fsanitize=implicit-conversion -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clang -x c -fsanitize=implicit-conversion -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clang -x c -fsanitize=implicit-conversion -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clang -x c -fsanitize=implicit-conversion -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clangxx -x c++ -fsanitize=implicit-conversion -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clangxx -x c++ -fsanitize=implicit-conversion -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clangxx -x c++ -fsanitize=implicit-conversion -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
// RUN: %clangxx -x c++ -fsanitize=implicit-conversion -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK
void test_unsigned() {
unsigned char x;
x = 0;
x++;
x = 0;
++x;
x = 0;
x--;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:4: 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)
x = 0;
--x;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:3: 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)
x = 1;
x++;
x = 1;
++x;
x = 1;
x--;
x = 1;
--x;
x = 254;
x++;
x = 254;
++x;
x = 254;
x--;
x = 254;
--x;
x = 255;
x++;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:4: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
x = 255;
++x;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
x = 255;
x--;
x = 255;
--x;
}
void test_signed() {
signed char x;
x = -128;
x++;
x = -128;
++x;
x = -128;
x--;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:4: 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)
x = -128;
--x;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:3: 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)
x = -1;
x++;
x = -1;
++x;
x = -1;
x--;
x = -1;
--x;
x = 0;
x++;
x = 0;
++x;
x = 0;
x--;
x = 0;
--x;
x = 1;
x++;
x = 1;
++x;
x = 1;
x--;
x = 1;
--x;
x = 127;
x++;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:4: 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)
x = 127;
++x;
// CHECK: {{.*}}integer-conversion-incdec.c:[[@LINE-1]]:3: 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)
x = 127;
x--;
x = 127;
--x;
}
int main() {
test_unsigned();
test_signed();
return 0;
}