Browse Source

* correctly calc case label distance after r36362, resolves #32115 and #32311

git-svn-id: trunk@37390 -
florian 7 years ago
parent
commit
cc44328109
3 changed files with 30 additions and 8 deletions
  1. 1 0
      .gitattributes
  2. 3 8
      compiler/ncgset.pas
  3. 26 0
      tests/webtbs/tw32115.pp

+ 1 - 0
.gitattributes

@@ -15788,6 +15788,7 @@ tests/webtbs/tw3207.pp svneol=native#text/plain
 tests/webtbs/tw3210.pp svneol=native#text/plain
 tests/webtbs/tw3210.pp svneol=native#text/plain
 tests/webtbs/tw32108.pp svneol=native#text/pascal
 tests/webtbs/tw32108.pp svneol=native#text/pascal
 tests/webtbs/tw32111.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/tw32118.pp svneol=native#text/pascal
 tests/webtbs/tw3212.pp svneol=native#text/plain
 tests/webtbs/tw3212.pp svneol=native#text/plain
 tests/webtbs/tw3214.pp svneol=native#text/plain
 tests/webtbs/tw3214.pp svneol=native#text/plain

+ 3 - 8
compiler/ncgset.pas

@@ -1003,7 +1003,7 @@ implementation
       var
       var
          oldflowcontrol: tflowcontrol;
          oldflowcontrol: tflowcontrol;
          i : longint;
          i : longint;
-         distv,dist,
+         dist,distv,
          lv,hv,
          lv,hv,
          max_label: tconstexprint;
          max_label: tconstexprint;
          labelcnt : tcgint;
          labelcnt : tcgint;
@@ -1081,14 +1081,9 @@ implementation
                    { can we omit the range check of the jump table ? }
                    { can we omit the range check of the jump table ? }
                    getrange(left.resultdef,lv,hv);
                    getrange(left.resultdef,lv,hv);
                    jumptable_no_range:=(lv=min_label) and (hv=max_label);
                    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
                      dist:=distv.uvalue
                    else
                    else
                      dist:=-distv.svalue;
                      dist:=-distv.svalue;

+ 26 - 0
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.