* src/SDCCicode.c (geniCodeIfx): fix bug 1406131: always false while loop
[fw/sdcc] / src / SDCCicode.c
index 932820e962c915a2d107ec34ffc7b1978f627d8e..c8ebf3be39270a7fed38fe0f6d2f2559c629ed1b 100644 (file)
@@ -233,7 +233,7 @@ printOperand (operand * op, FILE * file)
       opetype = getSpec (operandType (op));
       if (IS_FLOAT (opetype))
         fprintf (file, "%g {", SPEC_CVAL (opetype).v_float);
-      if (IS_FIXED16X16 (opetype))
+      else if (IS_FIXED16X16 (opetype))
         fprintf (file, "%g {", doubleFromFixed16x16(SPEC_CVAL (opetype).v_fixed16x16));
       else
         fprintf (file, "0x%x {", (unsigned) floatFromVal (op->operand.valOperand));
@@ -989,6 +989,34 @@ isOperandInFarSpace (operand * op)
   return (IN_FARSPACE (SPEC_OCLS (etype)) ? TRUE : FALSE);
 }
 
+/*-----------------------------------------------------------------*/
+/* isOperandInPagedSpace - return true if operand is in pagedSpace */
+/*-----------------------------------------------------------------*/
+bool
+isOperandInPagedSpace (operand * op)
+{
+  sym_link *etype;
+
+  if (!op)
+    return FALSE;
+
+  if (!IS_SYMOP (op))
+    return FALSE;
+
+  if (!IS_TRUE_SYMOP (op))
+    {
+      if (SPIL_LOC (op))
+        etype = SPIL_LOC (op)->etype;
+      else
+        return FALSE;
+    }
+  else
+    {
+      etype = getSpec (operandType (op));
+    }
+  return (IN_PAGEDSPACE (SPEC_OCLS (etype)) ? TRUE : FALSE);
+}
+
 /*------------------------------------------------------------------*/
 /* isOperandInDirSpace - will return true if operand is in dirSpace */
 /*------------------------------------------------------------------*/
@@ -1299,15 +1327,12 @@ operandOperation (operand * left, operand * right,
                                  (TYPE_UDWORD) operandLitValue (right));
       break;
     case EQ_OP:
-      if (IS_FLOAT (let) ||
-          IS_FLOAT (ret))
+      if (IS_FLOAT (let) || IS_FLOAT (ret))
         {
           retval = operandFromLit (operandLitValue (left) ==
                                    operandLitValue (right));
         }
