This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
apparent integer promotions bug
- From: David Holland <dholland at eecs dot harvard dot edu>
- To: bug-gcc at gnu dot org
- Date: Fri, 29 Mar 2002 16:01:57 -0500 (EST)
- Subject: apparent integer promotions bug
It appears that left-shifting an unsigned value is generating a signed
value, but only when a bitfield is involved.
Test case follows.
/*
* test.c
* Compile with gcc -W -c test.c
*
* Generates "comparison between signed and unsigned" warning which
* I believe to be incorrect.
*
* Observed with:
* gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
* (NetBSD 1.5W current i386 gcc)
*
* and also with
* gcc version 3.0.3
* built with --target=mips-linux, --nfp, and --disable-shared, running
* on i386-netbsd.
*/
struct foo {
unsigned field:29;
};
int bar(struct foo *f, unsigned val) {
// doesn't warn
//unsigned tmp = (unsigned)f->field;
//return ((tmp) << 3U) < val;
// doesn't warn
//return ((unsigned)(((unsigned)f->field) << 3U)) < val;
// doesn't warn
//return (((unsigned)f->field) * 8U) < val;
// warns (correctly)
//return (((unsigned)f->field) * 8) < val;
// warns (incorrectly)
return (((unsigned)f->field) << 3U) < val;
}
--
- David A. Holland / dholland [at] eecs.harvard.edu