* src/SDCCicode.c (geniCodeSwitch, geniCodeJumpTable): fixed
[fw/sdcc] / src / SDCCicode.c
index 4d0a9f4bf1d4a488b6c1c19f077fe91c19ffca2d..334ff8d83d0430da9b51f67a73da5b9b9f9e9bf0 100644 (file)
@@ -3699,23 +3699,6 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree)
         }
     }
 
-  /* If cond is volatile, it might change after the boundary  */
-  /* conditions are tested to an out of bounds value, causing */
-  /* a jump to a location outside of the jump table. To avoid */
-  /* this possibility, use a non-volatile copy of it instead. */
-  if (IS_OP_VOLATILE (cond))
-    {
-      operand * newcond;
-      iCode * ic;
-      
-      newcond = newiTempOperand (operandType (cond), TRUE);
-      newcond->isvolatile = 0;
-      ic = newiCode ('=', NULL, cond);
-      IC_RESULT (ic) = newcond;
-      ADDTOCHAIN (ic);
-      cond = newcond;
-    }
-
   /* first we rule out the boundary conditions */
   /* if only optimization says so */
   if (needRangeCheck)
@@ -3785,6 +3768,22 @@ geniCodeSwitch (ast * tree,int lvl)
         }
       goto defaultOrBreak;
     }
+  
+  /* If cond is volatile, it might change while we are trying to */
+  /* find the matching case. To avoid this possibility, make a   */
+  /* non-volatile copy to use instead. */
+  if (IS_OP_VOLATILE (cond))
+    {
+      operand * newcond;
+      iCode * ic;
+      
+      newcond = newiTempOperand (operandType (cond), TRUE);
+      newcond->isvolatile = 0;
+      ic = newiCode ('=', NULL, cond);
+      IC_RESULT (ic) = newcond;
+      ADDTOCHAIN (ic);
+      cond = newcond;
+    }
 
   /* if we can make this a jump table */
   if (geniCodeJumpTable (cond, caseVals, tree))