View Issue Details

IDProjectCategoryView StatusLast Update
0035841FPCCompilerpublic2020-10-10 12:12
ReporterJ. Gareth Moreton Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64-win64OSMicrosoft Windows 
Product Version3.0.4 
Fixed in Version3.3.1 
Summary0035841: Split from #32913 - Nested try blocks with Exit cause assembler error
DescriptionSplit from issue 0032913. If you have the following construct, the assembly of the source code fails because the label that Exit is meant to jump to is never created:

try
  ...
except
  try
    ...
    Exit;
  finally
    ...
  end;
end;

The following patch fixes this issue.
Steps To ReproduceSee above.
Additional InformationThis bug was previously only visible if there was no code was present in the try part of the try..except block, because that arrangement raised an internal error instead.
TagsNo tags attached.
Fixed in Revision47066
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0032913 feedbackFlorian nested try blocks with exit gives Error: Internal error 

Activities

J. Gareth Moreton

2019-07-12 19:33

developer  

i35841.patch (1,767 bytes)   
Index: compiler/x86_64/nx64flw.pas
===================================================================
--- compiler/x86_64/nx64flw.pas	(revision 42348)
+++ compiler/x86_64/nx64flw.pas	(working copy)
@@ -311,6 +311,12 @@
           InternalError(2014031601);
       end;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     flowcontrol:=[fc_inflowcontrol];
     cg.a_label(current_asmdata.CurrAsmList,finallylabel);
     { generate finally code as a separate procedure }
@@ -421,6 +427,12 @@
         current_procinfo.CurrBreakLabel:=breakexceptlabel;
       end;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     flowcontrol:=[fc_inflowcontrol];
     { on statements }
     if assigned(right) then
@@ -509,6 +521,12 @@
     { restore all saved labels }
     endexceptlabel:=oldendexceptlabel;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     { restore the control flow labels }
     current_procinfo.CurrExitLabel:=oldCurrExitLabel;
     if assigned(oldBreakLabel) then
i35841.patch (1,767 bytes)   

Florian

2020-10-08 22:38

administrator   ~0126154

Thanks, finally applied.

Do-wan Kim

2020-10-09 06:31

reporter   ~0126166

This is copy and paste patch for i386.
35841_n386flw.pas.patch (1,808 bytes)   
Index: compiler/i386/n386flw.pas
===================================================================
--- compiler/i386/n386flw.pas	(revision 47067)
+++ compiler/i386/n386flw.pas	(working copy)
@@ -384,6 +384,12 @@
     { end cleanup }
     current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     { generate finally code as a separate procedure }
     { !!! this resets flowcontrol, how to check flow away? }
     if not implicitframe then
@@ -583,6 +589,12 @@
         current_procinfo.CurrBreakLabel:=breakexceptlabel;
       end;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     flowcontrol:=[fc_inflowcontrol];
     { on statements }
     if assigned(right) then
@@ -661,6 +673,12 @@
     { restore all saved labels }
     endexceptlabel:=oldendexceptlabel;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if (fc_exit in flowcontrol) and (fc_inflowcontrol in oldflowcontrol) then
+      Include(oldflowcontrol, fc_exit);
+
     { restore the control flow labels }
     current_procinfo.CurrExitLabel:=oldCurrExitLabel;
     if assigned(oldBreakLabel) then
35841_n386flw.pas.patch (1,808 bytes)   

Do-wan Kim

2020-10-10 08:08

reporter   ~0126201

Update i386 patch after r47070.
35841_v2_n386flw.pas.patch (2,015 bytes)   
Index: compiler/i386/n386flw.pas
===================================================================
--- compiler/i386/n386flw.pas	(revision 47070)
+++ compiler/i386/n386flw.pas	(working copy)
@@ -384,6 +384,12 @@
     { end cleanup }
     current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if ((flowcontrol*[fc_exit,fc_break,fc_continue])<>[]) and (fc_inflowcontrol in oldflowcontrol) then
+      oldflowcontrol:=oldflowcontrol+(flowcontrol*[fc_exit,fc_break,fc_continue]);
+
     { generate finally code as a separate procedure }
     { !!! this resets flowcontrol, how to check flow away? }
     if not implicitframe then
@@ -583,6 +589,12 @@
         current_procinfo.CurrBreakLabel:=breakexceptlabel;
       end;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if ((flowcontrol*[fc_exit,fc_break,fc_continue])<>[]) and (fc_inflowcontrol in oldflowcontrol) then
+      oldflowcontrol:=oldflowcontrol+(flowcontrol*[fc_exit,fc_break,fc_continue]);
+
     flowcontrol:=[fc_inflowcontrol];
     { on statements }
     if assigned(right) then
@@ -661,6 +673,12 @@
     { restore all saved labels }
     endexceptlabel:=oldendexceptlabel;
 
+    { i32913 - if the try..finally block is also inside a try..finally or
+      try..except block, make a note of any Exit calls so all necessary labels
+      are generated. [Kit] }
+    if ((flowcontrol*[fc_exit,fc_break,fc_continue])<>[]) and (fc_inflowcontrol in oldflowcontrol) then
+      oldflowcontrol:=oldflowcontrol+(flowcontrol*[fc_exit,fc_break,fc_continue]);
+
     { restore the control flow labels }
     current_procinfo.CurrExitLabel:=oldCurrExitLabel;
     if assigned(oldBreakLabel) then
35841_v2_n386flw.pas.patch (2,015 bytes)   

Florian

2020-10-10 12:12

administrator   ~0126211

Do you have any test which fails without your patch? I386 handles things slightly different and for me it works without the patch?

Issue History

Date Modified Username Field Change
2019-07-12 19:33 J. Gareth Moreton New Issue
2019-07-12 19:33 J. Gareth Moreton Status new => assigned
2019-07-12 19:33 J. Gareth Moreton Assigned To => Florian
2019-07-12 19:33 J. Gareth Moreton File Added: i35841.patch
2019-07-12 19:34 J. Gareth Moreton Relationship added related to 0032913
2019-07-12 19:49 J. Gareth Moreton Status assigned => feedback
2019-07-12 19:49 J. Gareth Moreton FPCTarget => -
2020-10-08 22:38 Florian Status feedback => resolved
2020-10-08 22:38 Florian Resolution open => fixed
2020-10-08 22:38 Florian Fixed in Version => 3.3.1
2020-10-08 22:38 Florian Fixed in Revision => 47066
2020-10-08 22:38 Florian Note Added: 0126154
2020-10-09 06:31 Do-wan Kim Note Added: 0126166
2020-10-09 06:31 Do-wan Kim File Added: 35841_n386flw.pas.patch
2020-10-10 08:08 Do-wan Kim Note Added: 0126201
2020-10-10 08:08 Do-wan Kim File Added: 35841_v2_n386flw.pas.patch
2020-10-10 12:12 Florian Note Added: 0126211