* DFA now takes case-completeness into account (mantis #35598)

git-svn-id: trunk@42091 -
This commit is contained in:
Jonas Maebe 2019-05-18 12:01:41 +00:00
parent 2ff391c25c
commit 7e51c5e856
4 changed files with 56 additions and 2 deletions

2
.gitattributes vendored
View File

@ -12741,7 +12741,9 @@ tests/test/opt/tdfa15.pp svneol=native#text/pascal
tests/test/opt/tdfa16.pp svneol=native#text/pascal
tests/test/opt/tdfa17.pp svneol=native#text/pascal
tests/test/opt/tdfa18.pp svneol=native#text/pascal
tests/test/opt/tdfa19.pp svneol=native#text/plain
tests/test/opt/tdfa2.pp svneol=native#text/pascal
tests/test/opt/tdfa20.pp svneol=native#text/plain
tests/test/opt/tdfa3.pp svneol=native#text/pascal
tests/test/opt/tdfa4.pp svneol=native#text/pascal
tests/test/opt/tdfa5.pp svneol=native#text/pascal

View File

@ -53,7 +53,7 @@ unit optdfa;
implementation
uses
globtype,
globtype,constexp,
verbose,
symconst,symdef,symsym,
defutil,
@ -225,6 +225,7 @@ unit optdfa;
dfainfo : tdfainfo;
l : TDFASet;
save: TDFASet;
lv, hv: TConstExprInt;
i : longint;
counteruse_after_loop : boolean;
begin
@ -485,7 +486,16 @@ unit optdfa;
if assigned(tcasenode(node).elseblock) then
DFASetIncludeSet(l,tcasenode(node).elseblock.optinfo^.life)
else if assigned(node.successor) then
DFASetIncludeSet(l,node.successor.optinfo^.life);
begin
if is_ordinal(tcasenode(node).left.resultdef) then
begin
getrange(tcasenode(node).left.resultdef,lv,hv);
if tcasenode(node).labelcoverage<(hv-lv) then
DFASetIncludeSet(l,node.successor.optinfo^.life);
end
else
DFASetIncludeSet(l,node.successor.optinfo^.life);
end;
{ add use info from the "case" expression }
DFASetIncludeSet(l,tcasenode(node).optinfo^.use);

20
tests/test/opt/tdfa19.pp Normal file
View File

@ -0,0 +1,20 @@
{ %OPT=-Oodfa -vw -Sew }
{ %norun }
{$mode objfpc}
program project1;
type
trange=0..5;
function f(r: trange): longint;
begin
case r of
0..5: result:=r;
end;
end;
begin
writeln(f(2));
end.

22
tests/test/opt/tdfa20.pp Normal file
View File

@ -0,0 +1,22 @@
{ %OPT=-Oodfa -vw -Sew -vm6060 }
{ %FAIL }
{$mode objfpc}
program project1;
type
trange=0..5;
function f(r: trange): longint;
begin
{ must give a warning about unset function result; warning about incomplete
case statement is suppressed with -vm6060 }
case r of
0..4: result:=r;
end;
end;
begin
writeln(f(2));
end.