[cfe-commits] r137910 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Basic/DiagnosticIDs.cpp lib/Frontend/Warnings.cpp test/Sema/warn-unused-parameters.c

Eli Friedman eli.friedman at gmail.com
Wed Aug 17 19:06:12 PDT 2011


On Wed, Aug 17, 2011 at 6:12 PM, Ted Kremenek <kremenek at apple.com> wrote:
> Author: kremenek
> Date: Wed Aug 17 20:12:56 2011
> New Revision: 137910
>
> URL: http://llvm.org/viewvc/llvm-project?rev=137910&view=rev
> Log:
> Implement '-Weverything', which enables all warnings except those explicitly mapped to be ignored.
>
> Currently this includes -pedantic warnings as well; we'll need to consider whether these should
> be included.

This seems like a bad idea: people will start using it, then complain
whenever we add a new warning which isn't generically applicable
(suppose we add an opt-in warning for C-style casts in C++, for
example).  We already have -Wextra for people who want lots of
warnings.

-Eli

> This works as expected with -Werror.
>
> Test cases were added to Sema/warn-unused-parameters.c, but they should probably be broken off into
> their own test file.
>
> Modified:
>    cfe/trunk/include/clang/Basic/Diagnostic.h
>    cfe/trunk/lib/Basic/Diagnostic.cpp
>    cfe/trunk/lib/Basic/DiagnosticIDs.cpp
>    cfe/trunk/lib/Frontend/Warnings.cpp
>    cfe/trunk/test/Sema/warn-unused-parameters.c
>
> Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=137910&r1=137909&r2=137910&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
> +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Aug 17 20:12:56 2011
> @@ -149,7 +149,8 @@
>  private:
>   unsigned char AllExtensionsSilenced; // Used by __extension__
>   bool IgnoreAllWarnings;        // Ignore all warnings: -w
> -  bool WarningsAsErrors;         // Treat warnings like errors:
> +  bool WarningsAsErrors;         // Treat warnings like errors.
> +  bool EnableAllWarnings;        // Enable all warnings.
>   bool ErrorsAsFatal;            // Treat errors like fatal errors.
>   bool SuppressSystemWarnings;   // Suppress warnings in system headers.
>   bool SuppressAllDiagnostics;   // Suppress all diagnostics.
> @@ -370,6 +371,12 @@
>   void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; }
>   bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; }
>
> +  /// setEnableAllWarnings - When set to true, any unmapped ignored warnings
> +  /// are no longer ignored.  If this and IgnoreAllWarnings are both set,
> +  /// then that one wins.
> +  void setEnableAllWarnings(bool Val) { EnableAllWarnings = Val; }
> +  bool getEnableAllWarnngs() const { return EnableAllWarnings; }
> +
>   /// setWarningsAsErrors - When set to true, any warnings reported are issued
>   /// as errors.
>   void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; }
>
> Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=137910&r1=137909&r2=137910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
> +++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Aug 17 20:12:56 2011
> @@ -43,6 +43,7 @@
>   AllExtensionsSilenced = 0;
>   IgnoreAllWarnings = false;
>   WarningsAsErrors = false;
> +  EnableAllWarnings = false;
>   ErrorsAsFatal = false;
>   SuppressSystemWarnings = false;
>   SuppressAllDiagnostics = false;
>
> Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=137910&r1=137909&r2=137910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
> +++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Aug 17 20:12:56 2011
> @@ -496,14 +496,27 @@
>   switch (MappingInfo & 7) {
>   default: assert(0 && "Unknown mapping!");
>   case diag::MAP_IGNORE:
> -    // Ignore this, unless this is an extension diagnostic and we're mapping
> -    // them onto warnings or errors.
> -    if (!isBuiltinExtensionDiag(DiagID) ||  // Not an extension
> -        Diag.ExtBehavior == Diagnostic::Ext_Ignore || // Ext ignored
> -        (MappingInfo & 8) != 0)             // User explicitly mapped it.
> +    if (Diag.EnableAllWarnings) {
> +      // Leave the warning disabled if it was explicitly ignored.
> +      if ((MappingInfo & 8) != 0)
> +        return DiagnosticIDs::Ignored;
> +
> +      Result = Diag.WarningsAsErrors ? DiagnosticIDs::Error
> +                                     : DiagnosticIDs::Warning;
> +    }
> +    // Otherwise, ignore this diagnostic unless this is an extension diagnostic
> +    // and we're mapping them onto warnings or errors.
> +    else if (!isBuiltinExtensionDiag(DiagID) ||  // Not an extension
> +             Diag.ExtBehavior == Diagnostic::Ext_Ignore || // Ext ignored
> +             (MappingInfo & 8) != 0) {           // User explicitly mapped it.
>       return DiagnosticIDs::Ignored;
> -    Result = DiagnosticIDs::Warning;
> -    if (Diag.ExtBehavior == Diagnostic::Ext_Error) Result = DiagnosticIDs::Error;
> +    }
> +    else {
> +      Result = DiagnosticIDs::Warning;
> +    }
> +
> +    if (Diag.ExtBehavior == Diagnostic::Ext_Error)
> +      Result = DiagnosticIDs::Error;
>     if (Result == DiagnosticIDs::Error && Diag.ErrorsAsFatal)
>       Result = DiagnosticIDs::Fatal;
>     break;
>
> Modified: cfe/trunk/lib/Frontend/Warnings.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Warnings.cpp?rev=137910&r1=137909&r2=137910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/Warnings.cpp (original)
> +++ cfe/trunk/lib/Frontend/Warnings.cpp Wed Aug 17 20:12:56 2011
> @@ -98,6 +98,13 @@
>       Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
>       Opt = Specifier;
>     }
> +
> +    // -Weverything is a special case as well.  It implicitly enables all
> +    // warnings, including ones not explicitly in a warning group.
> +    if (Opt == "everything") {
> +      Diags.setEnableAllWarnings(true);
> +      continue;
> +    }
>
>     // -Wfatal-errors is yet another special case.
>     if (Opt.startswith("fatal-errors")) {
>
> Modified: cfe/trunk/test/Sema/warn-unused-parameters.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-parameters.c?rev=137910&r1=137909&r2=137910&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-unused-parameters.c (original)
> +++ cfe/trunk/test/Sema/warn-unused-parameters.c Wed Aug 17 20:12:56 2011
> @@ -19,4 +19,12 @@
>
>  // CHECK: 5:12: warning: unused parameter 'y'
>  // CHECK: 12:15: warning: unused parameter 'y'
> -// CHECK-unused: 1 warning generated
> \ No newline at end of file
> +// CHECK-unused: 1 warning generated
> +
> +// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s
> +// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s
> +// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s
> +// CHECK-everything: 6 warnings generated
> +// CHECK-everything-error: 5 errors generated
> +// CHECK-everything-no-unused: 5 warnings generated
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list