* Blocks of statements are now pruned (within reason) if a raise, exit, break, continue or goto node is found

This commit is contained in:
J. Gareth "Curious Kit" Moreton 2024-05-04 15:17:44 +01:00 committed by FPK
parent 41ae52dde1
commit e7145f5f7c

View File

@ -796,12 +796,45 @@ implementation
else if forinline or (cs_opt_level2 in current_settings.optimizerswitches) then
begin
n := TStatementNode(left);
while Assigned(n) and Assigned(n.right) do
while Assigned(n) do
begin
case n.left.nodetype of
raisen, exitn, breakn, continuen, goton:
{ Remove all subsequent statements, stopping only at a
label or asm block since code can theoretically jump
to them. Also, don't delete temp creates and deletes }
begin
last := n;
p := TStatementNode(n.Next);
while Assigned(p) do
begin
if (TStatementNode(p).left.nodetype in [labeln, asmn, tempcreaten, tempdeleten]) then
Break;
last := p;
p := TStatementNode(p.Next);
end;
if (last <> n) then
begin
last.next := nil; { Make sure we stop one before p }
n.next.Free;
n.next := p;
n := p;
Continue;
end;
end;
else
;
end;
{ Look one statement ahead in case it can be deleted - we
need the previous statement to stitch the tree correctly
}
p := TStatementNode(n.Next);
if not Assigned(p) then
Break;
if Assigned(p.left) then
begin
case p.left.nodetype of