[cfe-commits] r123995 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/AnalysisBasedWarnings.cpp test/Sema/uninit-variables.c

Douglas Gregor dgregor at apple.com
Fri Jan 21 13:08:07 PST 2011


On Jan 21, 2011, at 11:41 AM, Ted Kremenek wrote:

> Author: kremenek
> Date: Fri Jan 21 13:41:46 2011
> New Revision: 123995
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=123995&view=rev
> Log:
> Add basic fixits for -Wuninitialized-experimental
> to suggest initializations for pointer and
> ObjC pointer types.
> 
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>    cfe/trunk/test/Sema/uninit-variables.c
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=123995&r1=123994&r2=123995&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 21 13:41:46 2011
> @@ -824,6 +824,8 @@
>   InGroup<DiagGroup<"uninitialized-experimental">>, DefaultIgnore;
> def note_var_is_uninit : Note<
>   "variable %0 is possibly uninitialized when used here">;
> +def note_var_fixit_add_initialization : Note<
> +  "add initialization to silence this warning">;
> def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
> 
> def err_temp_copy_no_viable : Error<
> 
> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=123995&r1=123994&r2=123995&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jan 21 13:41:46 2011
> @@ -16,6 +16,7 @@
> #include "clang/Sema/AnalysisBasedWarnings.h"
> #include "clang/Sema/SemaInternal.h"
> #include "clang/Basic/SourceManager.h"
> +#include "clang/Lex/Preprocessor.h"
> #include "clang/AST/DeclObjC.h"
> #include "clang/AST/DeclCXX.h"
> #include "clang/AST/ExprObjC.h"
> @@ -405,7 +406,7 @@
> 
>       S.Diag(vd->getLocStart(), diag::warn_var_is_uninit)
>         << vd->getDeclName() << vd->getSourceRange();
> -
> +      
>       // Sort the uses by their SourceLocations.  While not strictly
>       // guaranteed to produce them in line/column order, this will provide
>       // a stable ordering.
> @@ -417,6 +418,24 @@
>         S.Diag(dr->getLocStart(), diag::note_var_is_uninit)
>           << vd->getDeclName() << dr->getSourceRange();
>       }
> +
> +      // Suggest possible initialization (if any).
> +      const char *initialization = 0;
> +      QualType vdTy = vd->getType();
> +      
> +      if (vdTy->getAs<ObjCObjectPointerType>()) {
> +        initialization = " = nil";
> +      }

Should you check if "nil" is defined as a macro?

	- Doug





More information about the cfe-commits mailing list