소스 검색

Merged r29636

git-svn-id: branches/fixes_3_0@31674 -
florian 10 년 전
부모
커밋
96c21fa0fe
3개의 변경된 파일54개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 11 6
      compiler/psub.pas
  3. 42 0
      tests/webtbs/tw25914.pp

+ 1 - 0
.gitattributes

@@ -14154,6 +14154,7 @@ tests/webtbs/tw25869.pp svneol=native#text/plain
 tests/webtbs/tw2588.pp svneol=native#text/plain
 tests/webtbs/tw2589.pp svneol=native#text/plain
 tests/webtbs/tw25895.pp svneol=native#text/pascal
+tests/webtbs/tw25914.pp svneol=native#text/pascal
 tests/webtbs/tw25916a.pp svneol=native#text/pascal
 tests/webtbs/tw25916b.pp svneol=native#text/pascal
 tests/webtbs/tw25929.pp svneol=native#text/pascal

+ 11 - 6
compiler/psub.pas

@@ -1338,13 +1338,18 @@ implementation
               { iterate through life info of the first node }
               for i:=0 to dfabuilder.nodemap.count-1 do
                 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
-                        (tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varspez=vs_var) and
+                  if DFASetIn(GetUserCode.optinfo^.life,i) then
+                    begin
+                      { do not warn for certain parameters: }
+                      if not((tnode(dfabuilder.nodemap[i]).nodetype=loadn) and (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ=paravarsym) and
+                        { do not warn about parameters passed by var }
+                        (((tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varspez=vs_var) and
                         { function result is passed by var but it must be initialized }
-                        not(vo_is_funcret in tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions)) then
-                    CheckAndWarn(GetUserCode,tnode(dfabuilder.nodemap[i]));
+                        not(vo_is_funcret in tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions)) or
+                        { do not warn about initialized hidden parameters }
+                        ((tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions*[vo_is_high_para,vo_is_parentfp,vo_is_result,vo_is_self])<>[]))) then
+                        CheckAndWarn(GetUserCode,tnode(dfabuilder.nodemap[i]));
+                     end;
                 end;
           end;
 

+ 42 - 0
tests/webtbs/tw25914.pp

@@ -0,0 +1,42 @@
+{ %opt=-Sh }
+{$MODE OBJFPC}
+{$HINTS ON}
+{$OPTIMIZATION DFA}
+program test;
+
+type
+   TTest1 = class
+      FArray: array of record end; // or AnsiString
+      procedure TestMethod();
+   end;
+
+procedure TTest1.TestMethod();
+begin
+   SetLength(FArray, 0); // Hint: Local variable "$self" does not seem to be initialized
+end;
+
+type
+   TTest2 = class
+      FString: AnsiString; // or dynamic array
+      procedure TestMethod();
+   end;
+
+procedure TTest2.TestMethod();
+begin
+   FString := Default(AnsiString); // Hint: Local variable "$self" does not seem to be initialized
+end;
+
+type
+   TTest3 = class
+      FValue: Integer;
+      procedure TestMethod(var Value: Integer);
+   end;
+
+procedure TTest3.TestMethod(var Value: Integer);
+begin
+   TestMethod(FValue); // Hint: Local variable "$self" does not seem to be initialized
+   Value:=FValue;
+end;
+
+begin
+end.