* src/SDCCicode.c (geniCodeJumpTable): fixed bug #967601
[fw/sdcc] / src / SDCCicode.c
index 9b841e5219bc278fc546397106634b626160a5ad..cc530311e7077b22d4cd0bb37156f421fb4a083d 100644 (file)
@@ -3522,6 +3522,23 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree)
 
   falseLabel = newiTempLabel (buffer);
 
+  /* 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;
+    }
+
   /* so we can create a jumptable */
   /* first we rule out the boundary conditions */
   /* if only optimization says so */