public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c/53063 Handle Wformat with LangEnabledBy
@ 2012-10-17 22:24 Manuel López-Ibáñez
  2012-10-19 16:22 ` Joseph S. Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Manuel López-Ibáñez @ 2012-10-17 22:24 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 1288 bytes --]

Bootstrapped and regression tested on x86_64-linux-gnu. Since Wformat
didn't have Var() associated, its corresponding entry was set to -1,
which is what warning(OPT_Wformat) checks for. Therefore, any such
warnings which were not guarded by if(warn_format), were enabled by
default. I only found one case in the objective-C FE.

The old code accepts -Wformat=X with X any number but -Wno-format=2
does not have any effect. The documentation only mentions -Wformat,
-Wno-format, -Wformat=2 and -Wno-format=2. I followed the
documentation but I can also implement -Wformat=0 being an alias for
-Wno-format and -Wformat=1 an alias for -Wformat and simply reject
-Wno-format=.

2012-10-17  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/53063
c-family/
	* c.opt (Wformat, Wformat-extra-args, Wformat-nonliteral,
	Wformat-contains-nul, Wformat-security, Wformat-y2k,
	Wformat-zero-length, Wformat=2, Wnonnull): Use LangEnabledBy.
	* c-opts.c (c_common_handle_option): Do not handle explicitly
	here.
	* c-common.c (warn_format): Delete.
	* c-format.c (set_Wformat): Delete.
	* c-common.h (warn_format,set_Wformat): Do not declare.
testsuite/
	* gcc.dg/warn-nsstring.c: Add -Wformat.
	* gcc.misc-tests/help.exp (check_for_options): Use
	-Wstrict-aliasing for test.

[-- Attachment #2: wformat.diff --]
[-- Type: application/octet-stream, Size: 8915 bytes --]

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt	(revision 192504)
+++ gcc/c-family/c.opt	(working copy)
@@ -371,39 +371,43 @@ This switch is deprecated; use -Werror=i
 Wfloat-equal
 C ObjC C++ ObjC++ Var(warn_float_equal) Warning
 Warn if testing floating point numbers for equality
 
 Wformat
-C ObjC C++ ObjC++ Warning
+C ObjC C++ ObjC++ Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=2,2,0)
 Warn about printf/scanf/strftime/strfmon format string anomalies
 
+Wformat
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
+;
+
 Wformat-extra-args
-C ObjC C++ ObjC++ Var(warn_format_extra_args) Warning
+C ObjC C++ ObjC++ Var(warn_format_extra_args) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat)
 Warn if passing too many arguments to a function for its format string
 
 Wformat-nonliteral
-C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning
+C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=2)
 Warn about format strings that are not literals
 
 Wformat-contains-nul
-C ObjC C++ ObjC++ Var(warn_format_contains_nul) Warning
+C ObjC C++ ObjC++ Var(warn_format_contains_nul) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat)
 Warn about format strings that contain NUL bytes
 
 Wformat-security
-C ObjC C++ ObjC++ Var(warn_format_security) Warning
+C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=2)
 Warn about possible security problems with format functions
 
 Wformat-y2k
-C ObjC C++ ObjC++ Var(warn_format_y2k) Warning
+C ObjC C++ ObjC++ Var(warn_format_y2k) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=2)
 Warn about strftime formats yielding 2-digit years
 
 Wformat-zero-length
-C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning
+C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat)
 Warn about zero-length formats
 
-Wformat=
-C ObjC C++ ObjC++ Joined Warning
+Wformat=2
+C ObjC C++ ObjC++ Warning
 
 Wignored-qualifiers
 C C++ Var(warn_ignored_qualifiers) Warning EnabledBy(Wextra)
 Warn whenever type qualifiers are ignored.
 
@@ -524,13 +528,17 @@ Warn when non-templatized friend functio
 Wnon-virtual-dtor
 C++ ObjC++ Var(warn_nonvdtor) Warning
 Warn about non-virtual destructors
 
 Wnonnull
-C ObjC C++ ObjC++ Var(warn_nonnull) Warning
+C ObjC C++ ObjC++ Var(warn_nonnull) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat)
 Warn about NULL being passed to argument slots marked as requiring non-NULL
 
+Wnonnull
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
+;
+
 Wnormalized=
 C ObjC C++ ObjC++ Joined Warning
 -Wnormalized=<id|nfc|nfkc>	Warn about non-normalised Unicode strings
 
 Wold-style-cast
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 192504)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -363,11 +363,10 @@ c_common_handle_option (size_t scode, co
       /* ??? Don't add new options here. Use LangEnabledBy in c.opt.  */
       handle_generated_option (&global_options, &global_options_set,
 			       OPT_Wunused, NULL, value,
 			       c_family_lang_mask, kind, loc,
 			       handlers, global_dc);
-      set_Wformat (value);
       handle_generated_option (&global_options, &global_options_set,
 			       OPT_Wimplicit, NULL, value,
 			       c_family_lang_mask, kind, loc,
 			       handlers, global_dc);
       warn_char_subscripts = value;
@@ -441,18 +440,10 @@ c_common_handle_option (size_t scode, co
 
     case OPT_Wendif_labels:
       cpp_opts->warn_endif_labels = value;
       break;
 
-    case OPT_Wformat:
-      set_Wformat (value);
-      break;
-
-    case OPT_Wformat_:
-      set_Wformat (atoi (arg));
-      break;
-
     case OPT_Wimplicit:
       gcc_assert (value == 0 || value == 1);
       if (warn_implicit_int == -1)
 	handle_generated_option (&global_options, &global_options_set,
 				 OPT_Wimplicit_int, NULL, value,
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 192504)
+++ gcc/c-family/c-common.c	(working copy)
@@ -195,15 +195,10 @@ int flag_iso;
 
 /* Warn about #pragma directives that are not recognized.  */
 
 int warn_unknown_pragmas; /* Tri state variable.  */
 
-/* Warn about format/argument anomalies in calls to formatted I/O functions
-   (*printf, *scanf, strftime, strfmon, etc.).  */
-
-int warn_format;
-
 /* C/ObjC language option variables.  */
 
 
 /* Nonzero means allow type mismatches in conditional expressions;
    just make their values `void'.  */