-      else
-      if (IS_FIXED16X16 (let) ||
-          IS_FIXED16X16 (ret))
+      else if (IS_FIXED16X16 (let) || IS_FIXED16X16 (ret))
         {
           retval = operandFromLit (operandLitValue (left) ==
                                    operandLitValue (right));
@@ -2170,7 +2195,7 @@ geniCodeMultiply (operand * left, operand * right, RESULT_TYPE resultType)
   /* code generated for 1 byte * 1 byte literal = 2 bytes result is more
      efficient in most cases than 2 bytes result = 2 bytes << literal
      if port has 1 byte muldiv */
-  if (p2 && !IS_FLOAT (letype) && !IS_FIXED (letype)
+  if ((p2 > 0) && !IS_FLOAT (letype) && !IS_FIXED (letype)
       && !((resultType == RESULT_TYPE_INT) && (getSize (resType) != getSize (ltype))
            && (port->support.muldiv == 1))
       && strcmp (port->target, "pic16") != 0  /* don't shift for pic */
@@ -2221,8 +2246,8 @@ geniCodeDivision (operand * left, operand * right, RESULT_TYPE resultType)
       !IS_FLOAT (letype) &&
       !IS_FIXED (letype) &&
       IS_UNSIGNED(letype) &&
-      (p2 = powof2 ((TYPE_UDWORD)
-                    floatFromVal (right->operand.valOperand)))) {
+      ((p2 = powof2 ((TYPE_UDWORD)
+                    floatFromVal (right->operand.valOperand))) > 0)) {
     ic = newiCode (RIGHT_OP, left, operandFromLit (p2)); /* right shift */
   }
   else
@@ -2618,8 +2643,7 @@ geniCodePostInc (operand * op)
     werror(W_SIZEOF_VOID);
   if (IS_FLOAT (rvtype))
     ic = newiCode ('+', rv, operandFromValue (constFloatVal ("1.0")));
-  else
-  if (IS_FIXED16X16 (rvtype))
+  else if (IS_FIXED16X16 (rvtype))
     ic = newiCode ('+', rv, operandFromValue (constFixed16x16Val ("1.0")));
   else
     ic = newiCode ('+', rv, operandFromLit (size));
@@ -2659,8 +2683,7 @@ geniCodePreInc (operand * op, bool lvalue)
     werror(W_SIZEOF_VOID);
   if (IS_FLOAT (roptype))
     ic = newiCode ('+', rop, operandFromValue (constFloatVal ("1.0")));
-  else
-  if (IS_FIXED16X16 (roptype))
+  else if (IS_FIXED16X16 (roptype))
     ic = newiCode ('+', rop, operandFromValue (constFixed16x16Val ("1.0")));
   else
     ic = newiCode ('+', rop, operandFromLit (size));
@@ -2710,8 +2733,7 @@ geniCodePostDec (operand * op)
     werror(W_SIZEOF_VOID);
   if (IS_FLOAT (rvtype))
     ic = newiCode ('-', rv, operandFromValue (constFloatVal ("1.0")));
-  else
-  if (IS_FIXED16X16 (rvtype))
+  else if (IS_FIXED16X16 (rvtype))
     ic = newiCode ('-', rv, operandFromValue (constFixed16x16Val ("1.0")));
   else
     ic = newiCode ('-', rv, operandFromLit (size));
@@ -2751,8 +2773,7 @@ geniCodePreDec (operand * op, bool lvalue)
     werror(W_SIZEOF_VOID);
   if (IS_FLOAT (roptype))
     ic = newiCode ('-', rop, operandFromValue (constFloatVal ("1.0")));
-  else
-  if (IS_FIXED16X16 (roptype))
+  else if (IS_FIXED16X16 (roptype))
     ic = newiCode ('-', rop, operandFromValue (constFixed16x16Val ("1.0")));
   else
     ic = newiCode ('-', rop, operandFromLit (size));
@@ -2833,6 +2854,7 @@ geniCodeAddressOf (operand * op)
   ADDTOCHAIN (ic);
   return IC_RESULT (ic);
 }
+
 /*-----------------------------------------------------------------*/
 /* setOClass - sets the output class depending on the pointer type */
 /*-----------------------------------------------------------------*/
@@ -3242,12 +3264,16 @@ geniCodeAssign (operand * left, operand * right, int nosupdate, int strictLval)
       isOperandGlobal (left))
     {
       symbol *sym = NULL;
+      operand *newRight;
 
       if (IS_TRUE_SYMOP (right))
         sym = OP_SYMBOL (right);
       ic = newiCode ('=', NULL, right);
-      IC_RESULT (ic) = right = newiTempOperand (ltype, 0);
-      SPIL_LOC (right) = sym;
+      IC_RESULT (ic) = newRight = newiTempOperand (ltype, 0);
+      /* avoid double fetch from volatile right, see bug 1369874 */
+      if (!isOperandVolatile (right, FALSE))
+        SPIL_LOC (newRight) = sym;
+      right = newRight;
       ADDTOCHAIN (ic);
     }
 
@@ -3609,8 +3635,6 @@ geniCodeIfx (ast * tree,int lvl)
         {
           if (tree->falseLabel)
             geniCodeGoto (tree->falseLabel);
-          else
-            assert (0);
         }
       goto exit;
     }