Browse Source

* fixed range test optimization for signed types and enabled it for them

git-svn-id: trunk@42332 -
Jonas Maebe 6 years ago
parent
commit
40082100e1
3 changed files with 39 additions and 8 deletions
  1. 1 0
      .gitattributes
  2. 5 8
      compiler/nadd.pas
  3. 33 0
      tests/webtbs/tw34385a.pp

+ 1 - 0
.gitattributes

@@ -16615,6 +16615,7 @@ 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/tw34385a.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

+ 5 - 8
compiler/nadd.pas

@@ -389,7 +389,7 @@ implementation
         var
           swapl, swapr: Boolean;
           valuer: tnode;
-          t: QWord;
+          t: Tconstexprint;
         begin
           result:=false;
           swapl:=false;
@@ -398,29 +398,26 @@ implementation
           if nodel.left.nodetype=ordconstn then
             begin
               swapl:=true;
-              cl:=tordconstnode(nodel.left).value.uvalue;
+              cl:=tordconstnode(nodel.left).value;
               value:=nodel.right;
             end
           else if nodel.right.nodetype=ordconstn then
             begin
-              cl:=tordconstnode(nodel.right).value.uvalue;
+              cl:=tordconstnode(nodel.right).value;
               value:=nodel.left;
             end
           else
             exit;
 
-          if is_signed(value.resultdef) then
-            exit;
-
           if noder.left.nodetype=ordconstn then
             begin
               swapl:=true;
-              cr:=tordconstnode(noder.left).value.uvalue;
+              cr:=tordconstnode(noder.left).value;
               valuer:=noder.right;
             end
           else if noder.right.nodetype=ordconstn then
             begin
-              cr:=tordconstnode(noder.right).value.uvalue;
+              cr:=tordconstnode(noder.right).value;
               valuer:=noder.left;
             end
           else

+ 33 - 0
tests/webtbs/tw34385a.pp

@@ -0,0 +1,33 @@
+{$r+}
+
+program rangeTest;
+const
+  w : longint = 123;
+  n : longint = 48;
+  m : longint = -5;
+  k : longint = low(longint);
+begin
+  if (w<=1) and (w>=10) then
+    halt(1);
+
+  if (w>=1) and (w<=1000) then
+  else
+    halt(2);
+
+  if (n>44)and(n<48) then
+    halt(3);
+
+  if (m>=-4) and (m<=$7ffffffe) then
+    halt(4);
+
+  if (m>=-5) and (m<=$7ffffffe) then
+  else
+    halt(5);
+
+  if (m>=-$7fffffff) and (m<=$7ffffffe) then
+  else
+    halt(6);
+
+  if (k>=-$7fffffff) and (k<=$7ffffffe) then
+    halt(7);
+end.