Found the reason for it, or at least what looks like the reason... the RemoveDeadCodeAfterJump routine, which removes all instructions between a "jmp" instruction and the next live label (since those instructions will never get executed), doesn't stop if it hits the SEH section and strips all that too.  Because of the "while True do" block covering the entire procedure, the function epilogue is suppressed by an unconditional jump and so gets stripped out (arguably fine in this case), but the optimizer doesn't think to stop if it goes past the final instruction.  I'll start doing a bisect to see if I can locate where this is corrected... or just write it myself if that fails.

Gareth aka. Kit

On 15/01/2022 15:25, Florian Klämpfl via fpc-devel wrote:
Am 13.01.2022 um 16:49 schrieb Martin Frb via fpc-devel:
In the  below code compiled with 3.2.3 (today and early Dec)
when the exception is reached the app exits.

There is no code from finally, nor from except block executed.

The "randomize" is just to put some code into each block. No special meaning otherwise.

This issue is on Win64. (works for 32 bit Win)
And appears to be ok in 3.3.1.

It happens only with -O1 or higher, the compiler optimizes away all the exception data (diff between -O- and -O1):

176,180d170
< # [37] end;
<       nop
<       leaq    (%rbp),%rsp
<       popq    %rbp
<       ret
183,195d172
<       .long   3
<       .long   0
<       .rva    .Lj27
<       .rva    .Lj28
<       .rva    P$PROJECT1$_$FOO_$$_fin$00000002
<       .long   0
<       .rva    .Lj22
<       .rva    .Lj23
<       .rva    P$PROJECT1$_$FOO_$$_fin$00000003
<       .long   1
<       .rva    .Lj20
<       .rva    .Lj17
<       .rva    .Lj18
199a177
> # [37] end;

Maybe Gareth can have a look?


     program Project1;
     {$mode objfpc}{$H+}

     uses SysUtils;

     var
       bar: boolean;

     procedure Foo;
     begin
       while true do begin
         try
           try
             try
               if bar then
                 raise Exception.Create('');
               Randomize;
             finally
               Randomize;
               try
                 Randomize;
               finally
                 Randomize;
               end;
             end;
             Randomize;
           finally
             Randomize;
           end;
           Randomize;
         except
           bar := false;
           Randomize;
         end;
       end;
     end;

     begin
       bar := true;
       Foo;
     end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to