1 // RUN: %clang_cc1 -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=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_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }
13 // CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }
14 // CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }
15 // CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }
16 // CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }
17 // CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }
18 // CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4, i32 0 }
19 // CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }
21 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
22 unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x
) {
27 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
28 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x
) {
33 // CHECK-LABEL: @convert_signed_int_to_signed_int
34 signed int convert_signed_int_to_signed_int(signed int x
) {
39 // CHECK-LABEL: @convert_signed_char_to_signed_char
40 signed char convert_signed_char_to_signed_char(signed char x
) {
45 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
46 unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x
) {
51 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
52 unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x
) {
57 // CHECK-LABEL: @convert_unsigned_char_to_signed_int
58 signed int convert_unsigned_char_to_signed_int(unsigned char x
) {
63 // CHECK-LABEL: @convert_signed_char_to_signed_int
64 signed int convert_signed_char_to_signed_int(signed char x
) {
69 // CHECK-LABEL: @convert_unsigned_int_to_signed_int
70 signed int convert_unsigned_int_to_signed_int(unsigned int x
) {
71 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_900_SIGN_CHANGE]]
76 // CHECK-LABEL: @convert_signed_int_to_unsigned_int
77 unsigned int convert_signed_int_to_unsigned_int(signed int x
) {
78 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1000_SIGN_CHANGE]]
83 // CHECK-LABEL: @convert_signed_int_to_unsigned_char
84 unsigned char convert_signed_int_to_unsigned_char(signed int x
) {
85 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]
90 // CHECK-LABEL: @convert_signed_char_to_unsigned_char
91 unsigned char convert_signed_char_to_unsigned_char(signed char x
) {
92 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1200_SIGN_CHANGE]]
97 // CHECK-LABEL: @convert_unsigned_char_to_signed_char
98 signed char convert_unsigned_char_to_signed_char(unsigned char x
) {
99 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1300_SIGN_CHANGE]]
104 // CHECK-LABEL: @convert_signed_char_to_unsigned_int
105 unsigned int convert_signed_char_to_unsigned_int(signed char x
) {
106 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1400_SIGN_CHANGE]]
111 // CHECK-LABEL: @convert_unsigned_int_to_signed_char
112 signed char convert_unsigned_int_to_signed_char(unsigned int x
) {
113 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE]]
118 // CHECK-LABEL: @convert_signed_int_to_signed_char
119 signed char convert_signed_int_to_signed_char(signed int x
) {
120 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]