Sfoglia il codice sorgente

* handle mod/div between a cardinal/qword and a smaller unsigned variable
(byte, word, postive subrange) as an unsigned operation (mantis #8870)

git-svn-id: trunk@7334 -

Jonas Maebe 18 anni fa
parent
commit
7bd8d0200e
3 ha cambiato i file con 26 aggiunte e 4 eliminazioni
  1. 1 0
      .gitattributes
  2. 11 4
      compiler/nmat.pas
  3. 14 0
      tests/webtbs/tw8870.pp

+ 1 - 0
.gitattributes

@@ -8209,6 +8209,7 @@ tests/webtbs/tw8777i.pp svneol=native#text/plain
 tests/webtbs/tw8810.pp svneol=native#text/plain
 tests/webtbs/tw8838.pp svneol=native#text/plain
 tests/webtbs/tw8861.pp svneol=native#text/plain
+tests/webtbs/tw8870.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 11 - 4
compiler/nmat.pas

@@ -209,16 +209,23 @@ implementation
          { Do the same for qwords and positive constants as well, otherwise things like   }
          { "qword mod 10" are evaluated with int64 as result, which is wrong if the       }
          { "qword" was > high(int64) (JM)                                                 }
+         { Additionally, do the same for cardinal/qwords and other positive types, but    }
+         { always in a way that a smaller type is converted to a bigger type              }
+         { (webtbs/tw8870)                                                                }
          if (rd.ordtype in [u32bit,u64bit]) and
-            is_constintnode(left) and
-            (tordconstnode(left).value >= 0) then
+            ((is_constintnode(left) and
+              (tordconstnode(left).value >= 0)) or
+             (not is_signed(ld) and
+              (rd.size >= ld.size))) then
            begin
              inserttypeconv(left,right.resultdef);
              ld:=torddef(left.resultdef);
            end;
          if (ld.ordtype in [u32bit,u64bit]) and
-            is_constintnode(right) and
-            (tordconstnode(right).value >= 0) then
+            ((is_constintnode(right) and
+              (tordconstnode(right).value >= 0)) or
+             (not is_signed(rd) and
+              (ld.size >= rd.size))) then
           begin
             inserttypeconv(right,left.resultdef);
             rd:=torddef(right.resultdef);

+ 14 - 0
tests/webtbs/tw8870.pp

@@ -0,0 +1,14 @@
+{$q+}
+{$r+}
+
+type
+   range = 0..32;
+var
+   a,b : Cardinal;
+   one : range;
+begin
+   a := $80000000;
+   one := 1;
+   b := a div one;
+   WriteLn(b);
+end.