1// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
2// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1
3// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2
4// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
5// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
6// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5
7// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6
8// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
9
10// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
11// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1
12// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2
13// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
14// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
15// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5
16// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6
17// RUN: %clangxx -x c++ -fsanitize=implicit-conversion %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
18
19#include <stdint.h>
20
21// Test plan:
22// * Two types - int and char
23// * Two signs - signed and unsigned
24// * Square that - we have input and output types.
25// Thus, there are total of (2*2)^2 == 16 tests.
26// These are all the possible variations/combinations of casts.
27// However, not all of them should result in the check.
28// So here, we *only* check which should and which should not result in checks.
29
30uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) {
31#line 100
32 return x;
33}
34
35uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) {
36#line 200
37 return x;
38}
39
40int32_t convert_signed_int_to_signed_int(int32_t x) {
41#line 300
42 return x;
43}
44
45int8_t convert_signed_char_to_signed_char(int8_t x) {
46#line 400
47 return x;
48}
49
50uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) {
51#line 500
52 return x;
53}
54
55uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) {
56#line 600
57 return x;
58}
59
60int32_t convert_unsigned_char_to_signed_int(uint8_t x) {
61#line 700
62 return x;
63}
64
65int32_t convert_signed_char_to_signed_int(int8_t x) {
66#line 800
67 return x;
68}
69
70int32_t convert_unsigned_int_to_signed_int(uint32_t x) {
71#line 900
72 return x;
73}
74
75uint32_t convert_signed_int_to_unsigned_int(int32_t x) {
76#line 1000
77 return x;
78}
79
80uint8_t convert_signed_int_to_unsigned_char(int32_t x) {
81#line 1100
82 return x;
83}
84
85uint8_t convert_signed_char_to_unsigned_char(int8_t x) {
86#line 1200
87 return x;
88}
89
90int8_t convert_unsigned_char_to_signed_char(uint8_t x) {
91#line 1300
92 return x;
93}
94
95uint32_t convert_signed_char_to_unsigned_int(int8_t x) {
96#line 1400
97 return x;
98}
99
100int8_t convert_unsigned_int_to_signed_char(uint32_t x) {
101#line 1500
102 return x;
103}
104
105int8_t convert_signed_int_to_signed_char(int32_t x) {
106#line 1600
107 return x;
108}
109
110#line 10111 // !!!
111
112int main() {
113 // No bits set.
114 convert_unsigned_int_to_unsigned_int(x: 0);
115 convert_unsigned_char_to_unsigned_char(x: 0);
116 convert_signed_int_to_signed_int(x: 0);
117 convert_signed_char_to_signed_char(x: 0);
118 convert_unsigned_int_to_unsigned_char(x: 0);
119 convert_unsigned_char_to_unsigned_int(x: 0);
120 convert_unsigned_char_to_signed_int(x: 0);
121 convert_signed_char_to_signed_int(x: 0);
122 convert_unsigned_int_to_signed_int(x: 0);
123 convert_signed_int_to_unsigned_int(x: 0);
124 convert_signed_int_to_unsigned_char(x: 0);
125 convert_signed_char_to_unsigned_char(x: 0);
126 convert_unsigned_char_to_signed_char(x: 0);
127 convert_signed_char_to_unsigned_int(x: 0);
128 convert_unsigned_int_to_signed_char(x: 0);
129 convert_signed_int_to_signed_char(x: 0);
130
131 // One lowest bit set.
132 convert_unsigned_int_to_unsigned_int(x: 1);
133 convert_unsigned_char_to_unsigned_char(x: 1);
134 convert_signed_int_to_signed_int(x: 1);
135 convert_signed_char_to_signed_char(x: 1);
136 convert_unsigned_int_to_unsigned_char(x: 1);
137 convert_unsigned_char_to_unsigned_int(x: 1);
138 convert_unsigned_char_to_signed_int(x: 1);
139 convert_signed_char_to_signed_int(x: 1);
140 convert_unsigned_int_to_signed_int(x: 1);
141 convert_signed_int_to_unsigned_int(x: 1);
142 convert_signed_int_to_unsigned_char(x: 1);
143 convert_signed_char_to_unsigned_char(x: 1);
144 convert_unsigned_char_to_signed_char(x: 1);
145 convert_signed_char_to_unsigned_int(x: 1);
146 convert_unsigned_int_to_signed_char(x: 1);
147 convert_signed_int_to_signed_char(x: 1);
148
149#if defined(V0)
150 // All source bits set.
151 convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX);
152 convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
153 convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX);
154 convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
155 convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX);
156// CHECK-V0: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned
157 convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
158 convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
159 convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
160 convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX);
161// CHECK-V0: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed)
162 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX);
163// CHECK-V0: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned)
164 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX);
165// CHECK-V0: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
166 convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
167// CHECK-V0: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
168 convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
169// CHECK-V0: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
170 convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
171// CHECK-V0: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned)
172 convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX);
173// CHECK-V0: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
174 convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX);
175#elif defined(V1)
176 // Source 'Sign' bit set.
177 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
178 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
179 convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN);
180 convert_signed_char_to_signed_char((int8_t)INT8_MIN);
181 convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN);
182// CHECK-V1: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned)
183 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
184 convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
185 convert_signed_char_to_signed_int((int8_t)INT8_MIN);
186 convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
187// CHECK-V1: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed)
188 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN);
189// CHECK-V1: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned)
190 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN);
191// CHECK-V1: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned)
192 convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
193// CHECK-V1: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
194 convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
195// CHECK-V1: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
196 convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
197// CHECK-V1: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned)
198 convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN);
199// CHECK-V1: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 0 (8-bit, signed)
200 convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN);
201// CHECK-V1: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 0 (8-bit, signed)
202#elif defined(V2)
203 // All bits except the source 'Sign' bit are set.
204 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
205 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
206 convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX);
207 convert_signed_char_to_signed_char((int8_t)INT8_MAX);
208 convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX);
209// CHECK-V2: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
210 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
211 convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
212 convert_signed_char_to_signed_int((int8_t)INT8_MAX);
213 convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
214 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX);
215 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX);
216// CHECK-V2: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
217 convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
218 convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
219 convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
220 convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX);
221// CHECK-V2: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
222 convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX);
223// CHECK-V2: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
224#elif defined(V3)
225 // All destination bits set.
226 convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX);
227 convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
228 convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX);
229 convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
230 convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX);
231 convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
232 convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
233 convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
234 convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX);
235 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX);
236 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX);
237 convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
238// CHECK-V3: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
239 convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
240// CHECK-V3: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
241 convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
242// CHECK-V3: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned)
243 convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX);
244// CHECK-V3: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
245 convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX);
246// CHECK-V3: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -1 (8-bit, signed)
247#elif defined(V4)
248 // Destination 'sign' bit set.
249 convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN);
250 convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
251 convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
252 convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
253 convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN);
254 convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
255 convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
256 convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
257 convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN);
258 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
259 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
260 convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
261// CHECK-V4: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
262 convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
263// CHECK-V4: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
264 convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
265// CHECK-V4: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned)
266 convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN);
267// CHECK-V4: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
268 convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
269// CHECK-V4: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
270#elif defined(V5)
271 // All bits except the destination 'sign' bit are set.
272 convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN)));
273 convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
274 convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
275 convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
276 convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN)));
277// CHECK-V5: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned)
278 convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
279 convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
280 convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
281 convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN)));
282// CHECK-V5: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -129 (32-bit, signed)
283 convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
284// CHECK-V5: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967167 (32-bit, unsigned)
285 convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
286// CHECK-V5: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned)
287 convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
288// CHECK-V5: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
289 convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
290// CHECK-V5: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
291 convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
292// CHECK-V5: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned)
293 convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN)));
294// CHECK-V5: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 127 (8-bit, signed)
295 convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
296// CHECK-V5: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 127 (8-bit, signed)
297#elif defined(V6)
298 // Only the source and destination sign bits are set.
299 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
300 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
301 convert_signed_int_to_signed_int((int32_t)INT32_MIN);
302 convert_signed_char_to_signed_char((int8_t)INT8_MIN);
303 convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN));
304// CHECK-V6: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
305 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
306 convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
307 convert_signed_char_to_signed_int((int8_t)INT8_MIN);
308 convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
309// CHECK-V6: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed)
310 convert_signed_int_to_unsigned_int((int32_t)INT32_MIN);
311// CHECK-V6: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned)
312 convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
313// CHECK-V6: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
314 convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
315// CHECK-V6: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned)
316 convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
317// CHECK-V6: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
318 convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
319// CHECK-V6: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka '{{(signed )?}}char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned)
320 convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
321// CHECK-V6: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
322 convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
323// CHECK-V6: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to -128 (8-bit, signed)
324#elif defined(V7)
325 // All bits except the source and destination sign bits are set.
326 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
327 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
328 convert_signed_int_to_signed_int((int32_t)INT32_MAX);
329 convert_signed_char_to_signed_char((int8_t)INT8_MAX);
330 convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
331// CHECK-V7: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned)
332 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
333 convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
334 convert_signed_char_to_signed_int((int8_t)INT8_MAX);
335 convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
336 convert_signed_int_to_unsigned_int((int32_t)INT32_MAX);
337 convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))));
338// CHECK-V7: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned)
339 convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
340 convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
341 convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
342 convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
343// CHECK-V7: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 127 (8-bit, signed)
344 convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
345// CHECK-V7: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka '{{(signed )?}}char') changed the value to 127 (8-bit, signed)
346#else
347#error Some V* needs to be defined!
348#endif
349
350 return 0;
351}
352

source code of compiler-rt/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c