]> granicus.if.org Git - clang/commitdiff
Revert r194097: "With this patch -Wwrite-strings is still implemented with the terrible
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 7 Feb 2014 08:33:28 +0000 (08:33 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 7 Feb 2014 08:33:28 +0000 (08:33 +0000)
    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

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Driver/Options.td
lib/Driver/Tools.cpp
test/Driver/clang_f_opts.c
test/PCH/different-diagnostic-level.c [new file with mode: 0644]

index c06a086eafe315a5868b21489e144aa0706a673a..b765677bdf045f9d1c3e43503d87133f96e0cfaf 100644 (file)
@@ -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">;
index 731bb0406b36fa878ca358bd6839183a6d1acc4c..d860d8f7dbcc12eb834fe7e0b333d3f2a3cb6f54 100644 (file)
@@ -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">,
index d0bcabf215414decb8b81316da394ce2ca595360..d2bb9ba5327a0ffb6d8964c9a5a28e053521cdd6 100644 (file)
@@ -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");
   }
 
index 70826d7299f3a829b48ef778add3344bfdbd22e4..e3be2eff9b5fc3064f41ae1f1b0e99a0b373954e 100644 (file)
 // 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 (file)
index 0000000..ac1a0da
--- /dev/null
@@ -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