114 lines · c
1// RUN: %clang_cc1 -fsanitize=implicit-signed-integer-truncation -fsanitize-recover=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_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }13// CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }14// CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }15 16// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int17unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {18#line 10019 return x;20}21 22// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char23unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {24#line 20025 return x;26}27 28// CHECK-LABEL: @convert_signed_int_to_signed_int29signed int convert_signed_int_to_signed_int(signed int x) {30#line 30031 return x;32}33 34// CHECK-LABEL: @convert_signed_char_to_signed_char35signed char convert_signed_char_to_signed_char(signed char x) {36#line 40037 return x;38}39 40// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char41unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {42#line 50043 return x;44}45 46// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int47unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {48#line 60049 return x;50}51 52// CHECK-LABEL: @convert_unsigned_char_to_signed_int53signed int convert_unsigned_char_to_signed_int(unsigned char x) {54#line 70055 return x;56}57 58// CHECK-LABEL: @convert_signed_char_to_signed_int59signed int convert_signed_char_to_signed_int(signed char x) {60#line 80061 return x;62}63 64// CHECK-LABEL: @convert_unsigned_int_to_signed_int65signed int convert_unsigned_int_to_signed_int(unsigned int x) {66#line 90067 return x;68}69 70// CHECK-LABEL: @convert_signed_int_to_unsigned_int71unsigned int convert_signed_int_to_unsigned_int(signed int x) {72#line 100073 return x;74}75 76// CHECK-LABEL: @convert_signed_int_to_unsigned_char77unsigned char convert_signed_int_to_unsigned_char(signed int x) {78 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]79#line 110080 return x;81}82 83// CHECK-LABEL: @convert_signed_char_to_unsigned_char84unsigned char convert_signed_char_to_unsigned_char(signed char x) {85#line 120086 return x;87}88 89// CHECK-LABEL: @convert_unsigned_char_to_signed_char90signed char convert_unsigned_char_to_signed_char(unsigned char x) {91#line 130092 return x;93}94 95// CHECK-LABEL: @convert_signed_char_to_unsigned_int96unsigned int convert_signed_char_to_unsigned_int(signed char x) {97#line 140098 return x;99}100 101// CHECK-LABEL: @convert_unsigned_int_to_signed_char102signed char convert_unsigned_int_to_signed_char(unsigned int x) {103 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1500_SIGNED_TRUNCATION]]104#line 1500105 return x;106}107 108// CHECK-LABEL: @convert_signed_int_to_signed_char109signed char convert_signed_int_to_signed_char(signed int x) {110 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]111#line 1600112 return x;113}114