From cc44328109cef335ec6214d4e7424d66332f8f7c Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 3 Oct 2017 20:36:09 +0000 Subject: [PATCH] * correctly calc case label distance after r36362, resolves #32115 and #32311 git-svn-id: trunk@37390 - --- .gitattributes | 1 + compiler/ncgset.pas | 11 +++-------- tests/webtbs/tw32115.pp | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tests/webtbs/tw32115.pp diff --git a/.gitattributes b/.gitattributes index dd4cd0c459..2b9846f046 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15788,6 +15788,7 @@ tests/webtbs/tw3207.pp svneol=native#text/plain tests/webtbs/tw3210.pp svneol=native#text/plain tests/webtbs/tw32108.pp svneol=native#text/pascal tests/webtbs/tw32111.pp svneol=native#text/pascal +tests/webtbs/tw32115.pp svneol=native#text/pascal tests/webtbs/tw32118.pp svneol=native#text/pascal tests/webtbs/tw3212.pp svneol=native#text/plain tests/webtbs/tw3214.pp svneol=native#text/plain diff --git a/compiler/ncgset.pas b/compiler/ncgset.pas index 74ada95bc1..61051b8f00 100644 --- a/compiler/ncgset.pas +++ b/compiler/ncgset.pas @@ -1003,7 +1003,7 @@ implementation var oldflowcontrol: tflowcontrol; i : longint; - distv,dist, + dist,distv, lv,hv, max_label: tconstexprint; labelcnt : tcgint; @@ -1081,14 +1081,9 @@ implementation { can we omit the range check of the jump table ? } getrange(left.resultdef,lv,hv); jumptable_no_range:=(lv=min_label) and (hv=max_label); - { hack a little bit, because the range can be greater } - { than the positive range of a aint } - if (min_label<0) and (max_label>0) then - distv:=max_label+min_label - else - distv:=max_label-min_label; - if (distv>=0) then + distv:=max_label-min_label; + if distv>=0 then dist:=distv.uvalue else dist:=-distv.svalue; diff --git a/tests/webtbs/tw32115.pp b/tests/webtbs/tw32115.pp new file mode 100644 index 0000000000..262a171161 --- /dev/null +++ b/tests/webtbs/tw32115.pp @@ -0,0 +1,26 @@ +{$mode objfpc} +program Project1; + +function CalcSmth(const AValue: Integer): Integer; +begin + case AValue of + -9999999..-1000000: Result := 2; + -999999..-100000: Result := 7; + -99999..-10000: Result := 5; + -9999..-1000: Result := 6; + -999..-100: Result := 3; + -99..-10: Result := 2; + -9..-1: Result := 3; + 0..9: Result := 5; + 10..99: Result := 2; + 100..999: Result := 3; + 1000..9999: Result := 1; + 10000..99999: Result := 5; + 100000..999999: Result := 8; + 1000000..9999999: Result := 6; + end; +end; + +begin + CalcSmth(0); +end.