Subject: Re: Compiler bug in g++ 2.7.2.1
To: None <port-arm32@NetBSD.ORG>
From: Adam Gundy <adam@impala.demon.co.uk>
List: port-arm32
Date: 06/15/1997 19:51:40
In message <19970613.212347.93@impala.demon.co.uk> I wrote:
> I've found a nasty bug in g++ 2.7.2.1 (from RiscBSD 1.2 Release with
> the patch applied).
> 
> Passing a 'bool' to a function as the fifth (or greater) argument
> causes the stack pointer to stop being word aligned (result - SEGV).

<snip>

> The compiler is attempting to byte align the argument on the stack,
> rather than word align it (a bool passed as argument 1-4 works fine
> because they're passed in registers).
> 
> My current hacky fix is the commented '#define bool signed char',
> which produces correct assembly.
> 
> A fixed version of g++ would be greatly appreciated - i'm currently
> suffering from a distinct lack of hard disk space, or I'd fix it
> myself ;-)

deleting unused parts of X11 can make room for a gcc build ;-)

ok. here's my patch for the bug I reported (the patch is against
gcc 2.7.2.2 with the riscbsd patches applied):

diff -N -c -r gcc-2.7.2.2/config/arm/arm.h gcc-2.7.2.2-riscbsd/config/arm/arm.h
*** gcc-2.7.2.2/config/arm/arm.h                        Mon Aug 28 11:17:11 1995
--- gcc-2.7.2.2-riscbsd/config/arm/arm.h                Sun Jun 15 01:43:53 1997
***************
*** 1748,1753 ****
--- 1748,1755 ----
  	fprintf (STREAM, "[%s%s, #%s%d]!", REGISTER_PREFIX,		\
  		 reg_names[REGNO (XEXP (X, 0))],			\
  		 GET_CODE (X) == PRE_DEC ? "-" : "",			\
+ 		 (REGNO (XEXP (X, 0)) == STACK_POINTER_REGNUM ) ?       \
+                ((GET_MODE_SIZE (output_memory_reference_mode) + 3) & ~3) : \
  		 GET_MODE_SIZE (output_memory_reference_mode));		\
        else								\
  	fprintf (STREAM, "[%s%s], #%s%d", REGISTER_PREFIX,		\


I would appreciate comments on the validity of the patch, as I'm not
certain this is the correct place for the fix.
My reasoning behind the fix (ensuring pre-decremented stores with
write back to the stack are always word aligned) is taken
from rtl.texi:

: @item (pre_dec:@var{m} @var{x})
: Represents the side effect of decrementing @var{x} by a standard
: amount and represents also the value that @var{x} has after being
: decremented.  @var{x} must be a @code{reg} or @code{mem}, but most
: machines allow only a @code{reg}.  @var{m} must be the machine mode
: for pointers on the machine in use.  The amount @var{x} is decremented
: by is the length in bytes of the machine mode of the containing memory
: reference of which this expression serves as the address.  Here is an
: example of its use:@refill

I'm assuming that the "length in bytes of the machine mode of the
containing memory reference of which this expression serves as the
address" should always be a multiple of 4 for an ARM stack.

As an aside, chars and shorts work without the patch because they're
promoted to ints when passed as function parameters.

It certainly seems to work, anyway...

Seeya,
 Adam.
-- 
As the year 2000 approaches, the carefully planned Millenium 'bug'
begins to manifest itself in the computing job market...
Real programmers don't comment their code. If it was hard to write, it
should be harder to modify. These are all my own opinions.