#! /bin/sh -e

# DP: 2003-04-07  Roman Zippel  <zippel@linux-m68k.org>
# DP: 
# DP:   * gcc/final.c (alter_subreg): Adjust stack offset for a paradoxical
# DP: 	SUBREG, when it's pushed on the stack.

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

diff -u -p -r1.241.2.4 final.c
--- gcc/final.c	24 May 2002 21:26:50 -0000	1.241.2.4
+++ gcc/final.c	3 Apr 2003 22:55:06 -0000
@@ -2738,7 +2738,15 @@ alter_subreg (xp)
   /* simplify_subreg does not remove subreg from volatile references.
      We are required to.  */
   if (GET_CODE (y) == MEM)
-    *xp = adjust_address (y, GET_MODE (x), SUBREG_BYTE (x));
+    {
+      register int offset = SUBREG_BYTE (x);
+
+      if (BYTES_BIG_ENDIAN)
+	if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (y)))
+	  offset -= GET_MODE_SIZE (GET_MODE (x)) - GET_MODE_SIZE (GET_MODE (y));
+
+      *xp = adjust_address (y, GET_MODE (x), offset);
+    }
   else
     {
       rtx new = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
