mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 22:47:59 +02:00
* 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:
parent
b4a15ed612
commit
07e47171d2
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -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
|
||||
|
@ -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
31
tests/webtbs/tw13948a.pp
Normal 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
29
tests/webtbs/tw13948b.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user