Browse Source

* exit in try..finally blocks needed a second fix
* a raise in a try..finally lead into a endless loop, fixed

florian 26 years ago
parent
commit
bf6bed1bf7
2 changed files with 32 additions and 12 deletions
  1. 25 9
      compiler/cg386flw.pas
  2. 7 3
      compiler/cgai386.pas

+ 25 - 9
compiler/cg386flw.pas

@@ -561,6 +561,7 @@ do_jmp:
              end
              end
            else
            else
              begin
              begin
+                emitcall('FPC_POPADDRSTACK');
                 emitcall('FPC_RERAISE');
                 emitcall('FPC_RERAISE');
              end;
              end;
        end;
        end;
@@ -606,13 +607,12 @@ do_jmp:
            exit;
            exit;
 
 
          emitlab(exceptlabel);
          emitlab(exceptlabel);
+         emitcall('FPC_POPADDRSTACK');
          exprasmlist^.concat(new(pai386,
          exprasmlist^.concat(new(pai386,
            op_reg(A_POP,S_L,R_EAX)));
            op_reg(A_POP,S_L,R_EAX)));
          exprasmlist^.concat(new(pai386,
          exprasmlist^.concat(new(pai386,
            op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
            op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
-         emitjmp(C_NE,doexceptlabel);
-         emitcall('FPC_POPADDRSTACK');
-         emitjmp(C_None,endexceptlabel);
+         emitjmp(C_E,endexceptlabel);
          emitlab(doexceptlabel);
          emitlab(doexceptlabel);
 
 
          if assigned(p^.right) then
          if assigned(p^.right) then
@@ -690,7 +690,7 @@ do_jmp:
 
 
       var
       var
          finallylabel,noreraiselabel : pasmlabel;
          finallylabel,noreraiselabel : pasmlabel;
-         oldaktexitlabel : pasmlabel;
+         oldaktexitlabel,exitfinallylabel : pasmlabel;
          oldaktexit2label : pasmlabel;
          oldaktexit2label : pasmlabel;
 
 
       begin
       begin
@@ -700,8 +700,9 @@ do_jmp:
          getlabel(noreraiselabel);
          getlabel(noreraiselabel);
          oldaktexitlabel:=aktexitlabel;
          oldaktexitlabel:=aktexitlabel;
          oldaktexit2label:=aktexit2label;
          oldaktexit2label:=aktexit2label;
-         aktexitlabel:=finallylabel;
-         aktexit2label:=finallylabel;
+         getlabel(exitfinallylabel);
+         aktexitlabel:=exitfinallylabel;
+         aktexit2label:=exitfinallylabel;
 
 
          push_int(1); { Type of stack-frame must be pushed}
          push_int(1); { Type of stack-frame must be pushed}
          emitcall('FPC_PUSHEXCEPTADDR');
          emitcall('FPC_PUSHEXCEPTADDR');
@@ -720,7 +721,7 @@ do_jmp:
            exit;
            exit;
 
 
          emitlab(finallylabel);
          emitlab(finallylabel);
-
+         emitcall('FPC_POPADDRSTACK');
          { finally code }
          { finally code }
          secondpass(p^.right);
          secondpass(p^.right);
          if codegenerror then
          if codegenerror then
@@ -730,9 +731,20 @@ do_jmp:
          exprasmlist^.concat(new(pai386,
          exprasmlist^.concat(new(pai386,
            op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
            op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
          emitjmp(C_E,noreraiselabel);
          emitjmp(C_E,noreraiselabel);
+         exprasmlist^.concat(new(pai386,
+           op_reg(A_DEC,S_L,R_EAX)));
+         emitjmp(C_NE,oldaktexitlabel);
          emitcall('FPC_RERAISE');
          emitcall('FPC_RERAISE');
+         { reraise never returns ! }
+         emitlab(exitfinallylabel);
+
+         { do some magic for exit in the try block }
+         exprasmlist^.concat(new(pai386,
+           op_reg(A_POP,S_L,R_EAX)));
+         exprasmlist^.concat(new(pai386,
+           op_const(A_PUSH,S_L,2)));
+         emitjmp(C_NONE,finallylabel);
          emitlab(noreraiselabel);
          emitlab(noreraiselabel);
-         emitcall('FPC_POPADDRSTACK');
          aktexitlabel:=oldaktexitlabel;
          aktexitlabel:=oldaktexitlabel;
          aktexit2label:=oldaktexit2label;
          aktexit2label:=oldaktexit2label;
       end;
       end;
@@ -760,7 +772,11 @@ do_jmp:
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.42  1999-07-26 09:41:59  florian
+  Revision 1.43  1999-07-26 12:13:45  florian
+    * exit in try..finally blocks needed a second fix
+    * a raise in a try..finally lead into a endless loop, fixed
+
+  Revision 1.42  1999/07/26 09:41:59  florian
     * bugs 494-496 fixed
     * bugs 494-496 fixed
 
 
   Revision 1.41  1999/07/05 20:13:09  peter
   Revision 1.41  1999/07/05 20:13:09  peter

+ 7 - 3
compiler/cgai386.pas

@@ -2954,6 +2954,8 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
       if (procinfo.flags and pi_needs_implicit_finally)<>0 then
       if (procinfo.flags and pi_needs_implicit_finally)<>0 then
         begin
         begin
            getlabel(noreraiselabel);
            getlabel(noreraiselabel);
+           exprasmlist^.concat(new(pai386,
+             op_sym(A_CALL,S_NO,newasmsymbol('FPC_POPADDRSTACK'))));
            exprasmlist^.concat(new(pai386,
            exprasmlist^.concat(new(pai386,
              op_reg(A_POP,S_L,R_EAX)));
              op_reg(A_POP,S_L,R_EAX)));
            exprasmlist^.concat(new(pai386,
            exprasmlist^.concat(new(pai386,
@@ -2974,8 +2976,6 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
            exprasmlist^.concat(new(pai386,
            exprasmlist^.concat(new(pai386,
              op_sym(A_CALL,S_NO,newasmsymbol('FPC_RERAISE'))));
              op_sym(A_CALL,S_NO,newasmsymbol('FPC_RERAISE'))));
            exprasmlist^.concat(new(pai_label,init(noreraiselabel)));
            exprasmlist^.concat(new(pai_label,init(noreraiselabel)));
-           exprasmlist^.concat(new(pai386,
-             op_sym(A_CALL,S_NO,newasmsymbol('FPC_POPADDRSTACK'))));
         end;
         end;
 
 
       { call __EXIT for main program }
       { call __EXIT for main program }
@@ -3116,7 +3116,11 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.17  1999-07-22 09:37:38  florian
+  Revision 1.18  1999-07-26 12:13:46  florian
+    * exit in try..finally blocks needed a second fix
+    * a raise in a try..finally lead into a endless loop, fixed
+
+  Revision 1.17  1999/07/22 09:37:38  florian
     + resourcestring implemented
     + resourcestring implemented
     + start of longstring support
     + start of longstring support