From 511beac49c57ef4c6791494a450cad1886a4fa9a Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 26 Oct 2024 16:10:24 +0200 Subject: [PATCH] * get rid of the hack that tlabelnode inherits from tunarynode and stores a statement in left, resolves #40964 --- compiler/ncgflw.pas | 2 -- compiler/nflw.pas | 9 ++------- compiler/optdfa.pas | 16 ++-------------- compiler/optutils.pas | 8 +------- compiler/pstatmnt.pas | 25 ++++++++++++------------- tests/webtbs/tw40964.pp | 14 ++++++++++++++ 6 files changed, 31 insertions(+), 43 deletions(-) create mode 100644 tests/webtbs/tw40964.pp diff --git a/compiler/ncgflw.pas b/compiler/ncgflw.pas index 37b6dc9dd9..77473dda66 100644 --- a/compiler/ncgflw.pas +++ b/compiler/ncgflw.pas @@ -509,8 +509,6 @@ implementation if assigned(labsym) and assigned(labsym.asmblocklabel) then hlcg.a_label(current_asmdata.CurrAsmList,labsym.asmblocklabel); - - secondpass(left); end; diff --git a/compiler/nflw.pas b/compiler/nflw.pas index 3669173692..c35535b9b3 100644 --- a/compiler/nflw.pas +++ b/compiler/nflw.pas @@ -199,7 +199,7 @@ interface end; tgotonodeclass = class of tgotonode; - tlabelnode = class(tunarynode) + tlabelnode = class(tnode) exceptionblock : integer; { when copying trees, this points to the newly created copy of a label } copiedto : tlabelnode; @@ -2439,7 +2439,7 @@ implementation constructor tlabelnode.create(l:tnode;alabsym:tlabelsym); begin - inherited create(labeln,l); + inherited create(labeln); exceptionblock:=current_exceptblock; labsym:=alabsym; { Register labelnode in labelsym } @@ -2494,9 +2494,6 @@ implementation function tlabelnode.pass_typecheck:tnode; begin result:=nil; - { left could still be unassigned } - if assigned(left) then - typecheckpass(left); resultdef:=voidtype; end; @@ -2509,8 +2506,6 @@ implementation if not (nf_internal in flags) then include(current_procinfo.flags,pi_has_label); - if assigned(left) then - firstpass(left); if (m_non_local_goto in current_settings.modeswitches) and { the owner can be Nil for internal labels } assigned(labsym.owner) and diff --git a/compiler/optdfa.pas b/compiler/optdfa.pas index cdfdf9e64b..c1978c83dc 100644 --- a/compiler/optdfa.pas +++ b/compiler/optdfa.pas @@ -574,17 +574,7 @@ unit optdfa; calclife(node); end; - labeln: - begin - calclife(node); - - if assigned(tlabelnode(node).left) then - begin - l:=node.optinfo^.life; - DFASetIncludeSet(l,tlabelnode(node).optinfo^.life); - UpdateLifeInfo(node,l); - end; - end; + labeln, tempcreaten, tempdeleten, nothingn, @@ -946,9 +936,6 @@ unit optdfa; MaybeDoCheck(tcasenode(node).elseblock); end; - labeln: - MaybeDoCheck(tlabelnode(node).left); - { we are aware of the following nodes so if new node types are added to the compiler and pop up in the search, the ie below kicks in as a reminder } exitn: @@ -979,6 +966,7 @@ unit optdfa; { all other platforms except jvm translate raise nodes into call nodes during pass_1 } raisen, {$endif JVM} + labeln, loadn, assignn, calln, diff --git a/compiler/optutils.pas b/compiler/optutils.pas index 38dded4996..757ba06294 100644 --- a/compiler/optutils.pas +++ b/compiler/optutils.pas @@ -324,13 +324,7 @@ unit optutils; labeln: begin result:=p; - if assigned(tlabelnode(p).left) then - begin - DoSet(tlabelnode(p).left,succ); - p.successor:=tlabelnode(p).left; - end - else - p.successor:=succ; + p.successor:=succ; end; assignn: begin diff --git a/compiler/pstatmnt.pas b/compiler/pstatmnt.pas index 551dedc65e..ec578701a5 100644 --- a/compiler/pstatmnt.pas +++ b/compiler/pstatmnt.pas @@ -1319,6 +1319,7 @@ implementation function statement : tnode; var p, + astatement, code : tnode; filepos : tfileposinfo; srsym : tsym; @@ -1487,21 +1488,19 @@ implementation if p.nodetype=labeln then begin - { the pointer to the following instruction } - { isn't a very clean way } - if token in endtokens then - tlabelnode(p).left:=cnothingnode.create - else - tlabelnode(p).left:=statement(); - { be sure to have left also typecheckpass } - typecheckpass(tlabelnode(p).left); + if not(token in endtokens) then + begin + astatement:=statement(); + typecheckpass(astatement); + p:=cblocknode.create(cstatementnode.create(p,cstatementnode.create(astatement,nil))); + Include(TBlockNode(p).blocknodeflags, bnf_strippable); + end; end else - - { change a load of a procvar to a call. this is also - supported in fpc mode } - if p.nodetype in [vecn,derefn,typeconvn,subscriptn,loadn] then - maybe_call_procvar(p,false); + { change a load of a procvar to a call. this is also + supported in fpc mode } + if p.nodetype in [vecn,derefn,typeconvn,subscriptn,loadn] then + maybe_call_procvar(p,false); { blockn support because a read/write is changed into a blocknode with a separate statement for each read/write operation (JM) diff --git a/tests/webtbs/tw40964.pp b/tests/webtbs/tw40964.pp new file mode 100644 index 0000000000..101c172df7 --- /dev/null +++ b/tests/webtbs/tw40964.pp @@ -0,0 +1,14 @@ +{$goto on} +program ie200211262; + +function func(v: pointer): string; inline; +begin + func:=''; +end; + +label lab; + +begin + lab: + func(@lab); // app.lpr(11,3) Error: Internal error 200211262 +end.