Browse Source

* destroyreg overwrote some memory if the reg was an FPU register

Jonas Maebe 25 years ago
parent
commit
2eb73a055e
1 changed files with 25 additions and 22 deletions
  1. 25 22
      compiler/daopt386.pas

+ 25 - 22
compiler/daopt386.pas

@@ -1240,6 +1240,10 @@ Var TmpWState, TmpRState: Byte;
     Counter: TRegister;
     Counter: TRegister;
 Begin
 Begin
   Reg := Reg32(Reg);
   Reg := Reg32(Reg);
+  { the following happens for fpu registers }
+  if (reg < low(NrOfInstrSinceLastMod)) or
+     (reg > high(NrOfInstrSinceLastMod)) then
+    exit;
   NrOfInstrSinceLastMod[Reg] := 0;
   NrOfInstrSinceLastMod[Reg] := 0;
   If (Reg >= R_EAX) And (Reg <= R_EDI)
   If (Reg >= R_EAX) And (Reg <= R_EDI)
     Then
     Then
@@ -1339,9 +1343,8 @@ Begin {checks whether the two ops are equal}
 End;
 End;
 
 
 Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
 Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
-{$ifdef csdebug}
-var hp: pai;
-{$endif csdebug}
+var
+  hp: pai;
 Begin {checks whether two Paicpu instructions are equal}
 Begin {checks whether two Paicpu instructions are equal}
   If Assigned(p1) And Assigned(p2) And
   If Assigned(p1) And Assigned(p2) And
      (Pai(p1)^.typ = ait_instruction) And
      (Pai(p1)^.typ = ait_instruction) And
@@ -1368,11 +1371,10 @@ Begin {checks whether two Paicpu instructions are equal}
               Begin
               Begin
                 With Paicpu(p2)^.oper[0].ref^ Do
                 With Paicpu(p2)^.oper[0].ref^ Do
                   Begin
                   Begin
-                    If Not(Base in [procinfo^.FramePointer, R_NO, R_ESP])
-       {it won't do any harm if the register is already in RegsLoadedForRef}
-                      Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
-                    If Not(Index in [procinfo^.FramePointer, R_NO, R_ESP])
-                      Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
+                    If Not(Base in [procinfo^.FramePointer, R_NO, R_ESP]) Then
+                      RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
+                    If Not(Index in [procinfo^.FramePointer, R_NO, R_ESP]) Then
+                      RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
                   End;
                   End;
  {add the registers from the reference (.oper[0]) to the RegInfo, all registers
  {add the registers from the reference (.oper[0]) to the RegInfo, all registers
   from the reference are the same in the old and in the new instruction
   from the reference are the same in the old and in the new instruction
@@ -1392,24 +1394,22 @@ Begin {checks whether two Paicpu instructions are equal}
             With Paicpu(p2)^.oper[0].ref^ Do
             With Paicpu(p2)^.oper[0].ref^ Do
               Begin
               Begin
                 If Not(Base in [procinfo^.FramePointer,
                 If Not(Base in [procinfo^.FramePointer,
-                                Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP])
+                     Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP]) Then
  {it won't do any harm if the register is already in RegsLoadedForRef}
  {it won't do any harm if the register is already in RegsLoadedForRef}
-                  Then
-                    Begin
-                      RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
+                  Begin
+                    RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
 {$ifdef csdebug}
 {$ifdef csdebug}
-                      Writeln(att_reg2str[base], ' added');
+                    Writeln(att_reg2str[base], ' added');
 {$endif csdebug}
 {$endif csdebug}
-                    end;
+                  end;
                 If Not(Index in [procinfo^.FramePointer,
                 If Not(Index in [procinfo^.FramePointer,
-                                 Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP])
-                  Then
-                    Begin
-                      RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
+                     Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP]) Then
+                  Begin
+                    RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
 {$ifdef csdebug}
 {$ifdef csdebug}
-                      Writeln(att_reg2str[index], ' added');
+                    Writeln(att_reg2str[index], ' added');
 {$endif csdebug}
 {$endif csdebug}
-                    end;
+                  end;
 
 
               End;
               End;
             If Not(Reg32(Paicpu(p2)^.oper[1].reg) In [procinfo^.FramePointer,R_NO,R_ESP])
             If Not(Reg32(Paicpu(p2)^.oper[1].reg) In [procinfo^.FramePointer,R_NO,R_ESP])
@@ -1657,7 +1657,7 @@ Begin
         if assigned(hp^.next) then
         if assigned(hp^.next) then
           hp^.next^.previous := hp;
           hp^.next^.previous := hp;
 {$endif statedebug}
 {$endif statedebug}
-        DestroyReg(PPaiProp(PaiObj^.OptInfo), o.reg, true);
+        DestroyReg(PPaiProp(PaiObj^.OptInfo), reg32(o.reg), true);
       end;
       end;
     top_ref:
     top_ref:
       Begin
       Begin
@@ -2335,7 +2335,10 @@ End.
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.86  2000-04-10 12:45:56  jonas
+ Revision 1.87  2000-04-29 16:56:45  jonas
+   * destroyreg overwrote some memory if the reg was an FPU register
+
+ Revision 1.86  2000/04/10 12:45:56  jonas
    * fixed a serious bug in the CSE which (I think) only showed with
    * fixed a serious bug in the CSE which (I think) only showed with
      -dnewoptimizations when using multi-dimensional arrays with
      -dnewoptimizations when using multi-dimensional arrays with
      elements of a size different from 1, 2 or 4 (especially strings).
      elements of a size different from 1, 2 or 4 (especially strings).