mycoboco / beluga

a standard C compiler (with an integrated preprocessor)
http://code.woong.org/beluga
Other
65 stars 8 forks source link

remove misleading diagnostics for values exceeding bitfield width #97

Closed mycoboco closed 7 years ago

mycoboco commented 7 years ago
struct foo { int a: 3; };

void f(void)
{
    struct foo s = { 9223372036854775808 };
}
foo.c:5:22: warning - integer constant is so large that it is unsinged
      struct foo s = { 9223372036854775808 };
                       ^~~~~~~~~~~~~~~~~~~
foo.c:5:22: warning - overflow in converting constant expression from `unsigned long long' to `long long int'
      struct foo s = { 9223372036854775808 };
                       ^~~~~~~~~~~~~~~~~~~
foo.c:5:22: warning - initializer exceeds bit-field
      struct foo s = { 9223372036854775808 };
                       ^~~~~~~~~~~~~~~~~~~
foo.c:5:16: warning - local `s' set but not used [-Wextra]
      struct foo s = { 9223372036854775808 };
                 ^
mycoboco commented 7 years ago

Difficult to completely remove diagnostics from enode_cast() because:

mycoboco commented 7 years ago

Seems not bad to separate a bit-field overflow check into two, one to check if an initializer fits in the storage unit and the other to check if fits in a bit-field if the first diagnostic message shows the type of the storage unit type correctly.