From f4235e9e1f80a6080d0da4076751dfda7da339e0 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 6 Jan 2004 22:03:36 +0000 Subject: [PATCH] * src/SDCCast.c (decorateType), * src/SDCCicode.c (geniCodeLeftShift): added promotion to int for LEFT_OP (left shift) * src/SDCCval.c (valShift): fixed warning * support/valdiag/tests/overflow.c: updated git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3090 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 +++- src/SDCCast.c | 55 ++++++++++++++++++-------------- src/SDCCicode.c | 9 +++--- src/SDCCval.c | 2 +- support/valdiag/tests/overflow.c | 8 ++--- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 156d91ee..fdd328cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ 2004-01-06 Bernhard Held - * src/SDCCval.c (valShift): changed from 16 to 32 bit shift count + * src/SDCCval.c (valShift): changed from 16 to 32 bit shift count, + fixed warning * support/valdiag/tests/overflow.c: added + * src/SDCCast.c (decorateType), + * src/SDCCicode.c (geniCodeLeftShift): added promotion to int for + LEFT_OP (left shift) 2004-01-06 Jesus Calvino-Fraga diff --git a/src/SDCCast.c b/src/SDCCast.c index 91cda09b..15f92a76 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2809,14 +2809,6 @@ decorateType (ast * tree) RTYPE (tree), TRUE)); - /* promote result to int if left & right are char - this will facilitate hardware multiplies 8bit x 8bit = 16bit */ - /* now done by computeType - if (IS_CHAR(LETYPE(tree)) && IS_CHAR(RETYPE(tree))) { - SPEC_NOUN(TETYPE(tree)) = V_INT; - } - */ - return tree; /*------------------------------------------------------------------*/ @@ -3187,28 +3179,43 @@ decorateType (ast * tree) return tree; } + LRVAL (tree) = RRVAL (tree) = 1; + if (tree->opval.op == LEFT_OP) + { + /* promote char to int */ + TETYPE (tree) = getSpec (TTYPE (tree) = + computeType (LTYPE (tree), + LTYPE (tree), /* no, not RTYPE! */ + TRUE)); + } + else /* RIGHT_OP */ + { + /* no promotion necessary */ + TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree)); + if (IS_LITERAL (TTYPE (tree))) + SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL; + } + /* if only the right side is a literal & we are shifting more than size of the left operand then zero */ if (IS_LITERAL (RTYPE (tree)) && - ((unsigned) floatFromVal (valFromType (RETYPE (tree)))) >= - (getSize (LTYPE (tree)) * 8)) + ((TYPE_UDWORD) floatFromVal (valFromType (RETYPE (tree)))) >= + (getSize (TETYPE (tree)) * 8)) { if (tree->opval.op==LEFT_OP || - (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree)))) { - lineno=tree->lineno; - werror (W_SHIFT_CHANGED, - (tree->opval.op == LEFT_OP ? "left" : "right")); - tree->type = EX_VALUE; - tree->left = tree->right = NULL; - tree->opval.val = constVal ("0"); - TETYPE (tree) = TTYPE (tree) = tree->opval.val->type; - return tree; - } + (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree)))) + { + lineno=tree->lineno; + werror (W_SHIFT_CHANGED, + (tree->opval.op == LEFT_OP ? "left" : "right")); + tree->type = EX_VALUE; + tree->left = tree->right = NULL; + tree->opval.val = constVal ("0"); + TETYPE (tree) = TTYPE (tree) = tree->opval.val->type; + return tree; + } } - LRVAL (tree) = RRVAL (tree) = 1; - TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree)); - if (IS_LITERAL (TTYPE (tree))) - SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL; + return tree; /*------------------------------------------------------------------*/ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index a6a2193a..a3f26e67 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1732,7 +1732,7 @@ getArraySizePtr (operand * op) /*-----------------------------------------------------------------*/ /* perform "usual unary conversions" */ /*-----------------------------------------------------------------*/ -operand * +static operand * usualUnaryConversions (operand * op) { if (IS_INTEGRAL (operandType (op))) @@ -2730,6 +2730,7 @@ geniCodeLeftShift (operand * left, operand * right) { iCode *ic; + left = usualUnaryConversions (left); ic = newiCode (LEFT_OP, left, right); IC_RESULT (ic) = newiTempOperand (operandType (left), 0); ADDTOCHAIN (ic); @@ -3796,11 +3797,11 @@ ast2iCode (ast * tree,int lvl) case RIGHT_OP: return geniCodeRightShift (geniCodeRValue (left, FALSE), geniCodeRValue (right, FALSE)); - case CAST: + case CAST: #if 0 // this indeed needs a second thought { operand *op; - + // let's keep this simple: get the rvalue we need op=geniCodeRValue (right, FALSE); // now cast it to whatever we want @@ -4000,7 +4001,7 @@ ast2iCode (ast * tree,int lvl) return NULL; case CRITICAL: - geniCodeCritical (tree, lvl); + geniCodeCritical (tree, lvl); } return NULL; diff --git a/src/SDCCval.c b/src/SDCCval.c index 66c6264d..7657be6b 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1306,7 +1306,7 @@ valShift (value * lval, value * rval, int lr) SPEC_USIGN (val->type) = SPEC_USIGN (lval->etype); SPEC_LONG (val->type) = SPEC_LONG (lval->etype); - if (getSize (lval->type) * 8 <= (TYPE_UDWORD) floatFromVal (rval) && + if (getSize (val->type) * 8 <= (TYPE_UDWORD) floatFromVal (rval) && /* left shift */ (lr || /* right shift and unsigned */ diff --git a/support/valdiag/tests/overflow.c b/support/valdiag/tests/overflow.c index 0e92a04f..550e3b0c 100644 --- a/support/valdiag/tests/overflow.c +++ b/support/valdiag/tests/overflow.c @@ -11,11 +11,11 @@ void foo(void) #ifdef TEST1 void foo(void) { - i = 1 << 10; /* WARNING(SDCC) */ - i = 1u << 10; - i = 1u << 18; /* WARNING(SDCC) */ + i = 1 << 10; + i = 1 << 16; /* WARNING(SDCC) */ + i = 1u << 16; /* WARNING(SDCC) */ i = 1L << 31; - i = 1L << 32; /* WARNING(SDCC) */ + i = 1L << 32; /* WARNING */ } #endif -- 2.47.2