From 94b476d74944186a591891d6af122b58cfffd3e5 Mon Sep 17 00:00:00 2001 From: epetrich Date: Tue, 16 Dec 2003 19:46:43 +0000 Subject: [PATCH] * src/SDCCval.c (valPlus, valMinus, valShift): fixed some problems with implicit casts via union; they don't work on big endian systems (possible fix for bug #861138) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3060 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++++ src/SDCCval.c | 78 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e8acf65..3bd51903 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-12-16 Erik Petrich + + * src/SDCCval.c (valPlus, valMinus, valShift): fixed some problems with + implicit casts via union; they don't work on big endian systems + (possible fix for bug #861138) + 2003-12-16 Frieder Ferlemann (committed by Erik Petrich on Frieder's behalf) diff --git a/src/SDCCval.c b/src/SDCCval.c index 8aa1e3b9..fbbf0c11 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1259,12 +1259,25 @@ valPlus (value * lval, value * rval) SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval); else { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) + - (TYPE_UDWORD) floatFromVal (rval); + if (SPEC_LONG (val->type)) + { + if (SPEC_USIGN (val->type)) + SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) + + (TYPE_UDWORD) floatFromVal (rval); + else + SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) + + (TYPE_DWORD) floatFromVal (rval); + } else - SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) + - (TYPE_DWORD) floatFromVal (rval); + { + if (SPEC_USIGN (val->type)) { + SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) + + (TYPE_UWORD) floatFromVal (rval); + } else { + SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) + + (TYPE_WORD) floatFromVal (rval); + } + } } return cheapestVal(val); } @@ -1300,12 +1313,25 @@ valMinus (value * lval, value * rval) SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval); else { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) - - (TYPE_UDWORD) floatFromVal (rval); + if (SPEC_LONG (val->type)) + { + if (SPEC_USIGN (val->type)) + SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) - + (TYPE_UDWORD) floatFromVal (rval); + else + SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) - + (TYPE_DWORD) floatFromVal (rval); + } else - SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) - - (TYPE_DWORD) floatFromVal (rval); + { + if (SPEC_USIGN (val->type)) { + SPEC_CVAL (val->type).v_uint = (TYPE_UWORD) floatFromVal (lval) - + (TYPE_UWORD) floatFromVal (rval); + } else { + SPEC_CVAL (val->type).v_int = (TYPE_WORD) floatFromVal (lval) - + (TYPE_WORD) floatFromVal (rval); + } + } } return cheapestVal(val); } @@ -1328,17 +1354,35 @@ valShift (value * lval, value * rval, int lr) SPEC_USIGN (val->type) = SPEC_USIGN (lval->etype); SPEC_LONG (val->type) = SPEC_LONG (lval->etype); - if (SPEC_USIGN (val->type)) + if (SPEC_LONG (val->type)) { - SPEC_CVAL (val->type).v_ulong = lr ? - (TYPE_UDWORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ - (TYPE_UDWORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + if (SPEC_USIGN (val->type)) + { + SPEC_CVAL (val->type).v_ulong = lr ? + (TYPE_UDWORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ + (TYPE_UDWORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + } + else + { + SPEC_CVAL (val->type).v_long = lr ? + (TYPE_DWORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ + (TYPE_DWORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + } } else { - SPEC_CVAL (val->type).v_long = lr ? - (TYPE_DWORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ - (TYPE_DWORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + if (SPEC_USIGN (val->type)) + { + SPEC_CVAL (val->type).v_uint = lr ? + (TYPE_UWORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ + (TYPE_UWORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + } + else + { + SPEC_CVAL (val->type).v_int = lr ? + (TYPE_WORD) floatFromVal (lval) << (TYPE_UWORD) floatFromVal (rval) : \ + (TYPE_WORD) floatFromVal (lval) >> (TYPE_UWORD) floatFromVal (rval); + } } return cheapestVal(val); } -- 2.39.5