diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-07 08:33:28 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-07 08:33:28 +0000 |
commit | 229253a4431d77d43c067e8d086bb8fd800f65bf (patch) | |
tree | c24f3993521d9397379a966eabfac830170fa5d2 | |
parent | 61a09b7d35b270bd78c7869fa524f5071fffdd1c (diff) | |
download | clang-229253a4431d77d43c067e8d086bb8fd800f65bf.tar.gz clang-229253a4431d77d43c067e8d086bb8fd800f65bf.tar.bz2 clang-229253a4431d77d43c067e8d086bb8fd800f65bf.tar.xz |
Revert r194097: "With this patch -Wwrite-strings is still implemented with the terrible
hack of passing -fconst-strings to -cc1"
Passing or not a language option based on diagnostic settings is a bad idea, it breaks
using a PCH that was compiled with different diagnostic settings.
Also add a test case to make sure we don't regress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200964 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Driver/Options.td | 2 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 11 | ||||
-rw-r--r-- | test/Driver/clang_f_opts.c | 4 | ||||
-rw-r--r-- | test/PCH/different-diagnostic-level.c | 17 |
5 files changed, 28 insertions, 8 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c06a086eaf..b765677bdf 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4557,8 +4557,6 @@ def warn_deprecated_string_literal_conversion : Warning< def ext_deprecated_string_literal_conversion : ExtWarn< "ISO C++11 does not allow conversion from string literal to %0">, InGroup<CXX11CompatDeprecatedWritableStr>, SFINAEFailure; -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">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 731bb0406b..d860d8f7db 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -279,6 +279,8 @@ def Wnonportable_cfstrings : Joined<["-"], "Wnonportable-cfstrings">, Group<W_Gr 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">, diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d0bcabf215..d2bb9ba532 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -21,7 +21,6 @@ #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" @@ -2881,9 +2880,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // 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)) { - DiagnosticsEngine::Level DiagLevel = D.getDiags().getDiagnosticLevel( - diag::warn_deprecated_string_literal_conversion_c, SourceLocation()); - if (DiagLevel > DiagnosticsEngine::Ignored) + // 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)) CmdArgs.push_back("-fconst-strings"); } diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index 70826d7299..e3be2eff9b 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -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 diff --git a/test/PCH/different-diagnostic-level.c b/test/PCH/different-diagnostic-level.c new file mode 100644 index 0000000000..ac1a0daab1 --- /dev/null +++ b/test/PCH/different-diagnostic-level.c @@ -0,0 +1,17 @@ +// RUN: %clang -x c-header %s -Weverything -o %t.h.pch +// RUN: %clang -x c %s -w -include %t.h -fsyntax-only -Xclang -verify + +#ifndef HEADER +#define HEADER + +extern int foo; + +#else + +void f() { + int a = foo; + // Make sure we parsed this by getting an error. + int b = bar; // expected-error {{undeclared}} +} + +#endif |