From: Chandler Carruth Date: Tue, 5 Apr 2011 18:27:05 +0000 (+0000) Subject: Simplify the tracking of when to issue a fixit hint, making the helper X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=262d50e1dcf529317da193ad585c11c16281a7ac;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128901 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index a649ff067e..e482172ca3 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -410,7 +410,12 @@ public: }; } -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 @@ static void DiagnoseUninitializedUse(Sema &S, const VarDecl *VD, // 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(Initializer)); @@ -464,16 +469,10 @@ static void DiagnoseUninitializedUse(Sema &S, const VarDecl *VD, 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 @@ public: 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;