[fpc-devel] Issue 3.2.3 (ok in 3.3.1) Win64 "raise exception" does not go to "except"

J. Gareth Moreton gareth at moreton-family.com
Wed Jan 19 00:28:13 CET 2022

Commit af107ca8fee33355e8c35fab6fc5ba5290bd3ebc fixes the problem in the 
main branch, so this one should be merged into fixes_3_2.

Note that this commit also extends an optimisation in OptPass2JMP that 
is unrelated to the bug fix.  If this proves incompatible with the fixes 
branch, it can be ignored, because the bug fix is wholly contained 
within compiler/aoptobj.pas, while the additional optimisation is in 

If needs be, the following can be merged manually:

diff --git a/compiler/aoptobj.pas b/compiler/aoptobj.pas
index 33efd80aad..67b62606cb 100644
--- a/compiler/aoptobj.pas
+++ b/compiler/aoptobj.pas
@@ -1616,6 +1616,15 @@ Unit AoptObj;

      { Removes all instructions between an unconditional jump and the 
next label }
      procedure TAOptObj.RemoveDeadCodeAfterJump(p: tai);
+      const
+{$ifdef JVM}
+        TaiFence = SkipInstr + [ait_const, ait_realconst, 
ait_typedconst, ait_label, ait_jcatch];
+{$else JVM}
+        { Stop if it reaches SEH directive information in the form of
+          consts, which may occur if RemoveDeadCodeAfterJump is called on
+          the final RET instruction on x86, for example }
+        TaiFence = SkipInstr + [ait_const, ait_realconst, 
ait_typedconst, ait_label];
+{$endif JVM}
          hp1, hp2: tai;
@@ -1624,12 +1633,7 @@ Unit AoptObj;
          while GetNextInstruction(p, hp1) and
                (hp1 <> BlockEnd) and
-              (hp1.typ <> ait_label)
-{$ifdef JVM}
-              and (hp1.typ <> ait_jcatch)
-              do
-          if not(hp1.typ in ([ait_label]+skipinstr)) then
+              not (hp1.typ in TaiFence) do
                if (hp1.typ = ait_instruction) and
                   taicpu(hp1).is_jmp and
@@ -1658,9 +1662,7 @@ Unit AoptObj;
-            end
-          else
-            Break;
+            end;

      { If hp is a label, strip it if its reference count is zero.  
Repeat until

Gareth aka. Kit

This email has been checked for viruses by Avast antivirus software.

More information about the fpc-devel mailing list