diff --git a/.gitattributes b/.gitattributes index 95c47b6399..b84dc381ac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/optdfa.pas b/compiler/optdfa.pas index d9adc62bb8..34c2be5e89 100644 --- a/compiler/optdfa.pas +++ b/compiler/optdfa.pas @@ -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. diff --git a/compiler/procinfo.pas b/compiler/procinfo.pas index e4ef0d0785..af6cda0834 100644 --- a/compiler/procinfo.pas +++ b/compiler/procinfo.pas @@ -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; diff --git a/compiler/psub.pas b/compiler/psub.pas index 908a32602e..f2e9d642d0 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -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; diff --git a/tests/webtbf/tw8079.pp b/tests/webtbf/tw8079.pp new file mode 100644 index 0000000000..3709121cb5 --- /dev/null +++ b/tests/webtbf/tw8079.pp @@ -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. \ No newline at end of file diff --git a/tests/webtbf/tw8717.pp b/tests/webtbf/tw8717.pp new file mode 100644 index 0000000000..c51a2d2e2a --- /dev/null +++ b/tests/webtbf/tw8717.pp @@ -0,0 +1,11 @@ +{ %opt=-vw -Sew -Oodfa } +{ %fail } +{$mode objfpc} +function f: Boolean; +begin + Exit; + Result := True +end; + +begin +end.