[cfe-commits] r128901 - /cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Chandler Carruth chandlerc at gmail.com
Tue Apr 5 11:27:05 PDT 2011


Author: chandlerc
Date: Tue Apr  5 13:27:05 2011
New Revision: 128901

URL: http://llvm.org/viewvc/llvm-project?rev=128901&view=rev
Log:
Simplify the tracking of when to issue a fixit hint, making the helper
function more clear and obvious in behavior.

Add some comments documenting the behavior of the primary diagnostic helper.

Modified:
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=128901&r1=128900&r2=128901&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Apr  5 13:27:05 2011
@@ -410,7 +410,12 @@
 };
 }
 
-static void DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
+/// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
+/// uninitialized variable. This manages the different forms of diagnostic
+/// emitted for particular types of uses. Returns true if the use was diagnosed
+/// as a warning. If a pariticular use is one we omit warnings for, returns
+/// false.
+static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
                                      const Expr *E, bool isAlwaysUninit) {
   bool isSelfInit = false;
 
@@ -432,7 +437,7 @@
       // variables initialized in this way?
       if (const Expr *Initializer = VD->getInit()) {
         if (DRE == Initializer->IgnoreParenImpCasts())
-          return;
+          return false;
 
         ContainsReference CR(S.Context, DRE);
         CR.Visit(const_cast<Expr*>(Initializer));
@@ -464,16 +469,10 @@
     S.Diag(VD->getLocStart(), diag::note_uninit_var_def)
       << VD->getDeclName();
 
+  return true;
 }
 
-static void SuggestInitializationFixit(Sema &S, const VarDecl *VD,
-                                       bool &fixitIssued) {
-  // Only report the fixit once.
-  if (fixitIssued)
-    return;
-
-  fixitIssued = true;
-
+static void SuggestInitializationFixit(Sema &S, const VarDecl *VD) {
   // Don't issue a fixit if there is already an initializer.
   if (VD->getInit())
     return;
@@ -557,9 +556,15 @@
       
       for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve;
            ++vi) {
-        DiagnoseUninitializedUse(S, vd, vi->first,
-                                 /*isAlwaysUninit=*/vi->second);
-        SuggestInitializationFixit(S, vd, fixitIssued);
+        if (!DiagnoseUninitializedUse(S, vd, vi->first,
+                                      /*isAlwaysUninit=*/vi->second))
+          continue;
+
+        // Suggest a fixit hint the first time we diagnose a use of a variable.
+        if (!fixitIssued) {
+          SuggestInitializationFixit(S, vd);
+          fixitIssued = true;
+        }
       }
 
       delete vec;





More information about the cfe-commits mailing list