From 7992852a53922946f1a842e067de610b0f2cd2ea Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Sun, 7 Mar 2004 21:38:02 +0000 Subject: [PATCH] * src/SDCCast.c (addCast): fixed bug #908454 by promoting bits to char * src/SDCCicode.c (usualBinaryConversions): op needs int type (geniCodeCast): cosmetic, don't preserve bit storage class (geniCodeLeftShift): added promotion (geniCodeLogic): fixed regression * src/SDCCsymt.c (computeTypeOr): accept bits too (compareType): 2nd part of fix for bug #908454, needed for bitfields git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3253 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 +++++++ src/SDCCast.c | 2 +- src/SDCCicode.c | 75 +++++++++---------------------------------------- src/SDCCsymt.c | 10 +++++-- 4 files changed, 33 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index 523c4c12..fcadef56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-03-07 Bernhard Held + + * src/SDCCast.c (addCast): fixed bug #908454 by promoting bits to char + * src/SDCCicode.c (usualBinaryConversions): op needs int type + (geniCodeCast): cosmetic, don't preserve bit storage class + (geniCodeLeftShift): added promotion + (geniCodeLogic): fixed regression + * src/SDCCsymt.c (computeTypeOr): accept bits too + (compareType): 2nd part of fix for bug #908454, needed for bitfields + 2004-03-07 Borut Razem * support/Util/findme.c: alloca() replaced with malloc()/free() pair diff --git a/src/SDCCast.c b/src/SDCCast.c index 8e20910c..7f34fdb5 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2059,7 +2059,7 @@ addCast (ast *tree, RESULT_TYPE resultType, bool upcast) upCasted = TRUE; break; case RESULT_TYPE_CHAR: - if (getSize (tree->etype) <= 1) + if (IS_CHAR (tree->etype)) return tree; newLink = newCharLink(); break; diff --git a/src/SDCCicode.c b/src/SDCCicode.c index f4e50eba..b359b830 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1766,68 +1766,14 @@ usualUnaryConversions (operand * op) static sym_link * usualBinaryConversions (operand ** op1, operand ** op2, - RESULT_TYPE resultType, char op) + RESULT_TYPE resultType, int op) { sym_link *ctype; sym_link *rtype = operandType (*op2); sym_link *ltype = operandType (*op1); -#define OLDONEBYTEOPS 1 - -#ifdef OLDONEBYTEOPS - bool oldOneByteOps = FALSE; - static bool saidHello = FALSE; - - if (strcmp (port->target, "pic14") == 0) - oldOneByteOps = TRUE; - if (getenv ("SDCC_NEWONEBYTEOPS")) - { - if (!saidHello) - { - fprintf (stderr, "Override: oldOneByteOps = FALSE\n"); - saidHello = TRUE; - } - oldOneByteOps = FALSE; - } - else if (getenv ("SDCC_OLDONEBYTEOPS")) - { - if (!saidHello) - { - fprintf (stderr, "Override: oldOneByteOps = TRUE\n"); - saidHello = TRUE; - } - oldOneByteOps = TRUE; - } - - - if ( oldOneByteOps - && ( (IS_CHAR (getSpec (ltype)) && !IS_UNSIGNED (getSpec (ltype))) - || (IS_CHAR (getSpec (rtype)) && !IS_UNSIGNED (getSpec (rtype))))) - /* one or two signed char operands: promote to int */ - resultType = RESULT_TYPE_INT; -#endif - ctype = computeType (ltype, rtype, resultType, op); -#ifdef OLDONEBYTEOPS - - if (oldOneByteOps) - { - if ( op == '*' - && IS_CHAR (getSpec (ltype)) && IS_UNSIGNED (getSpec (ltype)) - && IS_CHAR (getSpec (rtype)) && IS_UNSIGNED (getSpec (rtype))) - { - /* two unsigned char operands and Mult: no promotion */ - return ctype; - } - *op1 = geniCodeCast (ctype, *op1, TRUE); - *op2 = geniCodeCast (ctype, *op2, TRUE); - - return ctype; - } - -#endif - switch (op) { case '*': @@ -2034,7 +1980,8 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) /* preserve the storage class & output class */ /* of the original variable */ restype = getSpec (operandType (IC_RESULT (ic))); - if (!IS_LITERAL(opetype)) + if (!IS_LITERAL(opetype) && + !IS_BIT(opetype)) SPEC_SCLS (restype) = SPEC_SCLS (opetype); SPEC_OCLS (restype) = SPEC_OCLS (opetype); @@ -2840,12 +2787,15 @@ geniCodeUnaryMinus (operand * op) /* geniCodeLeftShift - gen i code for left shift */ /*-----------------------------------------------------------------*/ operand * -geniCodeLeftShift (operand * left, operand * right) +geniCodeLeftShift (operand * left, operand * right, RESULT_TYPE resultType) { iCode *ic; + sym_link *resType; ic = newiCode (LEFT_OP, left, right); - IC_RESULT (ic) = newiTempOperand (operandType (left), 0); + + resType = usualBinaryConversions (&left, &right, resultType, LEFT_OP); + IC_RESULT (ic) = newiTempOperand (resType, 0); ADDTOCHAIN (ic); return IC_RESULT (ic); } @@ -2926,7 +2876,7 @@ geniCodeLogic (operand * left, operand * right, int op) } } - ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_NONE, ' '); + ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_NOPROM, 0); ic = newiCode (op, left, right); IC_RESULT (ic) = newiTempOperand (newCharLink (), 1); @@ -3916,7 +3866,8 @@ ast2iCode (ast * tree,int lvl) case LEFT_OP: return geniCodeLeftShift (geniCodeRValue (left, FALSE), - geniCodeRValue (right, FALSE)); + geniCodeRValue (right, FALSE), + getResultTypeFromType (tree->ftype)); case RIGHT_OP: return geniCodeRightShift (geniCodeRValue (left, FALSE), @@ -4065,7 +4016,9 @@ ast2iCode (ast * tree,int lvl) geniCodeAssign (left, geniCodeLeftShift (geniCodeRValue (operandFromOperand (left) ,FALSE), - geniCodeRValue (right, FALSE)), 0); + geniCodeRValue (right, FALSE), + getResultTypeFromType (tree->ftype)), + 0); case RIGHT_ASSIGN: return geniCodeAssign (left, diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 4ceceaf0..53901c34 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1595,7 +1595,8 @@ static sym_link * computeTypeOr (sym_link * etype1, sym_link * etype2, sym_link * reType) { /* sanity check */ - assert (IS_CHAR (etype1) && IS_CHAR (etype2)); + assert ( (IS_CHAR (etype1) || IS_BIT (etype1)) + && (IS_CHAR (etype2) || IS_BIT (etype2))); if (SPEC_USIGN (etype1) == SPEC_USIGN (etype2)) { @@ -1904,7 +1905,12 @@ compareType (sym_link * dest, sym_link * src) { if (SPEC_USIGN (dest) == SPEC_USIGN (src) && IS_INTEGRAL (dest) && IS_INTEGRAL (src) && - getSize (dest) == getSize (src)) + /* I would prefer + bitsForType (dest) == bitsForType (src)) + instead of the next two lines, but the regression tests fail with + them; I guess it's a problem with replaceCheaperOp */ + getSize (dest) == getSize (src) && + !(!IS_BIT (dest) && IS_BIT (src))) return 1; else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src)) return -1; -- 2.30.2