[flang] Fix crash in HLFIR generation (#118399)
[llvm-project.git] / clang / test / CodeGen / catch-implicit-integer-truncations-basics.c
blob16320b8822d75922d413372d0eec6fba78113c74
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=CHECK
3 // Test plan:
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, 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 }
17 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
18 unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
19 #line 100
20 return x;
23 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
24 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
25 #line 200
26 return x;
29 // CHECK-LABEL: @convert_signed_int_to_signed_int
30 signed int convert_signed_int_to_signed_int(signed int x) {
31 #line 300
32 return x;
35 // CHECK-LABEL: @convert_signed_char_to_signed_char
36 signed char convert_signed_char_to_signed_char(signed char x) {
37 #line 400
38 return x;
41 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
42 unsigned 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 500
45 return x;
48 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
49 unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
50 #line 600
51 return x;
54 // CHECK-LABEL: @convert_unsigned_char_to_signed_int
55 signed int convert_unsigned_char_to_signed_int(unsigned char x) {
56 #line 700
57 return x;
60 // CHECK-LABEL: @convert_signed_char_to_signed_int
61 signed int convert_signed_char_to_signed_int(signed char x) {
62 #line 800
63 return x;
66 // CHECK-LABEL: @convert_unsigned_int_to_signed_int
67 signed int convert_unsigned_int_to_signed_int(unsigned int x) {
68 #line 900
69 return x;
72 // CHECK-LABEL: @convert_signed_int_to_unsigned_int
73 unsigned int convert_signed_int_to_unsigned_int(signed int x) {
74 #line 1000
75 return x;
78 // CHECK-LABEL: @convert_signed_int_to_unsigned_char
79 unsigned 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 1100
82 return x;
85 // CHECK-LABEL: @convert_signed_char_to_unsigned_char
86 unsigned char convert_signed_char_to_unsigned_char(signed char x) {
87 #line 1200
88 return x;
91 // CHECK-LABEL: @convert_unsigned_char_to_signed_char
92 signed char convert_unsigned_char_to_signed_char(unsigned char x) {
93 #line 1300
94 return x;
97 // CHECK-LABEL: @convert_signed_char_to_unsigned_int
98 unsigned int convert_signed_char_to_unsigned_int(signed char x) {
99 #line 1400
100 return x;
103 // CHECK-LABEL: @convert_unsigned_int_to_signed_char
104 signed 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 1500
107 return x;
110 // CHECK-LABEL: @convert_signed_int_to_signed_char
111 signed 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 1600
114 return x;