mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 04:29:42 +02:00
* safeguard the nf_block_with_exit flag when simplifying blockn and
statementn + test git-svn-id: trunk@9134 -
This commit is contained in:
parent
536a732823
commit
ed7511de58
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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
|
||||
|
@ -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
tests/test/tinline10.pp
Normal file
30
tests/test/tinline10.pp
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user