mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 02:29:36 +02:00
* simplify integer operations with constnat 0 or 1
git-svn-id: trunk@7009 -
This commit is contained in:
parent
69a4e616ba
commit
ab22fd42d1
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -8132,6 +8132,7 @@ tests/webtbs/tw8434.pp svneol=native#text/plain
|
||||
tests/webtbs/tw8462.pp svneol=native#text/plain
|
||||
tests/webtbs/tw8513.pp svneol=native#text/plain
|
||||
tests/webtbs/tw8525.pp svneol=native#text/plain
|
||||
tests/webtbs/tw8573.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
|
||||
|
@ -384,6 +384,52 @@ implementation
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ Add,Sub,Mul with constant 0 or 1? }
|
||||
if is_constintnode(right) then
|
||||
begin
|
||||
if tordconstnode(right).value = 0 then
|
||||
begin
|
||||
case nodetype of
|
||||
addn,subn:
|
||||
result := left.getcopy;
|
||||
muln:
|
||||
result:=cordconstnode.create(0,left.resultdef,true);
|
||||
end;
|
||||
end
|
||||
else if tordconstnode(right).value = 1 then
|
||||
begin
|
||||
case nodetype of
|
||||
muln:
|
||||
result := left.getcopy;
|
||||
end;
|
||||
end;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
end;
|
||||
if is_constintnode(left) then
|
||||
begin
|
||||
if tordconstnode(left).value = 0 then
|
||||
begin
|
||||
case nodetype of
|
||||
addn:
|
||||
result := right.getcopy;
|
||||
subn:
|
||||
result := cunaryminusnode.create(right.getcopy);
|
||||
muln:
|
||||
result:=cordconstnode.create(0,right.resultdef,true);
|
||||
end;
|
||||
end
|
||||
else if tordconstnode(left).value = 1 then
|
||||
begin
|
||||
case nodetype of
|
||||
muln:
|
||||
result := right.getcopy;
|
||||
end;
|
||||
end;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ both real constants ? }
|
||||
if (lt=realconstn) and (rt=realconstn) then
|
||||
begin
|
||||
|
23
tests/webtbs/tw8573.pp
Normal file
23
tests/webtbs/tw8573.pp
Normal file
@ -0,0 +1,23 @@
|
||||
program overflowbug;
|
||||
|
||||
{$mode objfpc}{$Q+}
|
||||
|
||||
const
|
||||
zero=0;
|
||||
one=1;
|
||||
|
||||
var
|
||||
x,y,z: cardinal;
|
||||
|
||||
begin
|
||||
x := 0;
|
||||
y := one + x;
|
||||
|
||||
// the next line sets the carry flag, so a overflow error will be generated
|
||||
if x>y then;
|
||||
// here the overflow error will be generated.
|
||||
// the addition of zero is optimized away, but the check for the carry flag
|
||||
// is not removed, so it is using the result of the compile in line 17
|
||||
z := zero + y;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user