| 1 |
// RUN: %clang -x c -fsanitize=implicit-integer-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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-truncation %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 |
|
| 30 |
uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { |
| 31 |
#line 100 |
| 32 |
return x; |
| 33 |
} |
| 34 |
|
| 35 |
uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { |
| 36 |
#line 200 |
| 37 |
return x; |
| 38 |
} |
| 39 |
|
| 40 |
int32_t convert_signed_int_to_signed_int(int32_t x) { |
| 41 |
#line 300 |
| 42 |
return x; |
| 43 |
} |
| 44 |
|
| 45 |
int8_t convert_signed_char_to_signed_char(int8_t x) { |
| 46 |
#line 400 |
| 47 |
return x; |
| 48 |
} |
| 49 |
|
| 50 |
uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { |
| 51 |
#line 500 |
| 52 |
return x; |
| 53 |
} |
| 54 |
|
| 55 |
uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { |
| 56 |
#line 600 |
| 57 |
return x; |
| 58 |
} |
| 59 |
|
| 60 |
int32_t convert_unsigned_char_to_signed_int(uint8_t x) { |
| 61 |
#line 700 |
| 62 |
return x; |
| 63 |
} |
| 64 |
|
| 65 |
int32_t convert_signed_char_to_signed_int(int8_t x) { |
| 66 |
#line 800 |
| 67 |
return x; |
| 68 |
} |
| 69 |
|
| 70 |
int32_t convert_unsigned_int_to_signed_int(uint32_t x) { |
| 71 |
#line 900 |
| 72 |
return x; |
| 73 |
} |
| 74 |
|
| 75 |
uint32_t convert_signed_int_to_unsigned_int(int32_t x) { |
| 76 |
#line 1000 |
| 77 |
return x; |
| 78 |
} |
| 79 |
|
| 80 |
uint8_t convert_signed_int_to_unsigned_char(int32_t x) { |
| 81 |
#line 1100 |
| 82 |
return x; |
| 83 |
} |
| 84 |
|
| 85 |
uint8_t convert_signed_char_to_unsigned_char(int8_t x) { |
| 86 |
#line 1200 |
| 87 |
return x; |
| 88 |
} |
| 89 |
|
| 90 |
int8_t convert_unsigned_char_to_signed_char(uint8_t x) { |
| 91 |
#line 1300 |
| 92 |
return x; |
| 93 |
} |
| 94 |
|
| 95 |
uint32_t convert_signed_char_to_unsigned_int(int8_t x) { |
| 96 |
#line 1400 |
| 97 |
return x; |
| 98 |
} |
| 99 |
|
| 100 |
int8_t convert_unsigned_int_to_signed_char(uint32_t x) { |
| 101 |
#line 1500 |
| 102 |
return x; |
| 103 |
} |
| 104 |
|
| 105 |
int8_t convert_signed_int_to_signed_char(int32_t x) { |
| 106 |
#line 1600 |
| 107 |
return x; |
| 108 |
} |
| 109 |
|
| 110 |
#line 1111 // !!! |
| 111 |
|
| 112 |
int main() { |
| 113 |
// No bits set. |
| 114 |
convert_unsigned_int_to_unsigned_int(0); |
| 115 |
convert_unsigned_char_to_unsigned_char(0); |
| 116 |
convert_signed_int_to_signed_int(0); |
| 117 |
convert_signed_char_to_signed_char(0); |
| 118 |
convert_unsigned_int_to_unsigned_char(0); |
| 119 |
convert_unsigned_char_to_unsigned_int(0); |
| 120 |
convert_unsigned_char_to_signed_int(0); |
| 121 |
convert_signed_char_to_signed_int(0); |
| 122 |
convert_unsigned_int_to_signed_int(0); |
| 123 |
convert_signed_int_to_unsigned_int(0); |
| 124 |
convert_signed_int_to_unsigned_char(0); |
| 125 |
convert_signed_char_to_unsigned_char(0); |
| 126 |
convert_unsigned_char_to_signed_char(0); |
| 127 |
convert_signed_char_to_unsigned_int(0); |
| 128 |
convert_unsigned_int_to_signed_char(0); |
| 129 |
convert_signed_int_to_signed_char(0); |
| 130 |
|
| 131 |
// One lowest bit set. |
| 132 |
convert_unsigned_int_to_unsigned_int(1); |
| 133 |
convert_unsigned_char_to_unsigned_char(1); |
| 134 |
convert_signed_int_to_signed_int(1); |
| 135 |
convert_signed_char_to_signed_char(1); |
| 136 |
convert_unsigned_int_to_unsigned_char(1); |
| 137 |
convert_unsigned_char_to_unsigned_int(1); |
| 138 |
convert_unsigned_char_to_signed_int(1); |
| 139 |
convert_signed_char_to_signed_int(1); |
| 140 |
convert_unsigned_int_to_signed_int(1); |
| 141 |
convert_signed_int_to_unsigned_int(1); |
| 142 |
convert_signed_int_to_unsigned_char(1); |
| 143 |
convert_signed_char_to_unsigned_char(1); |
| 144 |
convert_unsigned_char_to_signed_char(1); |
| 145 |
convert_signed_char_to_unsigned_int(1); |
| 146 |
convert_unsigned_int_to_signed_char(1); |
| 147 |
convert_signed_int_to_signed_char(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-truncation.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 |
convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); |
| 162 |
convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); |
| 163 |
// CHECK-V0: {{.*}}integer-truncation.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) |
| 164 |
convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); |
| 165 |
convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); |
| 166 |
convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); |
| 167 |
convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); |
| 168 |
convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); |
| 169 |
#elif defined(V1) |
| 170 |
// Source 'Sign' bit set. |
| 171 |
convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); |
| 172 |
convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); |
| 173 |
convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); |
| 174 |
convert_signed_char_to_signed_char((int8_t)INT8_MIN); |
| 175 |
convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); |
| 176 |
// CHECK-V1: {{.*}}integer-truncation.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) |
| 177 |
convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); |
| 178 |
convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); |
| 179 |
convert_signed_char_to_signed_int((int8_t)INT8_MIN); |
| 180 |
convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); |
| 181 |
convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); |
| 182 |
convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); |
| 183 |
// CHECK-V1: {{.*}}integer-truncation.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) |
| 184 |
convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); |
| 185 |
convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); |
| 186 |
convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); |
| 187 |
convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); |
| 188 |
// CHECK-V1: {{.*}}integer-truncation.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) |
| 189 |
convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); |
| 190 |
// CHECK-V1: {{.*}}integer-truncation.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) |
| 191 |
#elif defined(V2) |
| 192 |
// All bits except the source 'Sign' bit are set. |
| 193 |
convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); |
| 194 |
convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); |
| 195 |
convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); |
| 196 |
convert_signed_char_to_signed_char((int8_t)INT8_MAX); |
| 197 |
convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); |
| 198 |
// CHECK-V2: {{.*}}integer-truncation.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) |
| 199 |
convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); |
| 200 |
convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); |
| 201 |
convert_signed_char_to_signed_int((int8_t)INT8_MAX); |
| 202 |
convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); |
| 203 |
convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); |
| 204 |
convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); |
| 205 |
// CHECK-V2: {{.*}}integer-truncation.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) |
| 206 |
convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); |
| 207 |
convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); |
| 208 |
convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); |
| 209 |
convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); |
| 210 |
// CHECK-V2: {{.*}}integer-truncation.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) |
| 211 |
convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); |
| 212 |
// CHECK-V2: {{.*}}integer-truncation.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) |
| 213 |
#elif defined(V3) |
| 214 |
// All destination bits set. |
| 215 |
convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); |
| 216 |
convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); |
| 217 |
convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); |
| 218 |
convert_signed_char_to_signed_char((int8_t)UINT8_MAX); |
| 219 |
convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); |
| 220 |
convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); |
| 221 |
convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); |
| 222 |
convert_signed_char_to_signed_int((int8_t)UINT8_MAX); |
| 223 |
convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); |
| 224 |
convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); |
| 225 |
convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); |
| 226 |
convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); |
| 227 |
convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); |
| 228 |
convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); |
| 229 |
convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); |
| 230 |
// CHECK-V3: {{.*}}integer-truncation.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) |
| 231 |
convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); |
| 232 |
// CHECK-V3: {{.*}}integer-truncation.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) |
| 233 |
#elif defined(V4) |
| 234 |
// Destination 'sign' bit set. |
| 235 |
convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); |
| 236 |
convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); |
| 237 |
convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); |
| 238 |
convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); |
| 239 |
convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); |
| 240 |
convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); |
| 241 |
convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); |
| 242 |
convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); |
| 243 |
convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); |
| 244 |
convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); |
| 245 |
convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); |
| 246 |
convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); |
| 247 |
convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); |
| 248 |
convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); |
| 249 |
convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); |
| 250 |
// CHECK-V4: {{.*}}integer-truncation.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) |
| 251 |
convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); |
| 252 |
// CHECK-V4: {{.*}}integer-truncation.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) |
| 253 |
#elif defined(V5) |
| 254 |
// All bits except the destination 'sign' bit are set. |
| 255 |
convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); |
| 256 |
convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); |
| 257 |
convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); |
| 258 |
convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); |
| 259 |
convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); |
| 260 |
// CHECK-V5: {{.*}}integer-truncation.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) |
| 261 |
convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); |
| 262 |
convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); |
| 263 |
convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); |
| 264 |
convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); |
| 265 |
convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); |
| 266 |
convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); |
| 267 |
// CHECK-V5: {{.*}}integer-truncation.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) |
| 268 |
convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); |
| 269 |
convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); |
| 270 |
convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); |
| 271 |
convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); |
| 272 |
// CHECK-V5: {{.*}}integer-truncation.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) |
| 273 |
convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); |
| 274 |
// CHECK-V5: {{.*}}integer-truncation.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) |
| 275 |
#elif defined(V6) |
| 276 |
// Only the source and destination sign bits are set. |
| 277 |
convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); |
| 278 |
convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); |
| 279 |
convert_signed_int_to_signed_int((int32_t)INT32_MIN); |
| 280 |
convert_signed_char_to_signed_char((int8_t)INT8_MIN); |
| 281 |
convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); |
| 282 |
// CHECK-V6: {{.*}}integer-truncation.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) |
| 283 |
convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); |
| 284 |
convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); |
| 285 |
convert_signed_char_to_signed_int((int8_t)INT8_MIN); |
| 286 |
convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); |
| 287 |
convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); |
| 288 |
convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 289 |
// CHECK-V6: {{.*}}integer-truncation.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) |
| 290 |
convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); |
| 291 |
convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); |
| 292 |
convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); |
| 293 |
convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 294 |
// CHECK-V6: {{.*}}integer-truncation.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) |
| 295 |
convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 296 |
// CHECK-V6: {{.*}}integer-truncation.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) |
| 297 |
#elif defined(V7) |
| 298 |
// All bits except the source and destination sign bits are set. |
| 299 |
convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); |
| 300 |
convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); |
| 301 |
convert_signed_int_to_signed_int((int32_t)INT32_MAX); |
| 302 |
convert_signed_char_to_signed_char((int8_t)INT8_MAX); |
| 303 |
convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 304 |
// CHECK-V7: {{.*}}integer-truncation.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) |
| 305 |
convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); |
| 306 |
convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); |
| 307 |
convert_signed_char_to_signed_int((int8_t)INT8_MAX); |
| 308 |
convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); |
| 309 |
convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); |
| 310 |
convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); |
| 311 |
// CHECK-V7: {{.*}}integer-truncation.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) |
| 312 |
convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); |
| 313 |
convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); |
| 314 |
convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); |
| 315 |
convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 316 |
// CHECK-V7: {{.*}}integer-truncation.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) |
| 317 |
convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); |
| 318 |
// CHECK-V7: {{.*}}integer-truncation.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) |
| 319 |
#else |
| 320 |
#error Some V* needs to be defined! |
| 321 |
#endif |
| 322 |
|
| 323 |
return 0; |
| 324 |
} |