From 3fa77a4f627e5ce993c88be7849e27b64e7ae80a Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 24 Oct 2022 22:10:34 +0200 Subject: [PATCH] * fix life information propagation for while loops, resolves #39971 * warnings/errors fixed which are caused by the new life information propagation + test --- compiler/dbgdwarf.pas | 3 ++- compiler/ngtcon.pas | 2 +- compiler/optdfa.pas | 7 ++++++- compiler/pgenutil.pas | 1 + compiler/systems/t_bsd.pas | 1 + compiler/systems/t_linux.pas | 3 ++- compiler/systems/t_win.pas | 1 + tests/test/opt/tdfa2.pp | 1 + tests/webtbs/tw39971.pp | 19 +++++++++++++++++++ 9 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/webtbs/tw39971.pp diff --git a/compiler/dbgdwarf.pas b/compiler/dbgdwarf.pas index 541dfa0baf..4ddf5ad5d1 100644 --- a/compiler/dbgdwarf.pas +++ b/compiler/dbgdwarf.pas @@ -3486,7 +3486,8 @@ implementation prevline := 1; prevfileidx := 1; prevlabel := nil; - nolineinfolevel:=0; + nolineinfolevel := 0; + hpend := nil; while assigned(hp) do begin case hp.typ of diff --git a/compiler/ngtcon.pas b/compiler/ngtcon.pas index 18edb80953..33de135b44 100644 --- a/compiler/ngtcon.pas +++ b/compiler/ngtcon.pas @@ -1675,13 +1675,13 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis srsym:=get_next_varsym(def,symlist,symidx); recsym := nil; startoffset:=curoffset; + error := false; while token<>_RKLAMMER do begin s:=pattern; sorg:=orgpattern; consume(_ID); consume(_COLON); - error := false; recsym := tsym(def.symtable.Find(s)); if not assigned(recsym) then begin diff --git a/compiler/optdfa.pas b/compiler/optdfa.pas index ecfaa9cc8d..9c0b865cb3 100644 --- a/compiler/optdfa.pas +++ b/compiler/optdfa.pas @@ -289,7 +289,12 @@ unit optdfa; { for while loops, node use set is included at the beginning of loop } l:=twhilerepeatnode(node).right.optinfo^.life; if lnf_testatbegin in twhilerepeatnode(node).loopflags then - DFASetIncludeSet(l,node.optinfo^.use); + begin + DFASetIncludeSet(l,node.optinfo^.use); + { ... loop body could be skipped, so include life info of the successsor node } + if assigned(node.successor) then + DFASetIncludeSet(l,node.successor.optinfo^.life); + end; UpdateLifeInfo(node,l); diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index eca7f6f751..c33c8da72b 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -505,6 +505,7 @@ uses for j:=0 to formalobjdef.implementedinterfaces.count-1 do begin objdef:=paraobjdef; + intffound:=false; while assigned(objdef) do begin intffound:=assigned( diff --git a/compiler/systems/t_bsd.pas b/compiler/systems/t_bsd.pas index b3be7933d0..18eefbd29a 100644 --- a/compiler/systems/t_bsd.pas +++ b/compiler/systems/t_bsd.pas @@ -69,6 +69,7 @@ function ModulesLinkToLibc:boolean; var hp: tmodule; begin + result:=false; { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs. The former contains library names qualified with prefix and suffix (coming from "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c" diff --git a/compiler/systems/t_linux.pas b/compiler/systems/t_linux.pas index 9768d756ac..583f714375 100644 --- a/compiler/systems/t_linux.pas +++ b/compiler/systems/t_linux.pas @@ -334,11 +334,12 @@ function ModulesLinkToLibc:boolean; var hp: tmodule; begin + result:=false; { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs. The former contains library names qualified with prefix and suffix (coming from "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c" directives). } - hp:=tmodule(loaded_units.first); + hp:=tmodule(loaded_units.first); while assigned(hp) do begin result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext)); diff --git a/compiler/systems/t_win.pas b/compiler/systems/t_win.pas index 05e50d1c94..63855f123c 100644 --- a/compiler/systems/t_win.pas +++ b/compiler/systems/t_win.pas @@ -136,6 +136,7 @@ implementation begin if target_info.system=system_i386_win32 then begin + linkcygwin := false; hp:=tmodule(loaded_units.first); while assigned(hp) do begin diff --git a/tests/test/opt/tdfa2.pp b/tests/test/opt/tdfa2.pp index 67c1a60ef5..d39096fdbc 100644 --- a/tests/test/opt/tdfa2.pp +++ b/tests/test/opt/tdfa2.pp @@ -37,6 +37,7 @@ var c1: Word; begin counter:=0; + c1 := 0; while counter 1000 do + begin + fr := sz mod 1024; + sz := sz div 1024; + end; + result := fr; +end; + +begin + writeln(FileSizeFractionalPart(12)); + if FileSizeFractionalPart(12)<>0 then + halt(1); +end.