mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 06:09:22 +02:00
+ more restrictions on pred/succ to dec/inc optimization
o check if the argument can be used as a call by reference parameter o check if the argument has no side-effects + tests git-svn-id: trunk@34816 -
This commit is contained in:
parent
a02ac161d6
commit
a27b07b342
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -13339,6 +13339,8 @@ tests/test/units/system/todd.pp svneol=native#text/plain
|
|||||||
tests/test/units/system/tparam.pp svneol=native#text/plain
|
tests/test/units/system/tparam.pp svneol=native#text/plain
|
||||||
tests/test/units/system/tpchlen.pp svneol=native#text/plain
|
tests/test/units/system/tpchlen.pp svneol=native#text/plain
|
||||||
tests/test/units/system/tpi.pp svneol=native#text/plain
|
tests/test/units/system/tpi.pp svneol=native#text/plain
|
||||||
|
tests/test/units/system/tpredsucc1.pp svneol=native#text/pascal
|
||||||
|
tests/test/units/system/tpredsucc2.pp svneol=native#text/pascal
|
||||||
tests/test/units/system/trandom.pp svneol=native#text/plain
|
tests/test/units/system/trandom.pp svneol=native#text/plain
|
||||||
tests/test/units/system/trdtxt01.pp svneol=native#text/plain
|
tests/test/units/system/trdtxt01.pp svneol=native#text/plain
|
||||||
tests/test/units/system/trdtxt02.pp svneol=native#text/plain
|
tests/test/units/system/trdtxt02.pp svneol=native#text/plain
|
||||||
|
@ -569,8 +569,9 @@ implementation
|
|||||||
((tinlinenode(right).inlinenumber=in_succ_x) or (tinlinenode(right).inlinenumber=in_pred_x)) and
|
((tinlinenode(right).inlinenumber=in_succ_x) or (tinlinenode(right).inlinenumber=in_pred_x)) and
|
||||||
(tinlinenode(right).left.isequal(left)) and
|
(tinlinenode(right).left.isequal(left)) and
|
||||||
((localswitches*[cs_check_overflow,cs_check_range])=[]) and
|
((localswitches*[cs_check_overflow,cs_check_range])=[]) and
|
||||||
((right.localswitches*[cs_check_overflow,cs_check_range])=[])
|
((right.localswitches*[cs_check_overflow,cs_check_range])=[]) and
|
||||||
then
|
valid_for_var(tinlinenode(right).left,false) and
|
||||||
|
not(might_have_sideeffects(tinlinenode(right).left)) then
|
||||||
begin
|
begin
|
||||||
if tinlinenode(right).inlinenumber=in_succ_x then
|
if tinlinenode(right).inlinenumber=in_succ_x then
|
||||||
result:=cinlinenode.create(
|
result:=cinlinenode.create(
|
||||||
|
42
tests/test/units/system/tpredsucc1.pp
Normal file
42
tests/test/units/system/tpredsucc1.pp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
type
|
||||||
|
tmyclass = class
|
||||||
|
i : integer;
|
||||||
|
function GetI : Integer;
|
||||||
|
procedure SetI(const _i : Integer);
|
||||||
|
property i1 : integer read GetI write SetI;
|
||||||
|
property i2 : integer read i write i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function tmyclass.GetI : Integer;
|
||||||
|
begin
|
||||||
|
Result:=i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure tmyclass.SetI(const _i : Integer);
|
||||||
|
begin
|
||||||
|
i:=_i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
myclass : tmyclass;
|
||||||
|
|
||||||
|
begin
|
||||||
|
myclass:=tmyclass.create;
|
||||||
|
myclass.i1:=1;
|
||||||
|
|
||||||
|
myclass.i1:=pred(myclass.i1);
|
||||||
|
myclass.i1:=succ(myclass.i1);
|
||||||
|
|
||||||
|
myclass.i2:=pred(myclass.i2);
|
||||||
|
myclass.i2:=succ(myclass.i2);
|
||||||
|
|
||||||
|
if myclass.i<>1 then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
myclass.free;
|
||||||
|
|
||||||
|
writeln('ok');
|
||||||
|
end.
|
31
tests/test/units/system/tpredsucc2.pp
Normal file
31
tests/test/units/system/tpredsucc2.pp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
var
|
||||||
|
counter : longint;
|
||||||
|
|
||||||
|
function f : Integer;
|
||||||
|
begin
|
||||||
|
inc(counter);
|
||||||
|
f:=1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
s : array[0..10] of Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
s[1]:=1234;
|
||||||
|
counter:=0;
|
||||||
|
|
||||||
|
s[f]:=succ(s[f]);
|
||||||
|
s[f]:=pred(s[f]);
|
||||||
|
|
||||||
|
if s[1]<>1234 then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if counter<>4 then
|
||||||
|
halt(2);
|
||||||
|
|
||||||
|
writeln('ok');
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user