* don't narrow expressions that contain a mod/div followed by an "and",

since the mod/div get a different result if calculated using fewer
    bits (mantis )

git-svn-id: trunk@33413 -
This commit is contained in:
Jonas Maebe 2016-04-02 22:09:34 +00:00
parent ad34300873
commit 1e1b36515e
3 changed files with 25 additions and 2 deletions

1
.gitattributes vendored
View File

@ -14996,6 +14996,7 @@ tests/webtbs/tw2984.pp svneol=native#text/plain
tests/webtbs/tw29893.pp svneol=native#text/pascal
tests/webtbs/tw29912.pp svneol=native#text/plain
tests/webtbs/tw29923.pp svneol=native#text/plain
tests/webtbs/tw29930.pp svneol=native#text/plain
tests/webtbs/tw2998.pp svneol=native#text/plain
tests/webtbs/tw2999.pp svneol=native#text/plain
tests/webtbs/tw3004.pp svneol=native#text/plain

View File

@ -2563,8 +2563,11 @@ implementation
result:=
(docheckremoveinttypeconvs(tbinarynode(n).left) and
docheckremoveinttypeconvs(tbinarynode(n).right)) or
((n.nodetype=andn) and wasoriginallysmallerint(tbinarynode(n).left)) or
((n.nodetype=andn) and wasoriginallysmallerint(tbinarynode(n).right));
{ in case of div/mod, the result of that division/modulo can
usually be different in 32 and 64 bit }
(not gotdivmod and
(((n.nodetype=andn) and wasoriginallysmallerint(tbinarynode(n).left)) or
((n.nodetype=andn) and wasoriginallysmallerint(tbinarynode(n).right))));
end;
end;
end;

19
tests/webtbs/tw29930.pp Normal file
View File

@ -0,0 +1,19 @@
program and_problem;
{$mode objfpc}{$H+}
var
a : extended;
d : longint;
begin
a := -1;
d := (round(a*512) div 180) and 1023;
writeln(d);
if d<>1022 then
halt(1);
d := (round(a*512) div 180);
while (d<0) do d := d+1024;
writeln(d);
if d<>1022 then
halt(1);
end.