瀏覽代碼

* 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 年之前
父節點
當前提交
5c4f80d6bc
共有 3 個文件被更改,包括 40 次插入0 次删除
  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/tw13813.pp svneol=native#text/plain
 tests/webtbs/tw13820.pp svneol=native#text/plain
 tests/webtbs/tw13820.pp svneol=native#text/plain
 tests/webtbs/tw13890.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/tw1398.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain
 tests/webtbs/tw1407.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;
                   result := fen_norecurse_true;
                 end;
                 end;
             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 }
           { optimize the searching a bit }
           derefn,addrn,
           derefn,addrn,
           calln,inlinen,casen,
           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.