110 lines · c
1// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation -fsanitize-recover=implicit-unsigned-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK2 3// Test plan:4// * Two types - int and char5// * Two signs - signed and unsigned6// * Square that - we have input and output types.7// Thus, there are total of (2*2)^2 == 16 tests.8// These are all the possible variations/combinations of casts.9// However, not all of them should result in the check.10// So here, we *only* check which should and which should not result in checks.11 12// CHECK-DAG: @[[LINE_500_UNSIGNED_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, {{.*}}, i8 1, i32 0 }13 14// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int15unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {16#line 10017 return x;18}19 20// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char21unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {22#line 20023 return x;24}25 26// CHECK-LABEL: @convert_signed_int_to_signed_int27signed int convert_signed_int_to_signed_int(signed int x) {28#line 30029 return x;30}31 32// CHECK-LABEL: @convert_signed_char_to_signed_char33signed char convert_signed_char_to_signed_char(signed char x) {34#line 40035 return x;36}37 38// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char39unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {40 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_500_UNSIGNED_TRUNCATION]]41#line 50042 return x;43}44 45// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int46unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {47#line 60048 return x;49}50 51// CHECK-LABEL: @convert_unsigned_char_to_signed_int52signed int convert_unsigned_char_to_signed_int(unsigned char x) {53#line 70054 return x;55}56 57// CHECK-LABEL: @convert_signed_char_to_signed_int58signed int convert_signed_char_to_signed_int(signed char x) {59#line 80060 return x;61}62 63// CHECK-LABEL: @convert_unsigned_int_to_signed_int64signed int convert_unsigned_int_to_signed_int(unsigned int x) {65#line 90066 return x;67}68 69// CHECK-LABEL: @convert_signed_int_to_unsigned_int70unsigned int convert_signed_int_to_unsigned_int(signed int x) {71#line 100072 return x;73}74 75// CHECK-LABEL: @convert_signed_int_to_unsigned_char76unsigned char convert_signed_int_to_unsigned_char(signed int x) {77#line 110078 return x;79}80 81// CHECK-LABEL: @convert_signed_char_to_unsigned_char82unsigned char convert_signed_char_to_unsigned_char(signed char x) {83#line 120084 return x;85}86 87// CHECK-LABEL: @convert_unsigned_char_to_signed_char88signed char convert_unsigned_char_to_signed_char(unsigned char x) {89#line 130090 return x;91}92 93// CHECK-LABEL: @convert_signed_char_to_unsigned_int94unsigned int convert_signed_char_to_unsigned_int(signed char x) {95#line 140096 return x;97}98 99// CHECK-LABEL: @convert_unsigned_int_to_signed_char100signed char convert_unsigned_int_to_signed_char(unsigned int x) {101#line 1500102 return x;103}104 105// CHECK-LABEL: @convert_signed_int_to_signed_char106signed char convert_signed_int_to_signed_char(signed int x) {107#line 1600108 return x;109}110