brintos

brintos / llvm-project-archived public Read only

0
0
Text · 27.2 KiB · 3b359f0 Raw
650 lines · c
1// RUN: %clang   -x c   -fsanitize=implicit-bitfield-conversion -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK2// RUN: %clang   -x c   -fsanitize=implicit-bitfield-conversion -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK3// RUN: %clang   -x c   -fsanitize=implicit-bitfield-conversion -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK4// RUN: %clang   -x c   -fsanitize=implicit-bitfield-conversion -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK5// RUN: %clang   -x c   -fsanitize=implicit-conversion          -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK6 7// RUN: %clangxx -x c++ -fsanitize=implicit-bitfield-conversion -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK8// RUN: %clangxx -x c++ -fsanitize=implicit-bitfield-conversion -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK9// RUN: %clangxx -x c++ -fsanitize=implicit-bitfield-conversion -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK10// RUN: %clangxx -x c++ -fsanitize=implicit-bitfield-conversion -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK11// RUN: %clangxx -x c++ -fsanitize=implicit-conversion          -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK12 13#include <stdbool.h>14#include <stdint.h>15 16#define UINT4_MIN 017#define UINT4_MAX (1 << 4) - 118#define UINT5_MIN 019#define UINT5_MAX (1 << 5) - 120#define INT7_MIN -(1 << 6)21#define INT7_MAX (1 << 6) - 122 23typedef struct _X {24  uint8_t a : 4;25  uint32_t b : 5;26  int8_t c : 7;27  int32_t d : 16;28  uint8_t e : 8;29  uint16_t f : 16;30  uint32_t g : 32;31  int8_t h : 8;32  int16_t i : 16;33  int32_t j : 32;34  uint32_t k : 1;35  int32_t l : 1;36  bool m : 1;37} X;38 39void test_a() {40  X x;41  uint32_t min = UINT4_MIN;42  uint32_t max = UINT4_MAX;43 44  uint8_t v8 = max + 1;45  uint16_t v16 = (UINT8_MAX + 1) + (max + 1);46  uint32_t v32 = (UINT8_MAX + 1) + (max + 1);47 48  // Assignment49  x.a = v8;50  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint8_t' (aka 'unsigned char') of value 16 (8-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)51  x.a = v16;52  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint16_t' (aka 'unsigned short') of value 272 (16-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)53  x.a = v32;54  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 272 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)55 56  // PrePostIncDec57  x.a = min;58  x.a--;59  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 15 (4-bit bitfield, unsigned)60  x.a = min;61  --x.a;62  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 15 (4-bit bitfield, unsigned)63 64  x.a = max;65  x.a++;66  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 16 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)67  x.a = max;68  ++x.a;69  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 16 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)70 71  x.a = min + 1;72  x.a++;73  x.a = min + 1;74  ++x.a;75 76  x.a = min + 1;77  x.a--;78  x.a = min + 1;79  --x.a;80 81  x.a = max - 1;82  x.a++;83  x.a = max - 1;84  ++x.a;85 86  x.a = max - 1;87  x.a--;88  x.a = max - 1;89  --x.a;90 91  // Compound assignment92  x.a = 0;93  x.a += max;94  x.a = 0;95  x.a += (max + 1);96  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 16 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)97 98  x.a = max;99  x.a -= max;100  x.a = max;101  x.a -= (max + 1);102  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 15 (4-bit bitfield, unsigned)103 104  x.a = 1;105  x.a *= max;106  x.a = 1;107  x.a *= (max + 1);108  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 16 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (4-bit bitfield, unsigned)109}110 111void test_b() {112  X x;113  uint32_t min = UINT5_MIN;114  uint32_t max = UINT5_MAX;115 116  uint8_t v8 = max + 1;117  uint16_t v16 = max + 1;118  uint32_t v32 = max + 1;119 120  // Assignment121  x.b = v8;122  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint8_t' (aka 'unsigned char') of value 32 (8-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)123  x.b = v16;124  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint16_t' (aka 'unsigned short') of value 32 (16-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)125  x.b = v32;126  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)127 128  // PrePostIncDec129  x.b = min;130  x.b--;131  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 31 (5-bit bitfield, unsigned)132  x.b = min;133  --x.b;134  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 31 (5-bit bitfield, unsigned)135 136  x.b = max;137  x.b++;138  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)139  x.b = max;140  ++x.b;141  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)142 143  x.b = min + 1;144  x.b++;145  x.b = min + 1;146  ++x.b;147 148  x.b = min + 1;149  x.b--;150  x.b = min + 1;151  --x.b;152 153  x.b = max - 1;154  x.b++;155  x.b = max - 1;156  ++x.b;157 158  x.b = max - 1;159  x.b--;160  x.b = max - 1;161  --x.b;162 163  // Compound assignment164  x.b = 0;165  x.b += max;166  x.b = 0;167  x.b += (max + 1);168  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)169 170  x.b = max;171  x.b -= max;172  x.b = max;173  x.b -= (max + 1);174  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 31 (5-bit bitfield, unsigned)175 176  x.b = 1;177  x.b *= max;178  x.b = 1;179  x.b *= (max + 1);180  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (5-bit bitfield, unsigned)181}182 183void test_c() {184  X x;185  int32_t min = INT7_MIN;186  int32_t max = INT7_MAX;187 188  uint8_t v8 = max + 1;189  uint16_t v16 = (UINT8_MAX + 1) + (max + 1);190  uint32_t v32 = (UINT8_MAX + 1) + (max + 1);191 192  // Assignment193  x.c = v8;194  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint8_t' (aka 'unsigned char') of value 64 (8-bit, unsigned) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)195  x.c = v16;196  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint16_t' (aka 'unsigned short') of value 320 (16-bit, unsigned) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)197  x.c = v32;198  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 320 (32-bit, unsigned) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)199 200  // PrePostIncDec201  x.c = min;202  x.c--;203  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -65 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 63 (7-bit bitfield, signed)204  x.c = min;205  --x.c;206  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -65 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 63 (7-bit bitfield, signed)207 208  x.c = max;209  x.c++;210  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 64 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)211  x.c = max;212  ++x.c;213  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 64 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)214 215  x.c = min + 1;216  x.c++;217  x.c = min + 1;218  ++x.c;219 220  x.c = min + 1;221  x.c--;222  x.c = min + 1;223  --x.c;224 225  x.c = max - 1;226  x.c++;227  x.c = max - 1;228  ++x.c;229 230  x.c = max - 1;231  x.c--;232  x.c = max - 1;233  --x.c;234 235  // Compound assignment236  x.c = 0;237  x.c += max;238  x.c = 0;239  x.c += (max + 1);240  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 64 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)241 242  x.c = 0;243  x.c -= (-min);244  x.c = 0;245  x.c -= (-min + 1);246  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value -65 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 63 (7-bit bitfield, signed)247 248  x.c = 1;249  x.c *= max;250  x.c = 1;251  x.c *= (max + 1);252  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 64 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -64 (7-bit bitfield, signed)253}254 255void test_d() {256  X x;257  int32_t min = INT16_MIN;258  int32_t max = INT16_MAX;259 260  uint32_t v32 = max + 1;261 262  // Assignment263  x.d = v32;264  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 32768 (32-bit, unsigned) to type 'int32_t' (aka 'int') changed the value to -32768 (16-bit bitfield, signed)265 266  // PrePostIncDec267  x.d = min;268  x.d--;269  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value -32769 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to 32767 (16-bit bitfield, signed)270  x.d = min;271  --x.d;272  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value -32769 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to 32767 (16-bit bitfield, signed)273 274  x.d = max;275  x.d++;276  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 32768 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -32768 (16-bit bitfield, signed)277  x.d = max;278  ++x.d;279  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 32768 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -32768 (16-bit bitfield, signed)280 281  x.d = min + 1;282  x.d++;283  x.d = min + 1;284  ++x.d;285 286  x.d = min + 1;287  x.d--;288  x.d = min + 1;289  --x.d;290 291  x.d = max - 1;292  x.d++;293  x.d = max - 1;294  ++x.d;295 296  x.d = max - 1;297  x.d--;298  x.d = max - 1;299  --x.d;300 301  // Compound assignment302  x.d = 0;303  x.d += max;304  x.d = 0;305  x.d += (max + 1);306  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 32768 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -32768 (16-bit bitfield, signed)307 308  x.d = 0;309  x.d -= (-min);310  x.d = 0;311  x.d -= (-min + 1);312  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value -32769 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to 32767 (16-bit bitfield, signed)313 314  x.d = 1;315  x.d *= max;316  x.d = 1;317  x.d *= (max + 1);318  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 32768 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -32768 (16-bit bitfield, signed)319}320 321void test_e() {322  X x;323  uint32_t min = 0;324  uint32_t max = UINT8_MAX;325 326  uint16_t v16 = max + 1;327  uint32_t v32 = max + 1;328 329  // Assignment330  x.e = v16;331  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint16_t' (aka 'unsigned short') of value 256 (16-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit bitfield, unsigned)332  x.e = v32;333  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 256 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit bitfield, unsigned)334 335  // PrePostIncDec336  x.e = min;337  x.e--;338  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit bitfield, unsigned)339  x.e = min;340  --x.e;341  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit bitfield, unsigned)342  x.e = min + 1;343  x.e--;344 345  x.e = max;346  x.e++;347  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit bitfield, unsigned)348  x.e = max;349  ++x.e;350  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit bitfield, unsigned)351  x.e = max - 1;352  x.e++;353 354  // Compound assignment355  x.e = 0;356  x.e += max;357  x.e = 0;358  x.e += (max + 1);359  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 256 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit bitfield, unsigned)360 361  x.e = max;362  x.e -= max;363  x.e = max;364  x.e -= (max + 1);365  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit bitfield, unsigned)366}367 368void test_f() {369  X x;370  uint32_t min = 0;371  uint32_t max = UINT16_MAX;372 373  uint32_t v32 = max + 1;374 375  // Assignment376  x.f = v32;377  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 65536 (32-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 0 (16-bit bitfield, unsigned)378 379  // PrePostIncDec380  x.f = min;381  x.f--;382  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit bitfield, unsigned)383  x.f = min;384  --x.f;385  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit bitfield, unsigned)386  x.f = min + 1;387  x.f--;388 389  x.f = max;390  x.f++;391  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 65536 (32-bit, signed) to type 'uint16_t' (aka 'unsigned short') changed the value to 0 (16-bit bitfield, unsigned)392  x.f = max;393  ++x.f;394  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 65536 (32-bit, signed) to type 'uint16_t' (aka 'unsigned short') changed the value to 0 (16-bit bitfield, unsigned)395  x.f = max - 1;396  x.f++;397 398  // Compound assignment399  x.f = 0;400  x.f += max;401  x.f = 0;402  x.f += (max + 1);403  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 65536 (32-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 0 (16-bit bitfield, unsigned)404 405  x.f = max;406  x.f -= max;407  x.f = max;408  x.f -= (max + 1);409  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit bitfield, unsigned)410}411 412void test_g() {413  X x;414  uint64_t min = 0;415  uint64_t max = UINT32_MAX;416 417  uint64_t v64 = max + 1;418 419  // Assignment420  x.g = v64;421  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{( long)?}}') of value 4294967296 (64-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (32-bit bitfield, unsigned)422 423  // PrePostIncDec424  x.g = min;425  x.g--;426  x.g = min;427  --x.g;428  x.g = min + 1;429  x.g--;430 431  x.g = max;432  x.g++;433  x.g = max;434  ++x.g;435  x.g = max - 1;436  x.g++;437 438  // Compound assignment439  x.g = 0;440  x.g += max;441  x.g = 0;442  x.g += (max + 1);443  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{( long)?}}') of value 4294967296 (64-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (32-bit bitfield, unsigned)444 445  x.g = max;446  x.g -= max;447  x.g = max;448  x.g -= (max + 1);449  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{( long)?}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit bitfield, unsigned)450}451 452void test_h() {453  X x;454  int32_t min = INT8_MIN;455  int32_t max = INT8_MAX;456 457  int16_t v16 = max + 1;458  int32_t v32 = max + 1;459 460  // Assignment461  x.h = v16;462  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int16_t' (aka 'short') of value 128 (16-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -128 (8-bit bitfield, signed)463  x.h = v32;464  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 128 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -128 (8-bit bitfield, signed)465 466  // PrePostIncDec467  x.h = min;468  x.h--;469  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 127 (8-bit bitfield, signed)470  x.h = min;471  --x.h;472  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 127 (8-bit bitfield, signed)473  x.h = min + 1;474  x.h--;475 476  x.h = max;477  x.h++;478  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -128 (8-bit bitfield, signed)479  x.h = max;480  ++x.h;481  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -128 (8-bit bitfield, signed)482  x.h = max - 1;483  x.h++;484 485  // Compound assignment486  x.h = 0;487  x.h += max;488  x.h = 0;489  x.h += (max + 1);490  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to -128 (8-bit bitfield, signed)491 492  x.h = 0;493  x.h -= (-min);494  x.h = 0;495  x.h -= (-min + 1);496  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'int8_t' (aka '{{(signed )?}}char') changed the value to 127 (8-bit bitfield, signed)497}498 499void test_i() {500  X x;501  int32_t min = INT16_MIN;502  int32_t max = INT16_MAX;503 504  int32_t v32 = max + 1;505 506  // Assignment507  x.i = v32;508  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 32768 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to -32768 (16-bit bitfield, signed)509 510  // PrePostIncDec511  x.i = min;512  x.i--;513  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value -32769 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to 32767 (16-bit bitfield, signed)514  x.i = min;515  --x.i;516  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value -32769 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to 32767 (16-bit bitfield, signed)517  x.i = min + 1;518  x.i--;519 520  x.i = max;521  x.i++;522  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int' of value 32768 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to -32768 (16-bit bitfield, signed)523  x.i = max;524  ++x.i;525  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:3: runtime error: implicit conversion from type 'int' of value 32768 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to -32768 (16-bit bitfield, signed)526  x.i = max - 1;527  x.i++;528 529  // Compound assignment530  x.i = 0;531  x.i += max;532  x.i = 0;533  x.i += (max + 1);534  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value 32768 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to -32768 (16-bit bitfield, signed)535 536  x.i = 0;537  x.i -= (-min);538  x.i = 0;539  x.i -= (-min + 1);540  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int' of value -32769 (32-bit, signed) to type 'int16_t' (aka 'short') changed the value to 32767 (16-bit bitfield, signed)541}542 543void test_j() {544  X x;545  int64_t min = INT32_MIN;546  int64_t max = INT32_MAX;547 548  int64_t v64 = max + 1;549 550  // Assignment551  x.j = v64;552  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int64_t' (aka 'long{{( long)?}}') of value 2147483648 (64-bit, signed) to type 'int32_t' (aka 'int') changed the value to -2147483648 (32-bit bitfield, signed)553 554  // PrePostIncDec555  x.j = min;556  x.j--;557  x.j = min;558  --x.j;559  x.j = min + 1;560  x.j--;561 562  x.j = max;563  x.j++;564  x.j = max;565  ++x.j;566  x.j = max - 1;567  x.j++;568 569  // Compound assignment570  x.j = 0;571  x.j += max;572  x.j = 0;573  x.j += (max + 1);574  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int64_t' (aka 'long{{( long)?}}') of value 2147483648 (64-bit, signed) to type 'int32_t' (aka 'int') changed the value to -2147483648 (32-bit bitfield, signed)575 576  x.j = 0;577  x.j -= (-min);578  x.j = 0;579  x.j -= (-min + 1);580  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int64_t' (aka 'long{{( long)?}}') of value -2147483649 (64-bit, signed) to type 'int32_t' (aka 'int') changed the value to 2147483647 (32-bit bitfield, signed)581}582 583void test_k_l() {584  X x;585  int32_t one = 1;586  int32_t neg_one = -1;587 588  // k589  uint8_t v8 = 2;590  x.k = v8;591  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint8_t' (aka 'unsigned char') of value 2 (8-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (1-bit bitfield, unsigned)592  x.k = one;593  x.k = neg_one;594  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value -1 (32-bit, signed) to type 'uint32_t' (aka 'unsigned int') changed the value to 1 (1-bit bitfield, unsigned)595 596  x.k = 0;597  x.k--;598  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 1 (1-bit bitfield, unsigned)599  x.k = 1;600  x.k--;601 602  x.k = 1;603  x.k++;604  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2 (32-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 0 (1-bit bitfield, unsigned)605  x.k = 0;606  x.k++;607 608  // l609  x.l = v8;610  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'uint8_t' (aka 'unsigned char') of value 2 (8-bit, unsigned) to type 'int32_t' (aka 'int') changed the value to 0 (1-bit bitfield, signed)611  x.l = one;612  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:7: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 1 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -1 (1-bit bitfield, signed)613  x.l = neg_one;614 615  x.l = 0;616  x.l--;617  x.l = -1;618  x.l--;619  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value -2 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to 0 (1-bit bitfield, signed)620 621  x.l = 0;622  x.l++;623  // CHECK: {{.*}}bitfield-conversion.c:[[@LINE-1]]:6: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value 1 (32-bit, signed) to type 'int32_t' (aka 'int') changed the value to -1 (1-bit bitfield, signed)624  x.l = -1;625  x.l++;626}627 628void test_m() {629  X x;630 631  uint8_t v8 = 2;632  x.m = v8;633}634 635int main() {636  test_a();637  test_b();638  test_c();639  test_d();640  test_e();641  test_f();642  test_g();643  test_h();644  test_i();645  test_j();646  test_k_l();647  test_m();648  return 0;649}650