* don't perform temp substitution of an entire array when assigning only the

first array element (related to mantis #13948 and #17413)

git-svn-id: trunk@15992 -
This commit is contained in:
Jonas Maebe 2010-09-15 15:03:32 +00:00
parent b4a15ed612
commit 07e47171d2
4 changed files with 72 additions and 3 deletions

2
.gitattributes vendored
View File

@ -10475,6 +10475,8 @@ tests/webtbs/tw13840/tw13840d.pp svneol=native#text/plain
tests/webtbs/tw13872.pp svneol=native#text/plain
tests/webtbs/tw13890.pp svneol=native#text/plain
tests/webtbs/tw13948.pp svneol=native#text/plain
tests/webtbs/tw13948a.pp svneol=native#text/plain
tests/webtbs/tw13948b.pp svneol=native#text/plain
tests/webtbs/tw1398.pp svneol=native#text/plain
tests/webtbs/tw13984.pp svneol=native#text/plain
tests/webtbs/tw13992a.pp svneol=native#text/plain

View File

@ -123,11 +123,18 @@ implementation
{ Subscriptn must be rejected, otherwise we may replace an
an entire record with a temp for its first field, mantis #13948)
Exception: the field's size is the same as the entire record
The same goes for array indexing
}
subscriptn:
if not(tsubscriptnode(n).left.resultdef.typ in [recorddef,objectdef]) or
(tsubscriptnode(n).left.resultdef.size <> tsubscriptnode(n).resultdef.size) then
subscriptn,
vecn:
if not(tunarynode(n).left.resultdef.typ in [recorddef,objectdef,arraydef,stringdef]) or
{ make sure we don't try to call resultdef.size for types that
don't have a compile-time size such as open arrays }
is_special_array(tunarynode(n).left.resultdef) or
(tsubscriptnode(n).left.resultdef.size <> tunarynode(n).resultdef.size) then
result := fen_norecurse_false;
{ optimize the searching a bit }
derefn,addrn,
calln,inlinen,casen,

31
tests/webtbs/tw13948a.pp Normal file
View File

@ -0,0 +1,31 @@
{ %opt=-O2 }
type
tr = record
a: array[0..1] of longint;
end;
function f: tr;
begin
f.a[0]:=5;
f.a[1]:=6;
end;
procedure test;
var
r: tr;
begin
r.a[0]:=1;
r.a[1]:=2;
r.a[0]:=f.a[0];
writeln(r.a[0]);
writeln(r.a[1]);
if (r.a[0]<>5) then
halt(1);
if (r.a[1]<>2) then
halt(2);
end;
begin
test;
end.

29
tests/webtbs/tw13948b.pp Normal file
View File

@ -0,0 +1,29 @@
{ %opt=-O2 }
type
tr = array[0..1] of longint;
function f: tr;
begin
f[0]:=5;
f[1]:=6;
end;
procedure test;
var
r: tr;
begin
r[0]:=1;
r[1]:=2;
r[0]:=f[0];
writeln(r[0]);
writeln(r[1]);
if (r[0]<>5) then
halt(1);
if (r[1]<>2) then
halt(2);
end;
begin
test;
end.