Ver código fonte

* result for functions returning a managed type must be initialized and loaded, fixes #9704

git-svn-id: trunk@8512 -
florian 18 anos atrás
pai
commit
620ceac903
3 arquivos alterados com 21 adições e 3 exclusões
  1. 1 0
      .gitattributes
  2. 6 3
      compiler/ncgutil.pas
  3. 14 0
      tests/webtbs/tw9704.pp

+ 1 - 0
.gitattributes

@@ -8427,6 +8427,7 @@ tests/webtbs/tw9384.pp svneol=native#text/plain
 tests/webtbs/tw9385.pp svneol=native#text/plain
 tests/webtbs/tw9672.pp svneol=native#text/plain
 tests/webtbs/tw9695.pp svneol=native#text/plain
+tests/webtbs/tw9704.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 6 - 3
compiler/ncgutil.pas

@@ -1044,7 +1044,7 @@ implementation
                  nil);
              LOC_CFPUREGISTER :
                begin
-                 { initialize fpu regvar by loading from memory }              
+                 { initialize fpu regvar by loading from memory }
                  reference_reset_symbol(href,
                    current_asmdata.RefAsmSymbol(tstaticvarsym(p).mangledname), 0);
                  cg.a_loadfpu_ref_reg(TAsmList(arg), tstaticvarsym(p).initialloc.size,
@@ -1066,7 +1066,10 @@ implementation
         hp : tnode;
       begin
         if (tsym(p).typ in [staticvarsym,localvarsym]) and
-           (tabstractvarsym(p).refs>0) and
+           ((tabstractvarsym(p).refs>0) or
+            { managed return symbols must be inited }
+            ((tsym(p).typ=localvarsym) and (vo_is_funcret in tlocalvarsym(p).varoptions))
+           ) and
            not(vo_is_typed_const in tabstractvarsym(p).varoptions) and
            not(vo_is_external in tabstractvarsym(p).varoptions) and
            not(is_class(tabstractvarsym(p).vardef)) and
@@ -1311,7 +1314,7 @@ implementation
           ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
         else
           ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
-        if (ressym.refs>0) then
+        if (ressym.refs>0) or (ressym.vardef.needs_inittable) then
           begin
 {$ifdef OLDREGVARS}
             case ressym.localloc.loc of

+ 14 - 0
tests/webtbs/tw9704.pp

@@ -0,0 +1,14 @@
+program bug;
+
+{$H+}
+
+uses
+  SysUtils;
+
+function GetString: String;
+begin
+end;
+
+begin
+  WriteLn(Format('%s', [GetString()]));
+end.