This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

egcs 1.1.1 bitfield bug in 8bit port (ATMEL AVR)


Hello all.

I have compiler abort in the following test
(/gcc.c-torture/execute/920908-2.c):
-----------------------------------
struct T
{
unsigned i:8;
unsigned c:24; /* This is a my problem line */
};
f(struct T t)
{
struct T s[1];
s[0]=t;
return(char)s->c;
}
main()
{
struct T t;
t.i=0xff;
t.c=0xffff11;
if(f(t)!=0x11)abort();
exit(0);
}
-------------------------------------
Compiler aborts on `unsigned c:24;' because in my port:
 - int = 8 bit;
 - long = 16 bit;
 - long long = 32 bit.

Problem was borne in function `store_bit_field' in file expmed.c:
----------------- fragment ---------------------------
      int nwords = (bitsize + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
      int i;

      /* This is the mode we must force value to, so that there will be enough
	 subwords to extract.  Note that fieldmode will often (always?) be
	 VOIDmode, because that is what store_field uses to indicate that this
	 is a bit field, but passing VOIDmode to operand_subword_force will
	 result in an abort.  */
      fieldmode = mode_for_size (nwords * BITS_PER_WORD, MODE_INT, 0);
----------------------------------------------------------------------
In my case `mode_for_size' returns BLKmode because `unsigned c:24;'
fits to 3 bytes (3 words for AVR) and I do not have such mode.

I have substituted:
      fieldmode = mode_for_size (nwords * BITS_PER_WORD, MODE_INT, 0);
to:
      fieldmode = smallest_mode_for_size (nwords * BITS_PER_WORD, MODE_INT);

Is this right ?
May be patch needed ?

Denis.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]