* 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 -
This commit is contained in:
Jonas Maebe 2007-05-14 19:24:33 +00:00
parent c80d4225ca
commit 7bd8d0200e
3 changed files with 26 additions and 4 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/webtbs/tw8870.pp Normal file
View File

@ -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.