From c8c6e647be33882b84c2ffffd9c4b84ea4fee1a0 Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 31 Mar 2021 20:53:08 +0000 Subject: [PATCH] Avoid keeping optimized out node in callcleanupblock.statements or callinitblock.statements git-svn-id: trunk@49094 - --- compiler/ncal.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 1b838b35ff..d1c4c37cbe 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -1986,7 +1986,8 @@ implementation procedure tcallnode.add_init_statement(n:tnode); var - lastinitstatement : tstatementnode; + lastinitstatement, before_firstpass : tstatementnode; + was_first_statement : boolean; begin if not assigned(n) then exit; @@ -1999,6 +2000,7 @@ implementation exit; end; lastinitstatement:=laststatement(callinitblock); + was_first_statement:=(lastinitstatement=callinitblock.statements); { all these nodes must be immediately typechecked, because this routine } { can be called from pass_1 (i.e., after typecheck has already run) and } { moreover, the entire blocks themselves are also only typechecked in } @@ -2006,7 +2008,10 @@ implementation { typecheck pass for simplify purposes (not yet perfect, because the } { statementnodes themselves are not typechecked this way) } addstatement(lastinitstatement,n); + before_firstpass:=lastinitstatement; firstpass(tnode(lastinitstatement)); + if was_first_statement and (lastinitstatement<>before_firstpass) then + callinitblock.statements:=lastinitstatement; { Update expectloc for callinitblock } callinitblock.expectloc:=lastinitstatement.expectloc; end; @@ -2014,7 +2019,8 @@ implementation procedure tcallnode.add_done_statement(n:tnode); var - lastdonestatement : tstatementnode; + lastdonestatement, before_firstpass : tstatementnode; + was_first_statement : boolean; begin if not assigned(n) then exit; @@ -2027,9 +2033,13 @@ implementation exit; end; lastdonestatement:=laststatement(callcleanupblock); + was_first_statement:=(lastdonestatement=callcleanupblock.statements); { see comments in add_init_statement } addstatement(lastdonestatement,n); + before_firstpass:=lastdonestatement; firstpass(tnode(lastdonestatement)); + if was_first_statement and (lastdonestatement<>before_firstpass) then + callcleanupblock.statements:=lastdonestatement; { Update expectloc for callcleanupblock } callcleanupblock.expectloc:=lastdonestatement.expectloc; end;