Przeglądaj źródła

* when optimizing temp assignments by simply replacing one temp with
another, it's not enough that the temp sizes are the same, because
the assignment may only apply to part of them. In such cases,
perform a regular copy (mantis #13948)

git-svn-id: trunk@13255 -

Jonas Maebe 16 lat temu
rodzic
commit
5c4f80d6bc
3 zmienionych plików z 40 dodań i 0 usunięć
  1. 1 0
      .gitattributes
  2. 8 0
      compiler/ncgld.pas
  3. 31 0
      tests/webtbs/tw13948.pp

+ 1 - 0
.gitattributes

@@ -9158,6 +9158,7 @@ tests/webtbs/tw13763.pp svneol=native#text/plain
 tests/webtbs/tw13813.pp svneol=native#text/plain
 tests/webtbs/tw13820.pp svneol=native#text/plain
 tests/webtbs/tw13890.pp svneol=native#text/plain
+tests/webtbs/tw13948.pp svneol=native#text/plain
 tests/webtbs/tw1398.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain
 tests/webtbs/tw1407.pp svneol=native#text/plain

+ 8 - 0
compiler/ncgld.pas

@@ -116,6 +116,14 @@ implementation
                   result := fen_norecurse_true;
                 end;
             end;
+          { 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
+          }
+          subscriptn:
+            if not(tsubscriptnode(n).left.resultdef.typ in [recorddef,objectdef]) or
+               (tsubscriptnode(n).left.resultdef.size <> tsubscriptnode(n).resultdef.size) then
+              result := fen_norecurse_false;
           { optimize the searching a bit }
           derefn,addrn,
           calln,inlinen,casen,

+ 31 - 0
tests/webtbs/tw13948.pp

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