116 lines · c
1// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-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// CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }14// CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }15// CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }16 17// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int18unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {19#line 10020 return x;21}22 23// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char24unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {25#line 20026 return x;27}28 29// CHECK-LABEL: @convert_signed_int_to_signed_int30signed int convert_signed_int_to_signed_int(signed int x) {31#line 30032 return x;33}34 35// CHECK-LABEL: @convert_signed_char_to_signed_char36signed char convert_signed_char_to_signed_char(signed char x) {37#line 40038 return x;39}40 41// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char42unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {43 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_500_UNSIGNED_TRUNCATION]]44#line 50045 return x;46}47 48// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int49unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {50#line 60051 return x;52}53 54// CHECK-LABEL: @convert_unsigned_char_to_signed_int55signed int convert_unsigned_char_to_signed_int(unsigned char x) {56#line 70057 return x;58}59 60// CHECK-LABEL: @convert_signed_char_to_signed_int61signed int convert_signed_char_to_signed_int(signed char x) {62#line 80063 return x;64}65 66// CHECK-LABEL: @convert_unsigned_int_to_signed_int67signed int convert_unsigned_int_to_signed_int(unsigned int x) {68#line 90069 return x;70}71 72// CHECK-LABEL: @convert_signed_int_to_unsigned_int73unsigned int convert_signed_int_to_unsigned_int(signed int x) {74#line 100075 return x;76}77 78// CHECK-LABEL: @convert_signed_int_to_unsigned_char79unsigned char convert_signed_int_to_unsigned_char(signed int x) {80 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]81#line 110082 return x;83}84 85// CHECK-LABEL: @convert_signed_char_to_unsigned_char86unsigned char convert_signed_char_to_unsigned_char(signed char x) {87#line 120088 return x;89}90 91// CHECK-LABEL: @convert_unsigned_char_to_signed_char92signed char convert_unsigned_char_to_signed_char(unsigned char x) {93#line 130094 return x;95}96 97// CHECK-LABEL: @convert_signed_char_to_unsigned_int98unsigned int convert_signed_char_to_unsigned_int(signed char x) {99#line 1400100 return x;101}102 103// CHECK-LABEL: @convert_unsigned_int_to_signed_char104signed char convert_unsigned_int_to_signed_char(unsigned int x) {105 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1500_SIGNED_TRUNCATION]]106#line 1500107 return x;108}109 110// CHECK-LABEL: @convert_signed_int_to_signed_char111signed char convert_signed_int_to_signed_char(signed int x) {112 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]113#line 1600114 return x;115}116