Browse Source

* Adjustment to TBLockNode.pass_1 to actually strip nothing nodes

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
7854152304
1 changed files with 20 additions and 2 deletions
  1. 20 2
      compiler/nbas.pas

+ 20 - 2
compiler/nbas.pas

@@ -801,19 +801,37 @@ implementation
     function tblocknode.pass_1 : tnode;
     function tblocknode.pass_1 : tnode;
       var
       var
          hp : tstatementnode;
          hp : tstatementnode;
+         FirstNode: Boolean;
          //count : longint;
          //count : longint;
       begin
       begin
          result:=nil;
          result:=nil;
          expectloc:=LOC_VOID;
          expectloc:=LOC_VOID;
          //count:=0;
          //count:=0;
          hp:=tstatementnode(left);
          hp:=tstatementnode(left);
+         FirstNode := True;
          while assigned(hp) do
          while assigned(hp) do
            begin
            begin
               if assigned(hp.left) then
               if assigned(hp.left) then
                 begin
                 begin
+                   { Calling firstpass on a statement node normally causes
+                     problems, so we have to be a little bit hacky if we want
+                     to remove nothing nodes }
                    codegenerror:=false;
                    codegenerror:=false;
-                   firstpass(hp.left);
-                   hp.expectloc:=hp.left.expectloc;
+                   firstpass(tnode(hp));
+                   { If the first node gets deleted, left must be updated,
+                     otherwise it will be a dangling pointer }
+                   if FirstNode then
+                     begin
+                       { If multiple statements are to be removed, they would
+                         have all been removed by the firstpass call above, so
+                         the next one will not be removed, hence it's safe to
+                         set FirstNode to false }
+                       FirstNode := False;
+                       left := hp;
+                     end;
+
+                   if assigned(hp.left) then
+                     hp.expectloc:=hp.left.expectloc;
                 end;
                 end;
               expectloc:=hp.expectloc;
               expectloc:=hp.expectloc;
               //inc(count);
               //inc(count);