mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-23 13:51:30 +01:00
* 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:
parent
c80d4225ca
commit
7bd8d0200e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -8209,6 +8209,7 @@ tests/webtbs/tw8777i.pp svneol=native#text/plain
|
|||||||
tests/webtbs/tw8810.pp svneol=native#text/plain
|
tests/webtbs/tw8810.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw8838.pp svneol=native#text/plain
|
tests/webtbs/tw8838.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw8861.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/ub1873.pp svneol=native#text/plain
|
||||||
tests/webtbs/ub1883.pp svneol=native#text/plain
|
tests/webtbs/ub1883.pp svneol=native#text/plain
|
||||||
tests/webtbs/uw0555.pp svneol=native#text/plain
|
tests/webtbs/uw0555.pp svneol=native#text/plain
|
||||||
|
|||||||
@ -209,16 +209,23 @@ implementation
|
|||||||
{ Do the same for qwords and positive constants as well, otherwise things like }
|
{ 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 mod 10" are evaluated with int64 as result, which is wrong if the }
|
||||||
{ "qword" was > high(int64) (JM) }
|
{ "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
|
if (rd.ordtype in [u32bit,u64bit]) and
|
||||||
is_constintnode(left) and
|
((is_constintnode(left) and
|
||||||
(tordconstnode(left).value >= 0) then
|
(tordconstnode(left).value >= 0)) or
|
||||||
|
(not is_signed(ld) and
|
||||||
|
(rd.size >= ld.size))) then
|
||||||
begin
|
begin
|
||||||
inserttypeconv(left,right.resultdef);
|
inserttypeconv(left,right.resultdef);
|
||||||
ld:=torddef(left.resultdef);
|
ld:=torddef(left.resultdef);
|
||||||
end;
|
end;
|
||||||
if (ld.ordtype in [u32bit,u64bit]) and
|
if (ld.ordtype in [u32bit,u64bit]) and
|
||||||
is_constintnode(right) and
|
((is_constintnode(right) and
|
||||||
(tordconstnode(right).value >= 0) then
|
(tordconstnode(right).value >= 0)) or
|
||||||
|
(not is_signed(rd) and
|
||||||
|
(ld.size >= rd.size))) then
|
||||||
begin
|
begin
|
||||||
inserttypeconv(right,left.resultdef);
|
inserttypeconv(right,left.resultdef);
|
||||||
rd:=torddef(right.resultdef);
|
rd:=torddef(right.resultdef);
|
||||||
|
|||||||
14
tests/webtbs/tw8870.pp
Normal file
14
tests/webtbs/tw8870.pp
Normal 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.
|
||||||
Loading…
Reference in New Issue
Block a user