widen array indices to int type before doing other arithmetic
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Nov 2000 23:22:55 +0000 (23:22 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Nov 2000 23:22:55 +0000 (23:22 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@504 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCicode.c

index 36410ad3328e43e1ecbfaffd1e6f4283e8316393..874e318cc2be9fde904a46cd0b6704773b7dddb3 100644 (file)
@@ -1624,9 +1624,12 @@ operand *geniCodeAdd (operand *left, operand *right )
        isarray = left->isaddr;
        size = 
            operandFromLit(getSize(ltype->next));
+       if (getSize(ltype) > 1 && (getSize(rtype) < INTSIZE)) 
+       {
+           right = geniCodeCast(INTTYPE,right,TRUE);       
+       }
        right = geniCodeMultiply (right ,size);
-       if (getSize(ltype) > 1) 
-               right = geniCodeCast(INTTYPE,right,TRUE);
+
        resType = copyLinkChain(ltype);
     }
     else { /* make them the same size */
@@ -1723,11 +1726,18 @@ operand *geniCodeArray (operand *left,operand *right)
     
     if (IS_PTR(ltype)) {
        if (IS_PTR(ltype->next) && left->isaddr)
+       {
            left = geniCodeRValue(left,FALSE);
+       }
        return geniCodeDerefPtr(geniCodeAdd(left,right));
     }
 
     /* array access */
+    if (/* getSize(ltype) > 1 &&  */(getSize(operandType(right)) < INTSIZE)) 
+    {
+        /* Widen the index type to int first. */
+       right = geniCodeCast(INTTYPE,right,TRUE);           
+    }
     right = geniCodeMultiply(right,
                             operandFromLit(getSize(ltype->next)));