* src/SDCCast.c (addCast): fixed bug #908454 by promoting bits to char
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Mar 2004 21:38:02 +0000 (21:38 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Mar 2004 21:38:02 +0000 (21:38 +0000)
* 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
src/SDCCast.c
src/SDCCicode.c
src/SDCCsymt.c

index 523c4c12596c0ee7ae8dc26122ae0247d6c83e90..fcadef56c1e74af6d7438a73540db457fdd6e77a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-03-07 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * 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 <borut.razem AT siol.net>
 
        * support/Util/findme.c: alloca() replaced with malloc()/free() pair
index 8e20910cf1c505dae56081cc9e485c210bbe0a52..7f34fdb5b37b8319ce6f4d8b83e9c6a5dff2a7bc 100644 (file)
@@ -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;
index f4e50eba162c9333a736ee99c9196b129101bc24..b359b83091109012f175425393b2c0e28ca7f747 100644 (file)
@@ -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,
index 4ceceaf007bd50c5a55f08ee18cb4d8d12a879cb..53901c347ce67177c4fb4cf3021295e5275e1bed 100644 (file)
@@ -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;