Răsfoiți Sursa

* make self-pointer passed by reference not regable. Was not necessary
when we only had objects because they are never put in registers,
but (advanced) records can be (mantis #21177)

git-svn-id: trunk@20192 -

Jonas Maebe 13 ani în urmă
părinte
comite
1f83203117
3 a modificat fișierele cu 36 adăugiri și 0 ștergeri
  1. 1 0
      .gitattributes
  2. 6 0
      compiler/ncal.pas
  3. 29 0
      tests/webtbs/tw21177.pp

+ 1 - 0
.gitattributes

@@ -12179,6 +12179,7 @@ tests/webtbs/tw2109.pp svneol=native#text/plain
 tests/webtbs/tw2110.pp svneol=native#text/plain
 tests/webtbs/tw21146.pp svneol=native#text/pascal
 tests/webtbs/tw21151.pp svneol=native#text/plain
+tests/webtbs/tw21177.pp svneol=native#text/plain
 tests/webtbs/tw2128.pp svneol=native#text/plain
 tests/webtbs/tw2129.pp svneol=native#text/plain
 tests/webtbs/tw2129b.pp svneol=native#text/plain

+ 6 - 0
compiler/ncal.pas

@@ -2337,6 +2337,12 @@ implementation
                        para.left:=gen_procvar_context_tree
                      else
                        para.left:=gen_self_tree;
+                     { make sure that e.g. the self pointer of an advanced
+                       record does not become a regvar, because it's a vs_var
+                       parameter }
+                     if paramanager.push_addr_param(para.parasym.varspez,para.parasym.vardef,
+                         procdefinition.proccalloption) then
+                       make_not_regable(para.left,[ra_addr_regable]);
                    end
                 else
                  if vo_is_vmt in para.parasym.varoptions then

+ 29 - 0
tests/webtbs/tw21177.pp

@@ -0,0 +1,29 @@
+{$modeswitch ADVANCEDRECORDS}
+{$OPTIMIZATION REGVAR}
+program record_bug;
+
+type
+TColor = object
+  R : Byte;
+  function toDWord : DWord;
+end;
+
+function TColor.toDWord : DWord;
+begin
+  r:=4;
+  toDWord:=5;
+end;
+
+procedure Fill(Color: TColor);
+begin
+  Color.toDWord;
+  if color.r<>4 then
+    halt(1);
+end;
+
+var
+  c: TColor;
+begin
+  c.r:=1;
+  Fill(c);
+end.