From 069e040e49c79b8ce1f8b73d85e02a05df6126b2 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 19 Jan 2020 18:21:12 +0000 Subject: [PATCH] * do for-loop unrolling after for-loop simplification, resolves #36589 git-svn-id: trunk@43999 - --- .gitattributes | 1 + compiler/nflw.pas | 36 +++++++++++++++++++----------------- tests/webtbs/tw36589.pp | 6 ++++++ 3 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 tests/webtbs/tw36589.pp diff --git a/.gitattributes b/.gitattributes index 773768e870..3e8e4c83e2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17956,6 +17956,7 @@ tests/webtbs/tw3650.pp svneol=native#text/plain tests/webtbs/tw3653.pp svneol=native#text/plain tests/webtbs/tw36544a.pp svneol=native#text/pascal tests/webtbs/tw36544b.pp svneol=native#text/pascal +tests/webtbs/tw36589.pp svneol=native#text/pascal tests/webtbs/tw3661.pp svneol=native#text/plain tests/webtbs/tw3666.pp svneol=native#text/plain tests/webtbs/tw3669.pp svneol=native#text/plain diff --git a/compiler/nflw.pas b/compiler/nflw.pas index 25fd4b98a0..139992eb73 100644 --- a/compiler/nflw.pas +++ b/compiler/nflw.pas @@ -1690,8 +1690,26 @@ implementation set_varstate(left,vs_written,[]); + { Make sure that the loop var and the + from and to values are compatible types } + if not(m_iso in current_settings.modeswitches) then + rangedef:=left.resultdef + else + rangedef:=get_iso_range_type(left.resultdef); + + check_ranges(right.fileinfo,right,rangedef); + inserttypeconv(right,rangedef); + + check_ranges(t1.fileinfo,t1,rangedef); + inserttypeconv(t1,rangedef); + + if assigned(t2) then + typecheckpass(t2); + result:=simplify(false); + { loop unrolling } - if (cs_opt_loopunroll in current_settings.optimizerswitches) and + if not(assigned(result)) and + (cs_opt_loopunroll in current_settings.optimizerswitches) and assigned(t2) and { statements must be error free } not(nf_error in t2.flags) then @@ -1709,22 +1727,6 @@ implementation end; end; - { Make sure that the loop var and the - from and to values are compatible types } - if not(m_iso in current_settings.modeswitches) then - rangedef:=left.resultdef - else - rangedef:=get_iso_range_type(left.resultdef); - - check_ranges(right.fileinfo,right,rangedef); - inserttypeconv(right,rangedef); - - check_ranges(t1.fileinfo,t1,rangedef); - inserttypeconv(t1,rangedef); - - if assigned(t2) then - typecheckpass(t2); - result:=simplify(false); end; diff --git a/tests/webtbs/tw36589.pp b/tests/webtbs/tw36589.pp new file mode 100644 index 0000000000..9d84e774a0 --- /dev/null +++ b/tests/webtbs/tw36589.pp @@ -0,0 +1,6 @@ +var k : longint; +begin + for k:=1 downto 10 do + begin + end; +end.