1// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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-integer-arithmetic-value-change %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 convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
157 convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
158 convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
159 convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX);
160// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
161 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX);
162// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
163 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX);
164// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
165 convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
166// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
167 convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
168// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
169 convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
170// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
171 convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX);
172// CHECK-V0: {{.*}}integer-arithmetic-value-change.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)
173 convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX);
174#elif defined(V1)
175 // Source 'Sign' bit set.
176 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
177 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
178 convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN);
179 convert_signed_char_to_signed_char((int8_t)INT8_MIN);
180 convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN);
181 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
182 convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
183 convert_signed_char_to_signed_int((int8_t)INT8_MIN);
184 convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
185// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
186 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN);
187// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
188 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN);
189// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
190 convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
191// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
192 convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
193// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
194 convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
195// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
196 convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN);
197// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
198 convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN);
199// CHECK-V1: {{.*}}integer-arithmetic-value-change.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)
200#elif defined(V2)
201 // All bits except the source 'Sign' bit are set.
202 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
203 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
204 convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX);
205 convert_signed_char_to_signed_char((int8_t)INT8_MAX);
206 convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX);
207 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
208 convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
209 convert_signed_char_to_signed_int((int8_t)INT8_MAX);
210 convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
211 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX);
212 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX);
213// CHECK-V2: {{.*}}integer-arithmetic-value-change.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)
214 convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
215 convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
216 convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
217 convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX);
218// CHECK-V2: {{.*}}integer-arithmetic-value-change.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)
219 convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX);
220// CHECK-V2: {{.*}}integer-arithmetic-value-change.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)
221#elif defined(V3)
222 // All destination bits set.
223 convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX);
224 convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
225 convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX);
226 convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
227 convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX);
228 convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
229 convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
230 convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
231 convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX);
232 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX);
233 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX);
234 convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
235// CHECK-V3: {{.*}}integer-arithmetic-value-change.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)
236 convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
237// CHECK-V3: {{.*}}integer-arithmetic-value-change.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)
238 convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
239// CHECK-V3: {{.*}}integer-arithmetic-value-change.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)
240 convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX);
241// CHECK-V3: {{.*}}integer-arithmetic-value-change.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)
242 convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX);
243// CHECK-V3: {{.*}}integer-arithmetic-value-change.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)
244#elif defined(V4)
245 // Destination 'sign' bit set.
246 convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN);
247 convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
248 convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
249 convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
250 convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN);
251 convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
252 convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
253 convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
254 convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN);
255 convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
256 convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
257 convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
258// CHECK-V4: {{.*}}integer-arithmetic-value-change.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)
259 convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
260// CHECK-V4: {{.*}}integer-arithmetic-value-change.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)
261 convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
262// CHECK-V4: {{.*}}integer-arithmetic-value-change.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)
263 convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN);
264// CHECK-V4: {{.*}}integer-arithmetic-value-change.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)
265 convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
266// CHECK-V4: {{.*}}integer-arithmetic-value-change.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)
267#elif defined(V5)
268 // All bits except the destination 'sign' bit are set.
269 convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN)));
270 convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
271 convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
272 convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
273 convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN)));
274 convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
275 convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
276 convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
277 convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN)));
278// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
279 convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
280// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
281 convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
282// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
283 convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
284// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
285 convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
286// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
287 convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
288// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
289 convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN)));
290// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
291 convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
292// CHECK-V5: {{.*}}integer-arithmetic-value-change.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)
293#elif defined(V6)
294 // Only the source and destination sign bits are set.
295 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
296 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
297 convert_signed_int_to_signed_int((int32_t)INT32_MIN);
298 convert_signed_char_to_signed_char((int8_t)INT8_MIN);
299 convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN));
300 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
301 convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
302 convert_signed_char_to_signed_int((int8_t)INT8_MIN);
303 convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
304// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
305 convert_signed_int_to_unsigned_int((int32_t)INT32_MIN);
306// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
307 convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
308// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
309 convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
310// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
311 convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
312// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
313 convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
314// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
315 convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
316// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
317 convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
318// CHECK-V6: {{.*}}integer-arithmetic-value-change.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)
319#elif defined(V7)
320 // All bits except the source and destination sign bits are set.
321 convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
322 convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
323 convert_signed_int_to_signed_int((int32_t)INT32_MAX);
324 convert_signed_char_to_signed_char((int8_t)INT8_MAX);
325 convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
326 convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
327 convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
328 convert_signed_char_to_signed_int((int8_t)INT8_MAX);
329 convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
330 convert_signed_int_to_unsigned_int((int32_t)INT32_MAX);
331 convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))));
332// CHECK-V7: {{.*}}integer-arithmetic-value-change.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)
333 convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
334 convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
335 convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
336 convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
337// CHECK-V7: {{.*}}integer-arithmetic-value-change.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)
338 convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
339// CHECK-V7: {{.*}}integer-arithmetic-value-change.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)
340#else
341#error Some V* needs to be defined!
342#endif
343
344 return 0;
345}
346

source code of compiler-rt/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c