Преглед изворни кода

* fixed adjustments of lower/upper bounds in range test optimization in case
of strictly smaller/greater comparisons (mantis #34385)

git-svn-id: trunk@40344 -

Jonas Maebe пре 6 година
родитељ
комит
d1361ca6ed
3 измењених фајлова са 28 додато и 4 уклоњено
  1. 1 0
      .gitattributes
  2. 4 4
      compiler/nadd.pas
  3. 23 0
      tests/webtbs/tw34385.pp

+ 1 - 0
.gitattributes

@@ -16415,6 +16415,7 @@ tests/webtbs/tw3433.pp svneol=native#text/plain
 tests/webtbs/tw34332.pp svneol=native#text/pascal
 tests/webtbs/tw3435.pp svneol=native#text/plain
 tests/webtbs/tw34380.pp svneol=native#text/plain
+tests/webtbs/tw34385.pp svneol=native#text/plain
 tests/webtbs/tw3441.pp svneol=native#text/plain
 tests/webtbs/tw3443.pp svneol=native#text/plain
 tests/webtbs/tw34438.pp svneol=native#text/pascal

+ 4 - 4
compiler/nadd.pas

@@ -377,11 +377,11 @@ implementation
 
     function taddnode.simplify(forinline : boolean) : tnode;
 
-      function is_range_test(nodel, noder: taddnode; var value: tnode; var cl,cr: Tconstexprint): boolean;
+      function is_range_test(nodel, noder: taddnode; out value: tnode; var cl,cr: Tconstexprint): boolean;
         const
           is_upper_test: array[ltn..gten] of boolean = (true,true,false,false);
-          inclusive_adjust: array[boolean,ltn..gten] of integer = ((1,0,-1,0),
-                                                                   (-1,0,1,0));
+          inclusive_adjust: array[boolean,ltn..gten] of integer = ((-1,0,1,0),
+                                                                   (1,0,-1,0));
         var
           swapl, swapr: Boolean;
           valuer: tnode;
@@ -1056,7 +1056,7 @@ implementation
             if is_boolean(left.resultdef) and is_boolean(right.resultdef) then
               begin
                 { transform unsigned comparisons of (v>=x) and (v<=y)
-                  into (v-x)<(y-x)
+                  into (v-x)<=(y-x)
                 }
                 if (nodetype=andn) and
                    (left.nodetype in [ltn,lten,gtn,gten]) and

+ 23 - 0
tests/webtbs/tw34385.pp

@@ -0,0 +1,23 @@
+program rangeTest;
+const
+  w : dword = 123;
+  n : dword = 48;
+begin
+  if (w<=1) and (w>=10) then
+    begin
+      writeln('error 1-10');
+      halt(1);
+    end;
+  if (w>=1) and (w<=1000) then
+    writeln('ok')
+  else
+    begin
+      writeln('error 1-1000');
+      halt(2);
+    end;
+  if (n>44)and(n<48) then
+    begin
+      writeln('error 48');
+      halt(3);
+    end;
+end.