فهرست منبع

* limit initialization to register variables which really need to be initialized

git-svn-id: trunk@29569 -
florian 10 سال پیش
والد
کامیت
69ac7dd7ef
3فایلهای تغییر یافته به همراه16 افزوده شده و 5 حذف شده
  1. 1 1
      compiler/hlcgobj.pas
  2. 12 4
      compiler/psub.pas
  3. 3 0
      compiler/symsym.pas

+ 1 - 1
compiler/hlcgobj.pas

@@ -4387,7 +4387,7 @@ implementation
     var
     var
       href : treference;
       href : treference;
     begin
     begin
-      if (tsym(p).typ=staticvarsym) then
+      if (tsym(p).typ=staticvarsym) and not(tstaticvarsym(p).noregvarinitneeded) then
        begin
        begin
          { Static variables can have the initialloc only set to LOC_CxREGISTER
          { Static variables can have the initialloc only set to LOC_CxREGISTER
            or LOC_INVALID, for explaination see gen_alloc_symtable (PFV) }
            or LOC_INVALID, for explaination see gen_alloc_symtable (PFV) }

+ 12 - 4
compiler/psub.pas

@@ -1334,13 +1334,21 @@ implementation
               { iterate through life info of the first node }
               { iterate through life info of the first node }
               for i:=0 to dfabuilder.nodemap.count-1 do
               for i:=0 to dfabuilder.nodemap.count-1 do
                 begin
                 begin
-                  if DFASetIn(GetUserCode.optinfo^.life,i) and
-                    { do not warn about parameters passed by var }
-                    not((tnode(dfabuilder.nodemap[i]).nodetype=loadn) and (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ=paravarsym) and
+                  if DFASetIn(GetUserCode.optinfo^.life,i) then
+                    begin
+                      { do not warn about parameters passed by var }
+                      if not((tnode(dfabuilder.nodemap[i]).nodetype=loadn) and (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ=paravarsym) and
                         (tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varspez=vs_var) and
                         (tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varspez=vs_var) and
                         { function result is passed by var but it must be initialized }
                         { function result is passed by var but it must be initialized }
                         not(vo_is_funcret in tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions)) then
                         not(vo_is_funcret in tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions)) then
-                    CheckAndWarn(GetUserCode,tnode(dfabuilder.nodemap[i]));
+                        CheckAndWarn(GetUserCode,tnode(dfabuilder.nodemap[i]));
+                    end
+                  else
+                    begin
+                      if (tnode(dfabuilder.nodemap[i]).nodetype=loadn) and
+                        (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ in [staticvarsym,localvarsym]) then
+                        tabstractnormalvarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).noregvarinitneeded:=true
+                    end;
                 end;
                 end;
           end;
           end;
 
 

+ 3 - 0
compiler/symsym.pas

@@ -220,6 +220,9 @@ interface
           currentregloc  : TLocation;
           currentregloc  : TLocation;
           { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
           { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
           inparentfpstruct : boolean;
           inparentfpstruct : boolean;
+          { the variable is not living at entry of the scope, so it does not need to be initialized if it is a reg. var
+            (not written to ppu, because not important and would change interface crc) }
+          noregvarinitneeded : boolean;
           constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
           constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
           constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
           constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
           function globalasmsym: boolean;
           function globalasmsym: boolean;