2
0
Эх сурвалжийг харах

* safeguard the nf_block_with_exit flag when simplifying blockn and
statementn + test

git-svn-id: trunk@9134 -

Jonas Maebe 17 жил өмнө
parent
commit
ed7511de58

+ 1 - 0
.gitattributes

@@ -6932,6 +6932,7 @@ tests/test/tindex.pp svneol=native#text/plain
 tests/test/tinivar.pp svneol=native#text/plain
 tests/test/tinlin64.pp svneol=native#text/plain
 tests/test/tinline1.pp svneol=native#text/plain
+tests/test/tinline10.pp svneol=native#text/plain
 tests/test/tinline2.pp svneol=native#text/plain
 tests/test/tinline3.pp svneol=native#text/plain
 tests/test/tinline4.pp svneol=native#text/plain

+ 23 - 1
compiler/nbas.pas

@@ -214,7 +214,7 @@ implementation
       verbose,globals,systems,
       symconst,symdef,defutil,defcmp,
       pass_1,
-      nld,ncal,nflw,
+      nutils,nld,ncal,nflw,
       procinfo
       ;
 
@@ -315,6 +315,21 @@ implementation
       end;
 
 
+    function is_exit_statement(var n: tnode; arg: pointer): foreachnoderesult;
+      begin
+        if (n.nodetype<>exitn) then
+          result:=fen_false
+        else
+          result:=fen_norecurse_true;
+      end;
+
+
+    function no_exit_statement_in_block(n: tnode): boolean;
+      begin
+        result:=not foreachnodestatic(n,@is_exit_statement,nil);
+      end;
+
+
     function tstatementnode.simplify : tnode;
       begin
         result:=nil;
@@ -353,7 +368,12 @@ implementation
 
         { if the current statement contains a block with one statement, }
         { replace the current statement with that block's statement     }
+        { (but only if the block does not have nf_block_with_exit set   }
+        {  or has no exit statement, because otherwise it needs an own  }
+        {  exit label, see tests/test/tinline10)                        }
         if (left.nodetype = blockn) and
+           (not(nf_block_with_exit in left.flags) or
+            no_exit_statement_in_block(left)) and
            assigned(tblocknode(left).left) and
            not assigned(tstatementnode(tblocknode(left).left).right) then
           begin
@@ -458,6 +478,8 @@ implementation
           begin
             result:=tstatementnode(left).left;
             tstatementnode(left).left:=nil;
+            { make sure the nf_block_with_exit flag is safeguarded }
+            result.flags:=result.flags+(flags * [nf_block_with_exit]);
             exit;
           end;
       end;

+ 30 - 0
tests/test/tinline10.pp

@@ -0,0 +1,30 @@
+{$inline on}
+
+type
+  tr = record
+    l: longint;
+  end;
+  pr = ^tr;
+
+procedure test(r: pr); inline;
+begin
+  with r^ do
+    begin
+      l:=5;
+      exit;
+    end;
+end;
+
+function f: longint;
+var
+  r: tr;
+begin
+  f:=1;
+  test(@r);
+  f:=2;
+end;
+
+begin
+  if (f <> 2) then
+    halt(1);
+end.