fix segfault on casting int to pointer
[fw/sdcc] / src / mcs51 / ralloc.c
index cf088764cb47bace9002844f69fe6ec854d8b9c9..09fd032dfcc3b2d7ef83d7ee2ab34bc5b3d5a684 100644 (file)
@@ -1076,7 +1076,8 @@ static void serialRegAssign (eBBlock **ebbs, int count)
                
                /* if we need ptr regs for the right side
                   then mark it */
-               if (POINTER_GET(ic) && getSize(OP_SYMBOL(IC_LEFT(ic))->type) 
+               if (POINTER_GET(ic) && IS_SYMOP(IC_LEFT(ic)) 
+                && getSize(OP_SYMBOL(IC_LEFT(ic))->type) 
                    <= PTRSIZE) 
                {
                    mcs51_ptrRegReq++;
@@ -1460,11 +1461,13 @@ static iCode *farSpacePackable (iCode *ic)
 /*-----------------------------------------------------------------*/
 static int packRegsForAssign (iCode *ic,eBBlock *ebp)
 {
-    iCode *dic, *sic;
-    
+       iCode *dic, *sic;
+       link *etype = operandType(IC_RIGHT(ic));
+       
     if (!IS_ITEMP(IC_RIGHT(ic))       ||       
        OP_SYMBOL(IC_RIGHT(ic))->isind ||
-       OP_LIVETO(IC_RIGHT(ic)) > ic->seq) {
+       OP_LIVETO(IC_RIGHT(ic)) > ic->seq ||
+       IS_BITFIELD(etype)) {
        return 0;
     }
        
@@ -1531,7 +1534,12 @@ static int packRegsForAssign (iCode *ic,eBBlock *ebp)
     
     if (!dic)
        return 0 ; /* did not find */
-           
+       
+    /* if assignment then check that right is not a bit */
+    if (ASSIGNMENT(dic) && !POINTER_SET(dic)) {
+           link *etype = operandType(IC_RIGHT(dic));
+           if (IS_BITFIELD(etype)) return 0;
+    }
     /* if the result is on stack or iaccess then it must be
        the same atleast one of the operands */
     if (OP_SYMBOL(IC_RESULT(ic))->onStack  || 
@@ -1548,7 +1556,7 @@ static int packRegsForAssign (iCode *ic,eBBlock *ebp)
              (IC_RIGHT(dic) &&
               IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
            return 0;                
-    }
+    }    
 pack:
     /* found the definition */
     /* replace the result with the result of */
@@ -2241,12 +2249,10 @@ static void packRegisters (eBBlock *ebp)
           the result of that operation is not on stack then
           we can leave the result of this operation in acc:b
           combination */
-       if ((IS_ARITHMETIC_OP(ic) 
-            
-            || IS_BITWISE_OP(ic) 
-            
+       if ((IS_ARITHMETIC_OP(ic)            
+            || IS_BITWISE_OP(ic)            
             || ic->op == LEFT_OP || ic->op == RIGHT_OP
-            
+            || (ic->op == ADDRESS_OF && isOperandOnStack(IC_LEFT(ic)))
             ) &&
            IS_ITEMP(IC_RESULT(ic)) &&
            getSize(operandType(IC_RESULT(ic))) <= 2)