]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCast.c (decorateType),
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 6 Jan 2004 22:03:36 +0000 (22:03 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 6 Jan 2004 22:03:36 +0000 (22:03 +0000)
* 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
src/SDCCast.c
src/SDCCicode.c
src/SDCCval.c
support/valdiag/tests/overflow.c

index 156d91eef1991c159c0e05f6af24fa96101fc91d..fdd328cb3d8a98b2987e781da5e0549e53d84691 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
 2004-01-06 Bernhard Held <bernhard@bernhardheld.de>
 
-       * 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 <jesusc@ece.ubc.ca>
 
index 91cda09b09ff762c04ccb830c32b2bdfce40a991..15f92a760e34a7147bb041efeff3b514693915c9 100644 (file)
@@ -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;
 
       /*------------------------------------------------------------------*/
index a6a2193a5cbe7116fccc9e8d259bf759c97ede25..a3f26e677ac067660253f6058407c220b533bab9 100644 (file)
@@ -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;
index 66c6264d1a82ed1abffb75035d0207ff699d6ac3..7657be6b206e6fb01b703ba5b174a0b38213aae8 100644 (file)
@@ -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 */
index 0e92a04f8afbbea55f6b77ba86c73b039255593b..550e3b0c1084e4629cd5a7ac506ef1b163ce934c 100644 (file)
@@ -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