This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bug in bitfield handling?
- From: <Paul_Koning at Dell dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Fri, 7 Sep 2012 17:57:41 +0000
- Subject: Bug in bitfield handling?
This seems to be a bug:
struct bug
{
int f1:1;
unsigned long long f2:31;
};
struct bug test = { 1, 0x8000ULL };
int main (int c, char **v)
{
unsigned long long tf2;
tf2 = test.f2 << 16;
if (tf2 == 0x80000000ULL)
return 0;
return 1;
}
Since the underlying type of field f2 is unsigned long long, I would not expect the expression "test.f2 << 16" to do sign extending of a 32 bit intermediate result. But that is in fact what GCC produces, for x86_64-linux (gcc 4.7.0).
If I explicitly cast test.f2 to unsigned long long before the shift, the expected result appears. But I shouldn't have to do that cast, given that the type of f2 is already unsigned long long, correct?
paul