On Wed, Jun 03, 2009 at 07:49:29PM +0200, Stelian Pop wrote: > I'm doing a port of gcc 4.3.3 on a custom architecture and I'm having trouble > when initializing the bit fields of a structure.
Ok, after further analysis, it looks like a genuine bug in gcc, in store_bit_field_1(): when a field is bigger than a word, the rvalue is splitted in several words, after being placed in a smallest_mode_for_size() operand. But the logic for adressing the words of this operand is buggy in the WORDS_BIG_ENDIAN case, the most signficant words being used instead of the least significant ones. The following patch corrects this, and makes the gcc.c-torture/execute/991118-1.c testcase work correctly on my platform. Stelian. diff --git a/gcc/expmed.c b/gcc/expmed.c index dc61de7..03c60a8 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -582,7 +582,10 @@ store_bit_field_1 (rtx str_rtx, unsigned HOST_WIDE_INT bitsize, { /* If I is 0, use the low-order word in both field and target; if I is 1, use the next to lowest word; and so on. */ - unsigned int wordnum = (backwards ? nwords - i - 1 : i); + unsigned int wordnum = (backwards + ? GET_MODE_SIZE(fieldmode) / UNITS_PER_WORD + - i - 1 + : i); unsigned int bit_offset = (backwards ? MAX ((int) bitsize - ((int) i + 1) * BITS_PER_WORD, -- Stelian Pop <stel...@popies.net>