Browse Source

+ give more sophisticated warnings about uninitalized variables when life info is available

git-svn-id: trunk@7562 -
florian 18 years ago
parent
commit
63b35fdb2e
4 changed files with 56 additions and 10 deletions
  1. 17 8
      compiler/optdfa.pas
  2. 2 0
      compiler/optutils.pas
  3. 5 1
      compiler/procinfo.pas
  4. 32 1
      compiler/psub.pas

+ 17 - 8
compiler/optdfa.pas

@@ -329,7 +329,7 @@ unit optdfa;
                     dfainfo.map:=map;
                     dfainfo.map:=map;
                     foreachnodestatic(pm_postprocess,tifnode(node).left,@AddDefUse,@dfainfo);
                     foreachnodestatic(pm_postprocess,tifnode(node).left,@AddDefUse,@dfainfo);
                   end;
                   end;
-                { create life info for left and right node }
+                { create life info for then and else node }
                 CreateInfo(tifnode(node).right);
                 CreateInfo(tifnode(node).right);
                 CreateInfo(tifnode(node).t1);
                 CreateInfo(tifnode(node).t1);
 
 
@@ -418,10 +418,22 @@ unit optdfa;
                 calclife(node);
                 calclife(node);
               end;
               end;
 
 
+            calln:
+              begin
+                if not(assigned(node.optinfo^.def)) and
+                  not(assigned(node.optinfo^.use)) then
+                  begin
+                    dfainfo.use:[email protected]^.use;
+                    dfainfo.def:[email protected]^.def;
+                    dfainfo.map:=map;
+                    foreachnodestatic(pm_postprocess,node,@AddDefUse,@dfainfo);
+                  end;
+                calclife(node);
+              end;
+
             tempcreaten,
             tempcreaten,
             tempdeleten,
             tempdeleten,
             inlinen,
             inlinen,
-            calln,
             nothingn,
             nothingn,
             continuen,
             continuen,
             goton,
             goton,
@@ -484,17 +496,14 @@ unit optdfa;
 
 
 
 
     procedure createdfainfo(node : tnode);
     procedure createdfainfo(node : tnode);
-      var
-        map : TIndexedNodeSet;
       begin
       begin
-        map:=TIndexedNodeSet.Create;
+        if not(assigned(current_procinfo.nodemap)) then
+          current_procinfo.nodemap:=TIndexedNodeSet.Create;
         { add controll flow information }
         { add controll flow information }
         SetNodeSucessors(node);
         SetNodeSucessors(node);
 
 
         { now, collect life information }
         { now, collect life information }
-        CreateLifeInfo(node,map);
-
-        map.free;
+        CreateLifeInfo(node,current_procinfo.nodemap);
       end;
       end;
 
 
 end.
 end.

+ 2 - 0
compiler/optutils.pas

@@ -266,6 +266,8 @@ unit optutils;
                 result:=p;
                 result:=p;
                 p.successor:=succ;
                 p.successor:=succ;
               end;
               end;
+            tempcreaten,
+            tempdeleten,
             nothingn:
             nothingn:
                begin
                begin
                 result:=p;
                 result:=p;

+ 5 - 1
compiler/procinfo.pas

@@ -34,7 +34,8 @@ unit procinfo;
       symconst,symtype,symdef,symsym,
       symconst,symtype,symdef,symsym,
       { aasm }
       { aasm }
       cpubase,cpuinfo,cgbase,cgutils,
       cpubase,cpuinfo,cgbase,cgutils,
-      aasmbase,aasmtai,aasmdata
+      aasmbase,aasmtai,aasmdata,
+      optutils
       ;
       ;
 
 
     const
     const
@@ -102,6 +103,9 @@ unit procinfo;
           { max. of space need for parameters }
           { max. of space need for parameters }
           maxpushedparasize : aint;
           maxpushedparasize : aint;
 
 
+          { node to index mapping for the node level optimizer }
+          nodemap : TIndexedNodeSet;
+
           constructor create(aparent:tprocinfo);virtual;
           constructor create(aparent:tprocinfo);virtual;
           destructor destroy;override;
           destructor destroy;override;
 
 

+ 32 - 1
compiler/psub.pas

@@ -102,9 +102,11 @@ implementation
        { codegen }
        { codegen }
        tgobj,cgbase,cgobj,dbgbase,
        tgobj,cgbase,cgobj,dbgbase,
        ncgutil,regvars,
        ncgutil,regvars,
+       optbase,
        opttail,
        opttail,
        optcse,
        optcse,
-       optdfa
+       optdfa,
+       optutils
 {$if defined(arm) or defined(powerpc) or defined(powerpc64)}
 {$if defined(arm) or defined(powerpc) or defined(powerpc64)}
        ,aasmcpu
        ,aasmcpu
 {$endif arm}
 {$endif arm}
@@ -692,6 +694,8 @@ implementation
         oldfilepos : tfileposinfo;
         oldfilepos : tfileposinfo;
         templist : TAsmList;
         templist : TAsmList;
         headertai : tai;
         headertai : tai;
+        i : integer;
+        varsym : tabstractnormalvarsym;
       begin
       begin
         { the initialization procedure can be empty, then we
         { the initialization procedure can be empty, then we
           don't need to generate anything. When it was an empty
           don't need to generate anything. When it was an empty
@@ -763,6 +767,33 @@ implementation
                   pi_needs_stackframe])=[]) then
                   pi_needs_stackframe])=[]) then
           begin
           begin
             createdfainfo(code);
             createdfainfo(code);
+            { when life info is available, we can give more sophisticated warning about unintialized
+              variables }
+
+            { iterate through life info of the first node }
+            for i:=0 to nodemap.count-1 do
+              begin
+                if DFASetIn(code.optinfo^.life,i) then
+                  case tnode(nodemap[i]).nodetype of
+                    loadn:
+                      begin
+                        varsym:=tabstractnormalvarsym(tloadnode(nodemap[i]).symtableentry);
+
+                        { Give warning/note for living locals }
+                        if assigned(varsym.owner) and
+                          not(vo_is_external in varsym.varoptions) then
+                          begin
+                            if (vo_is_funcret in varsym.varoptions) then
+                              CGMessage(sym_w_function_result_uninitialized)
+                            else
+                              begin
+                                if varsym.owner=procdef.localst then
+                                  CGMessage1(sym_w_uninitialized_local_variable,varsym.realname);
+                              end;
+                          end;
+                      end;
+                  end;
+              end;
           end;
           end;
 
 
         if cs_opt_nodecse in current_settings.optimizerswitches then
         if cs_opt_nodecse in current_settings.optimizerswitches then