Browse Source

* 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 -

Jonas Maebe 15 years ago
parent
commit
07e47171d2
4 changed files with 72 additions and 3 deletions
  1. 2 0
      .gitattributes
  2. 10 3
      compiler/ncgld.pas
  3. 31 0
      tests/webtbs/tw13948a.pp
  4. 29 0
      tests/webtbs/tw13948b.pp

+ 2 - 0
.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

+ 10 - 3
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,

+ 31 - 0
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.

+ 29 - 0
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.