r194097 - With this patch -Wwrite-strings is still implemented with the terrible

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri Feb 7 00:46:59 PST 2014


Hi Rafael,

I reverted this in r200964 because it broke using a PCH with different diagnostic settings, see the test case in that commit.

-Argyrios

On Nov 5, 2013, at 1:43 PM, Rafael Espindola <rafael.espindola at gmail.com> wrote:

> Author: rafael
> Date: Tue Nov  5 15:43:54 2013
> New Revision: 194097
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=194097&view=rev
> Log:
> With this patch -Wwrite-strings is still implemented with the terrible
> hack of passing -fconst-strings to -cc1, but at least the driver uses
> the regular warning checking code path.
> 
> Since we don't support a warning that is DefaultIgnore in one language
> but not in another, this patch creates a dummy C only warning in the same
> group as the existing one to get the desired effect.
> 
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/include/clang/Driver/Options.td
>    cfe/trunk/lib/Driver/Tools.cpp
>    cfe/trunk/test/Driver/clang_f_opts.c
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=194097&r1=194096&r2=194097&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov  5 15:43:54 2013
> @@ -4493,6 +4493,8 @@ def ext_array_init_parens : ExtWarn<
>   InGroup<DiagGroup<"gnu-array-member-paren-init">>, DefaultError;
> def warn_deprecated_string_literal_conversion : Warning<
>   "conversion from string literal to %0 is deprecated">, InGroup<DeprecatedWritableStr>;
> +def warn_deprecated_string_literal_conversion_c : Warning<
> +  "dummy warning to enable -fconst-strings">, InGroup<DeprecatedWritableStr>, DefaultIgnore;
> def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">;
> def err_typecheck_sclass_fscope : Error<
>   "illegal storage class on file-scoped variable">;
> 
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=194097&r1=194096&r2=194097&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Tue Nov  5 15:43:54 2013
> @@ -262,8 +262,6 @@ def Wnonportable_cfstrings : Joined<["-"
> def Wp_COMMA : CommaJoined<["-"], "Wp,">,
>   HelpText<"Pass the comma separated arguments in <arg> to the preprocessor">,
>   MetaVarName<"<arg>">;
> -def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group<W_Group>, Flags<[CC1Option]>;
> -def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group<W_Group>, Flags<[CC1Option]>;
> def W_Joined : Joined<["-"], "W">, Group<W_Group>, Flags<[CC1Option, CoreOption]>,
>   MetaVarName<"<warning>">, HelpText<"Enable the specified warning">;
> def Xanalyzer : Separate<["-"], "Xanalyzer">,
> 
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=194097&r1=194096&r2=194097&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Tue Nov  5 15:43:54 2013
> @@ -21,6 +21,7 @@
> #include "clang/Driver/SanitizerArgs.h"
> #include "clang/Driver/ToolChain.h"
> #include "clang/Driver/Util.h"
> +#include "clang/Sema/SemaDiagnostic.h"
> #include "llvm/ADT/SmallString.h"
> #include "llvm/ADT/StringExtras.h"
> #include "llvm/ADT/StringSwitch.h"
> @@ -2790,13 +2791,9 @@ void Clang::ConstructJob(Compilation &C,
>   // behavior for now. FIXME: Directly diagnose uses of a string literal as
>   // a non-const char* in C, rather than using this crude hack.
>   if (!types::isCXX(InputType)) {
> -    // FIXME: This should behave just like a warning flag, and thus should also
> -    // respect -Weverything, -Wno-everything, -Werror=write-strings, and so on.
> -    Arg *WriteStrings =
> -        Args.getLastArg(options::OPT_Wwrite_strings,
> -                        options::OPT_Wno_write_strings, options::OPT_w);
> -    if (WriteStrings &&
> -        WriteStrings->getOption().matches(options::OPT_Wwrite_strings))
> +    DiagnosticsEngine::Level DiagLevel = D.getDiags().getDiagnosticLevel(
> +        diag::warn_deprecated_string_literal_conversion_c, SourceLocation());
> +    if (DiagLevel > DiagnosticsEngine::Ignored)
>       CmdArgs.push_back("-fconst-strings");
>   }
> 
> 
> Modified: cfe/trunk/test/Driver/clang_f_opts.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=194097&r1=194096&r2=194097&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/clang_f_opts.c (original)
> +++ cfe/trunk/test/Driver/clang_f_opts.c Tue Nov  5 15:43:54 2013
> @@ -15,11 +15,11 @@
> // CHECK-OPTIONS2: -fno-show-source-location
> 
> // RUN: %clang -### -S -Wwrite-strings %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS1 %s
> +// RUN: %clang -### -S -Weverything %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS1 %s
> // WRITE-STRINGS1: -fconst-strings
> // RUN: %clang -### -S -Wwrite-strings -Wno-write-strings %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS2 %s
> +// RUN: %clang -### -S -Wwrite-strings -w %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS2 %s
> // WRITE-STRINGS2-NOT: -fconst-strings
> -// RUN: %clang -### -S -Wwrite-strings -w %s 2>&1 | FileCheck -check-prefix=WRITE-STRINGS3 %s
> -// WRITE-STRINGS3-NOT: -fconst-strings
> 
> // RUN: %clang -### -x c++ -c %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s
> // RUN: %clang -### -x c++ -c -Wdeprecated %s 2>&1 | FileCheck -check-prefix=DEPRECATED-ON-CHECK %s
> 
> 
> _______________________________________________
> 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