126 lines · c
1// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -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_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }14// CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }15// CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }16// CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }17// CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }18// CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }19// CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4, i32 0 }20// CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }21 22// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int23unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {24#line 10025 return x;26}27 28// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char29unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {30#line 20031 return x;32}33 34// CHECK-LABEL: @convert_signed_int_to_signed_int35signed int convert_signed_int_to_signed_int(signed int x) {36#line 30037 return x;38}39 40// CHECK-LABEL: @convert_signed_char_to_signed_char41signed char convert_signed_char_to_signed_char(signed char x) {42#line 40043 return x;44}45 46// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char47unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {48 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_500_UNSIGNED_TRUNCATION]]49#line 50050 return x;51}52 53// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int54unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {55#line 60056 return x;57}58 59// CHECK-LABEL: @convert_unsigned_char_to_signed_int60signed int convert_unsigned_char_to_signed_int(unsigned char x) {61#line 70062 return x;63}64 65// CHECK-LABEL: @convert_signed_char_to_signed_int66signed int convert_signed_char_to_signed_int(signed char x) {67#line 80068 return x;69}70 71// CHECK-LABEL: @convert_unsigned_int_to_signed_int72signed int convert_unsigned_int_to_signed_int(unsigned int x) {73 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_900_SIGN_CHANGE]]74#line 90075 return x;76}77 78// CHECK-LABEL: @convert_signed_int_to_unsigned_int79unsigned int convert_signed_int_to_unsigned_int(signed int x) {80 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1000_SIGN_CHANGE]]81#line 100082 return x;83}84 85// CHECK-LABEL: @convert_signed_int_to_unsigned_char86unsigned char convert_signed_int_to_unsigned_char(signed int x) {87 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]88#line 110089 return x;90}91 92// CHECK-LABEL: @convert_signed_char_to_unsigned_char93unsigned char convert_signed_char_to_unsigned_char(signed char x) {94 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1200_SIGN_CHANGE]]95#line 120096 return x;97}98 99// CHECK-LABEL: @convert_unsigned_char_to_signed_char100signed char convert_unsigned_char_to_signed_char(unsigned char x) {101 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1300_SIGN_CHANGE]]102#line 1300103 return x;104}105 106// CHECK-LABEL: @convert_signed_char_to_unsigned_int107unsigned int convert_signed_char_to_unsigned_int(signed char x) {108 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1400_SIGN_CHANGE]]109#line 1400110 return x;111}112 113// CHECK-LABEL: @convert_unsigned_int_to_signed_char114signed char convert_unsigned_int_to_signed_char(unsigned int x) {115 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE]]116#line 1500117 return x;118}119 120// CHECK-LABEL: @convert_signed_int_to_signed_char121signed char convert_signed_int_to_signed_char(signed int x) {122 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]123#line 1600124 return x;125}126