Index: gcc/c-family/c-format.c
===================================================================
--- gcc/c-family/c-format.c	(revision 192504)
+++ gcc/c-family/c-format.c	(working copy)
@@ -32,31 +32,10 @@ along with GCC; see the file COPYING3.  
 #include "langhooks.h"
 #include "c-format.h"
 #include "alloc-pool.h"
 #include "c-target.h"
 \f
-/* Set format warning options according to a -Wformat=n option.  */
-
-void
-set_Wformat (int setting)
-{
-  warn_format = setting;
-  warn_format_extra_args = setting;
-  warn_format_zero_length = setting;
-  warn_format_contains_nul = setting;
-  if (setting != 1)
-    {
-      warn_format_nonliteral = setting;
-      warn_format_security = setting;
-      warn_format_y2k = setting;
-    }
-  /* Make sure not to disable -Wnonnull if -Wformat=0 is specified.  */
-  if (setting)
-    warn_nonnull = setting;
-}
-
-\f
 /* Handle attributes associated with format checking.  */
 
 /* This must be in the same order as format_types, except for
    format_type_error.  Target-specific format types do not have
    matching enum values.  */
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 192504)
+++ gcc/c-family/c-common.h	(working copy)
@@ -587,16 +587,10 @@ extern int flag_iso;
 
 /* Warn about #pragma directives that are not recognized.  */
 
 extern int warn_unknown_pragmas; /* Tri state variable.  */
 
-/* Warn about format/argument anomalies in calls to formatted I/O functions
-   (*printf, *scanf, strftime, strfmon, etc.).  */
-
-extern int warn_format;
-
-
 /* C/ObjC language option variables.  */
 
 
 /* Nonzero means allow type mismatches in conditional expressions;
    just make their values `void'.  */
@@ -734,11 +728,10 @@ extern void check_function_arguments_rec
 					       unsigned HOST_WIDE_INT),
 					      void *, tree,
 					      unsigned HOST_WIDE_INT);
 extern bool check_builtin_function_arguments (tree, int, tree *);
 extern void check_function_format (tree, int, tree *);
-extern void set_Wformat (int);
 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
 extern bool attribute_takes_identifier_p (const_tree);
 extern bool c_common_handle_option (size_t, const char *, int, int, location_t,
 				    const struct cl_option_handlers *);
Index: gcc/testsuite/gcc.dg/warn-nsstring.c
===================================================================
--- gcc/testsuite/gcc.dg/warn-nsstring.c	(revision 192504)
+++ gcc/testsuite/gcc.dg/warn-nsstring.c	(working copy)
@@ -1,7 +1,7 @@
 /* Check that the NSString format extension is rejected in c.  */
 /* { dg-do compile } */
-
+/* { dg-options "-Wformat" } */
 extern void NSLog (void *fmt, ...) __attribute__((format(__NSString__, 1, 2))); /* { dg-warning "is only allowed in Objective-C dialects" } */
 extern void NSLog1 (void *fmt, ...) __attribute__((format(NSString, 1, 2))); /* { dg-warning "is only allowed in Objective-C dialects" } */
 
 
Index: gcc/testsuite/gcc.misc-tests/help.exp
===================================================================
--- gcc/testsuite/gcc.misc-tests/help.exp	(revision 192504)
+++ gcc/testsuite/gcc.misc-tests/help.exp	(working copy)
@@ -66,14 +66,14 @@ check_for_options c "--help=params --hel
 maximum number of
 -O
 } "" ""
 
 # Ensure PR 37805 is fixed.
-check_for_options c "--help=joined" "Wformat=" "-fstrict-prototype" ""
+check_for_options c "--help=joined" "Wstrict-aliasing=" "-fstrict-prototype" ""
 check_for_options c "--help=separate" "-MF" "-fstrict-prototype" ""
-check_for_options c "--help=warnings,joined" "Wformat=" "Wtrigraphs" ""
-check_for_options c "--help=warnings,^joined" "Wtrigraphs" "Wformat=" ""
+check_for_options c "--help=warnings,joined" "Wstrict-aliasing=" "Wtrigraphs" ""
+check_for_options c "--help=warnings,^joined" "Wtrigraphs" "Wstrict-aliasing=" ""
 check_for_options c "--help=joined,separate" "-I" "" ""
 check_for_options c "--help=^joined,separate" "--param " "" ""
 check_for_options c "--help=joined,^separate" "--help=" "" ""
 check_for_options c "--help=joined,undocumented" "" "" ""
 # Listing only excludes gives empty results.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-11-03 17:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-17 22:24 PR c/53063 Handle Wformat with LangEnabledBy Manuel López-Ibáñez
2012-10-19 16:22 ` Joseph S. Myers
2012-10-23 19:38   ` Manuel López-Ibáñez
2012-10-24  0:54     ` Joseph S. Myers
2012-10-27 17:03   ` Manuel López-Ibáñez
2012-11-03 17:19     ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).