Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / catch-implicit-integer-conversions-basics.c
blob6bc5472bf39db34d056983ec2051298e14209ec9
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
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 }
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) {
24 #line 100
25 return x;
28 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
29 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
30 #line 200
31 return x;
34 // CHECK-LABEL: @convert_signed_int_to_signed_int
35 signed int convert_signed_int_to_signed_int(signed int x) {
36 #line 300
37 return x;
40 // CHECK-LABEL: @convert_signed_char_to_signed_char
41 signed char convert_signed_char_to_signed_char(signed char x) {
42 #line 400
43 return 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]]
49 #line 500
50 return x;
53 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
54 unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
55 #line 600
56 return x;
59 // CHECK-LABEL: @convert_unsigned_char_to_signed_int
60 signed int convert_unsigned_char_to_signed_int(unsigned char x) {
61 #line 700
62 return x;
65 // CHECK-LABEL: @convert_signed_char_to_signed_int
66 signed int convert_signed_char_to_signed_int(signed char x) {
67 #line 800
68 return 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]]
74 #line 900
75 return x;
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]]
81 #line 1000
82 return x;
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]]
88 #line 1100
89 return x;
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]]
95 #line 1200
96 return x;
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]]
102 #line 1300
103 return x;
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]]
109 #line 1400
110 return x;
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]]
116 #line 1500
117 return x;
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]]
123 #line 1600
124 return x;