diff --git a/.gitattributes b/.gitattributes index c71ae963a2..e40ba07318 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/ncgld.pas b/compiler/ncgld.pas index 633edfabe3..028e51e1bb 100644 --- a/compiler/ncgld.pas +++ b/compiler/ncgld.pas @@ -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, diff --git a/tests/webtbs/tw13948a.pp b/tests/webtbs/tw13948a.pp new file mode 100644 index 0000000000..2e5870495e --- /dev/null +++ b/tests/webtbs/tw13948a.pp @@ -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. diff --git a/tests/webtbs/tw13948b.pp b/tests/webtbs/tw13948b.pp new file mode 100644 index 0000000000..49519afd88 --- /dev/null +++ b/tests/webtbs/tw13948b.pp @@ -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.