1999-08-6 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
authorHerman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
Sat, 7 Aug 1999 05:57:14 +0000 (23:57 -0600)
committerJeff Law <law@gcc.gnu.org>
Sat, 7 Aug 1999 05:57:14 +0000 (23:57 -0600)
        * reg-stack.c (change_stack) Fixed problem with negative array index.

From-SVN: r28570

gcc/ChangeLog
gcc/reg-stack.c

index 3510a477bb6ac428b8f13f1d0287491ae12d2c9c..6eaa20f4fc5219725e311ffef4117e0c82eaa959 100644 (file)
@@ -1,3 +1,7 @@
+1999-08-6 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
+
+       * reg-stack.c (change_stack) Fixed problem with negative array index.
+
 Fri Aug  6 23:08:44 1999  Jeffrey A Law  (law@cygnus.com)
 
        * extend.texi, install.texi: Fix spelling mistakes.
index 8a27b9563b62c087f7998c0061bdefa450f94a6c..dd4a87e697cdada17e85db0b62aa2d80c6fe0b4a 100644 (file)
@@ -2640,43 +2640,46 @@ change_stack (insn, old, new, when)
       if (old->top != new->top)
        abort ();
 
-      /* Loop here emitting swaps until the stack is correct.  The
-        worst case number of swaps emitted is N + 2, where N is the
+      /* If the stack is not empty (new->top != -1), loop here emitting
+        swaps until the stack is correct. 
+
+        The worst case number of swaps emitted is N + 2, where N is the
         depth of the stack.  In some cases, the reg at the top of
         stack may be correct, but swapped anyway in order to fix
         other regs.  But since we never swap any other reg away from
         its correct slot, this algorithm will converge.  */
 
-      do
-       {
-         /* Swap the reg at top of stack into the position it is
-            supposed to be in, until the correct top of stack appears.  */
+      if (new->top != -1)
+       do
+         {
+           /* Swap the reg at top of stack into the position it is
+              supposed to be in, until the correct top of stack appears.  */
 
-         while (old->reg[old->top] != new->reg[new->top])
-           {
-             for (reg = new->top; reg >= 0; reg--)
-               if (new->reg[reg] == old->reg[old->top])
-                 break;
+           while (old->reg[old->top] != new->reg[new->top])
+             {
+               for (reg = new->top; reg >= 0; reg--)
+                 if (new->reg[reg] == old->reg[old->top])
+                   break;
 
-             if (reg == -1)
-               abort ();
+               if (reg == -1)
+                 abort ();
 
-             emit_swap_insn (insn, old,
-                             FP_MODE_REG (old->reg[reg], DFmode));
-           }
+               emit_swap_insn (insn, old,
+                               FP_MODE_REG (old->reg[reg], DFmode));
+             }
 
-         /* See if any regs remain incorrect.  If so, bring an
+           /* See if any regs remain incorrect.  If so, bring an
             incorrect reg to the top of stack, and let the while loop
             above fix it.  */
 
-         for (reg = new->top; reg >= 0; reg--)
-           if (new->reg[reg] != old->reg[reg])
-             {
-               emit_swap_insn (insn, old,
-                               FP_MODE_REG (old->reg[reg], DFmode));
-               break;
-             }
-       } while (reg >= 0);
+           for (reg = new->top; reg >= 0; reg--)
+             if (new->reg[reg] != old->reg[reg])
+               {
+                 emit_swap_insn (insn, old,
+                                 FP_MODE_REG (old->reg[reg], DFmode));
+                 break;
+               }
+         } while (reg >= 0);
 
       /* At this point there must be no differences.  */