Przeglądaj źródła

* don't insert type conversions in add nodes if both arguments are constant
and if the result does not depend on the types of the arguments (to
prevent "qwordconst>int64const" being turned into
"int64(qwordconst)>int64const" and thereby potentially change the outcome)
(mantis #19622)

git-svn-id: trunk@21395 -

Jonas Maebe 13 lat temu
rodzic
commit
a2426178dc
3 zmienionych plików z 44 dodań i 0 usunięć
  1. 1 0
      .gitattributes
  2. 10 0
      compiler/nadd.pas
  3. 33 0
      tests/webtbs/tw19622.pp

+ 1 - 0
.gitattributes

@@ -12498,6 +12498,7 @@ tests/webtbs/tw19500.pp svneol=native#text/pascal
 tests/webtbs/tw19511.pp svneol=native#text/pascal
 tests/webtbs/tw19548.pp svneol=native#text/pascal
 tests/webtbs/tw19555.pp svneol=native#text/pascal
+tests/webtbs/tw19622.pp -text svneol=native#text/plain
 tests/webtbs/tw1964.pp svneol=native#text/plain
 tests/webtbs/tw19651.pp svneol=native#text/plain
 tests/webtbs/tw19700.pp svneol=native#text/plain

+ 10 - 0
compiler/nadd.pas

@@ -1347,6 +1347,16 @@ implementation
                   if (torddef(rd).ordtype<>scurrency) then
                    inserttypeconv(right,s64currencytype);
                end
+             { leave some constant integer expressions alone in case the
+               resultdef of the integer types doesn't influence the outcome,
+               because the forced type conversions below can otherwise result
+               in unexpected results (such as high(qword)<high(int64) returning
+               true because high(qword) gets converted to int64) }
+             else if is_integer(ld) and is_integer(rd) and
+                     (lt=ordconstn) and (rt=ordconstn) and
+                     (nodetype in [equaln,unequaln,gtn,gten,ltn,lten]) then
+               begin
+               end
              { "and" does't care about the sign of integers }
              { "xor", "or" and compares don't need extension to native int }
              { size either as long as both values are signed or unsigned   }

+ 33 - 0
tests/webtbs/tw19622.pp

@@ -0,0 +1,33 @@
+Var a,b:qword;
+      c:boolean;
+      aa,bb:longword;      
+Begin
+    a:=qword($FFFFFFFFFFFFFFFF);
+    b:=9223372036854775807;
+    c:=a>b;
+    if not c then
+      halt(1);
+    if not(qword($FFFFFFFFFFFFFFFF)>9223372036854775807) then
+      halt(2);
+    c:=qword($FFFFFFFFFFFFFFFF)>b;
+    if not c then
+      halt(3);
+    c:=18446744073709551615>=9223372036854775807;  
+    if not c then
+      halt(4);
+    
+    
+    aa:=$FFFFFFFF;
+    bb:=2147483647;
+    c:=aa>bb;
+    if not c then
+      halt(5);
+    if not ($FFFFFFFF>2147483647) then
+      halt(6);
+    c:=$FFFFFFFF>bb;
+    if not c then
+      halt(7);
+    c:=4294967295>=2147483647;
+    if not c then
+      halt(8);
+End.