From: bernhardheld Date: Thu, 18 Sep 2003 09:30:51 +0000 (+0000) Subject: src/SDCCval.c (valPlus, valMinus): fixed bug #808337 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=5fed4a0d90d3cdabd0b98a38dd966b327f87a3e7;p=fw%2Fsdcc src/SDCCval.c (valPlus, valMinus): fixed bug #808337 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2896 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index bffa8bb4..5c211d47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ +2003-09-18 Bernhard Held + * src/SDCCval.c (valPlus, valMinus): fixed bug #808337 + 2003-07-06 Jesus Calvino-Fraga - * support/librarian/sdcclib.c: Generate correct offsets for libraries with - Unix (/n) and DOS (/r/n) line terminations. + * support/librarian/sdcclib.c: Generate correct offsets for libraries with + Unix (/n) and DOS (/r/n) line terminations. 2003-09-17 Erik Petrich diff --git a/src/SDCCval.c b/src/SDCCval.c index 0bdace5e..fdb2c4be 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1243,27 +1243,30 @@ valPlus (value * lval, value * rval) val->type = val->etype = newLink (SPECIFIER); SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); - SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = - SPEC_USIGN (lval->etype) && - SPEC_USIGN (rval->etype) && - (floatFromVal(lval)+floatFromVal(rval))>=0; - - SPEC_LONG (val->type) = 1; - + SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ + SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); + /* both signed char and unsigned char are promoted to signed int */ + if (IS_CHAR (lval->etype)) + { + SPEC_USIGN (lval->etype) = 0; + SPEC_NOUN (lval->etype) = V_INT; + } + if (IS_CHAR (rval->etype)) + { + SPEC_USIGN (rval->etype) = 0; + SPEC_NOUN (rval->etype) = V_INT; + } + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); if (IS_FLOAT (val->type)) SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval); else { - if (SPEC_LONG (val->type)) - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) + - (unsigned long) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) + - (long) floatFromVal (rval); - } + 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); } return cheapestVal(val); } @@ -1282,38 +1285,29 @@ valMinus (value * lval, value * rval) SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = - SPEC_USIGN (lval->etype) && - SPEC_USIGN (rval->etype) && - (floatFromVal(lval)-floatFromVal(rval))>=0; - - SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); - + SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); + /* both signed char and unsigned char are promoted to signed int */ + if (IS_CHAR (lval->etype)) + { + SPEC_USIGN (lval->etype) = 0; + SPEC_NOUN (lval->etype) = V_INT; + } + if (IS_CHAR (rval->etype)) + { + SPEC_USIGN (rval->etype) = 0; + SPEC_NOUN (rval->etype) = V_INT; + } + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); if (IS_FLOAT (val->type)) - SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval); + SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval); else { - if (SPEC_LONG (val->type)) - { - if (SPEC_USIGN (val->type)) { - SPEC_CVAL (val->type).v_ulong = - (unsigned long) floatFromVal (lval) - - (unsigned long) floatFromVal (rval); - } else { - SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) - - (long) floatFromVal (rval); - } - } + if (SPEC_USIGN (val->type)) + SPEC_CVAL (val->type).v_ulong = (TYPE_UDWORD) floatFromVal (lval) - + (TYPE_UDWORD) floatFromVal (rval); else - { - if (SPEC_USIGN (val->type)) { - SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) - - (unsigned) floatFromVal (rval); - } else { - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) - - (int) floatFromVal (rval); - } - } + SPEC_CVAL (val->type).v_long = (TYPE_DWORD) floatFromVal (lval) - + (TYPE_DWORD) floatFromVal (rval); } return cheapestVal(val); }