* proper handling of dummy result node in dfa, resolves #8717 and #8079

+ tests

git-svn-id: trunk@8147 -
This commit is contained in:
florian 2007-07-23 08:57:31 +00:00
parent 8d53e54e3e
commit b6cca14944
6 changed files with 65 additions and 23 deletions

2
.gitattributes vendored
View File

@ -7374,6 +7374,7 @@ tests/webtbf/tw7989.pp svneol=native#text/plain
tests/webtbf/tw7998.pp svneol=native#text/plain
tests/webtbf/tw8019.pp svneol=native#text/plain
tests/webtbf/tw8031.pp svneol=native#text/plain
tests/webtbf/tw8079.pp svneol=native#text/plain
tests/webtbf/tw8140a.pp svneol=native#text/plain
tests/webtbf/tw8140c.pp svneol=native#text/plain
tests/webtbf/tw8140d.pp svneol=native#text/plain
@ -7392,6 +7393,7 @@ tests/webtbf/tw8528.pp svneol=native#text/plain
tests/webtbf/tw8583.pp svneol=native#text/plain
tests/webtbf/tw8588.pp svneol=native#text/plain
tests/webtbf/tw8591.pp -text
tests/webtbf/tw8717.pp svneol=native#text/plain
tests/webtbf/tw8738.pas svneol=native#text/plain
tests/webtbf/tw8777a.pp svneol=native#text/plain
tests/webtbf/tw8777b.pp svneol=native#text/plain

View File

@ -31,13 +31,22 @@ unit optdfa;
interface
uses
node;
node,optutils;
{ reset all dfa info, this is required before creating dfa info
if the tree has been changed without updating dfa }
procedure resetdfainfo(node : tnode);
type
TDFABuilder = class
protected
procedure CreateLifeInfo(node : tnode;map : TIndexedNodeSet);
public
resultnode : tnode;
nodemap : TIndexedNodeSet;
{ reset all dfa info, this is required before creating dfa info
if the tree has been changed without updating dfa }
procedure resetdfainfo(node : tnode);
procedure createdfainfo(node : tnode);
procedure createdfainfo(node : tnode);
destructor destroy;override;
end;
implementation
@ -50,7 +59,7 @@ unit optdfa;
procinfo,
nutils,
nbas,nflw,ncon,ninl,ncal,nset,
optbase,optutils;
optbase;
(*
@ -131,11 +140,10 @@ unit optdfa;
end;
procedure CreateLifeInfo(node : tnode;map : TIndexedNodeSet);
procedure TDFABuilder.CreateLifeInfo(node : tnode;map : TIndexedNodeSet);
var
changed : boolean;
Resultnode : TNode;
procedure CreateInfo(node : tnode);
@ -484,26 +492,33 @@ unit optdfa;
{$ifdef DEBUG_DFA}
writeln('DFA solver iterations: ',runs);
{$endif DEBUG_DFA}
resultnode.free;
end;
{ reset all dfa info, this is required before creating dfa info
if the tree has been changed without updating dfa }
procedure resetdfainfo(node : tnode);
procedure TDFABuilder.resetdfainfo(node : tnode);
begin
end;
procedure createdfainfo(node : tnode);
procedure TDFABuilder.createdfainfo(node : tnode);
begin
if not(assigned(current_procinfo.nodemap)) then
current_procinfo.nodemap:=TIndexedNodeSet.Create;
if not(assigned(nodemap)) then
nodemap:=TIndexedNodeSet.Create;
{ add controll flow information }
SetNodeSucessors(node);
{ now, collect life information }
CreateLifeInfo(node,current_procinfo.nodemap);
CreateLifeInfo(node,nodemap);
end;
destructor TDFABuilder.Destroy;
begin
Resultnode.free;
nodemap.free;
inherited destroy;
end;
end.

View File

@ -103,9 +103,6 @@ unit procinfo;
{ max. of space need for parameters }
maxpushedparasize : aint;
{ node to index mapping for the node level optimizer }
nodemap : TIndexedNodeSet;
constructor create(aparent:tprocinfo);virtual;
destructor destroy;override;

View File

@ -28,7 +28,7 @@ interface
uses
cclasses,globals,
node,nbas,
symdef,procinfo;
symdef,procinfo,optdfa;
type
tcgprocinfo = class(tprocinfo)
@ -46,6 +46,7 @@ interface
final_asmnode : tasmnode;
{ list to store the procinfo's of the nested procedures }
nestedprocs : tlinkedlist;
dfabuilder : TDFABuilder;
constructor create(aparent:tprocinfo);override;
destructor destroy;override;
procedure printproc;
@ -105,7 +106,6 @@ implementation
optbase,
opttail,
optcse,
optdfa,
optutils
{$if defined(arm) or defined(powerpc) or defined(powerpc64)}
,aasmcpu
@ -771,18 +771,19 @@ implementation
pi_needs_implicit_finally,pi_has_implicit_finally,pi_has_stackparameter,
pi_needs_stackframe])=[]) then
begin
createdfainfo(code);
dfabuilder:=TDFABuilder.Create;
dfabuilder.createdfainfo(code);
{ when life info is available, we can give more sophisticated warning about unintialized
variables }
{ iterate through life info of the first node }
for i:=0 to nodemap.count-1 do
for i:=0 to dfabuilder.nodemap.count-1 do
begin
if DFASetIn(code.optinfo^.life,i) then
case tnode(nodemap[i]).nodetype of
case tnode(dfabuilder.nodemap[i]).nodetype of
loadn:
begin
varsym:=tabstractnormalvarsym(tloadnode(nodemap[i]).symtableentry);
varsym:=tabstractnormalvarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry);
{ Give warning/note for living locals }
if assigned(varsym.owner) and
@ -1100,6 +1101,8 @@ implementation
tg:=nil;
end;
dfabuilder.free;
{ restore symtablestack }
remove_from_symtablestack;

14
tests/webtbf/tw8079.pp Normal file
View File

@ -0,0 +1,14 @@
{ %opt=-vw -Sew -Oodfa }
{ %fail }
program test;
function foo(x: integer): integer;
begin
if x > 10 then
exit(10);
end;
begin
foo(4);
foo(12);
end.

11
tests/webtbf/tw8717.pp Normal file
View File

@ -0,0 +1,11 @@
{ %opt=-vw -Sew -Oodfa }
{ %fail }
{$mode objfpc}
function f: Boolean;
begin
Exit;
Result := True
end;
begin
end.