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=CHECK
4 // * Two types - int and char
5 // * Two signs - signed and unsigned
6 // * 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.
12 // CHECK-DAG: @[[LINE_500_UNSIGNED_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, {{.*}}, i8 1 }
13 // CHECK-DAG: @[[LINE_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3 }
14 // CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3 }
15 // CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2 }
16 // CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3 }
17 // CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3 }
18 // CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3 }
19 // CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4 }
20 // CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2 }
22 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
23 unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x
) {
28 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
29 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x
) {
34 // CHECK-LABEL: @convert_signed_int_to_signed_int
35 signed int convert_signed_int_to_signed_int(signed int x
) {
40 // CHECK-LABEL: @convert_signed_char_to_signed_char
41 signed char convert_signed_char_to_signed_char(signed char x
) {
46 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
47 unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x
) {
48 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_500_UNSIGNED_TRUNCATION]]
53 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
54 unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x
) {
59 // CHECK-LABEL: @convert_unsigned_char_to_signed_int
60 signed int convert_unsigned_char_to_signed_int(unsigned char x
) {
65 // CHECK-LABEL: @convert_signed_char_to_signed_int
66 signed int convert_signed_char_to_signed_int(signed char x
) {
71 // CHECK-LABEL: @convert_unsigned_int_to_signed_int
72 signed int convert_unsigned_int_to_signed_int(unsigned int x
) {
73 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_900_SIGN_CHANGE]]
78 // CHECK-LABEL: @convert_signed_int_to_unsigned_int
79 unsigned int convert_signed_int_to_unsigned_int(signed int x
) {
80 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1000_SIGN_CHANGE]]
85 // CHECK-LABEL: @convert_signed_int_to_unsigned_char
86 unsigned char convert_signed_int_to_unsigned_char(signed int x
) {
87 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]
92 // CHECK-LABEL: @convert_signed_char_to_unsigned_char
93 unsigned char convert_signed_char_to_unsigned_char(signed char x
) {
94 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1200_SIGN_CHANGE]]
99 // CHECK-LABEL: @convert_unsigned_char_to_signed_char
100 signed char convert_unsigned_char_to_signed_char(unsigned char x
) {
101 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1300_SIGN_CHANGE]]
106 // CHECK-LABEL: @convert_signed_char_to_unsigned_int
107 unsigned int convert_signed_char_to_unsigned_int(signed char x
) {
108 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1400_SIGN_CHANGE]]
113 // CHECK-LABEL: @convert_unsigned_int_to_signed_char
114 signed 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]]
120 // CHECK-LABEL: @convert_signed_int_to_signed_char
121 signed char convert_signed_int_to_signed_char(signed int x
) {
122 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]