public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c/53063 Use (Lang)EnabledBy for a bunch of options
@ 2012-10-17 17:29 Manuel López-Ibáñez
  2012-10-19 16:10 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Manuel López-Ibáñez @ 2012-10-17 17:29 UTC (permalink / raw)
  To: Gcc Patch List

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

Hi,

This patch changes most trivial cases to use the new  (Lang)EnabledBy.

Bootstrapped and regression tested on x86_64-linux-gnu. OK?

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

	PR c/53063
	PR c/40989
c-family/
	* c.opt (Waddress,Wchar-subscripts,Wsign-conversion,Wimplicit,
	Wimplicit-function-declaration,Wimplicit-int,Wsizeof-pointer-memaccess,
	Wnarrowing,Wparentheses,Wpointer-sign,Wreturn-type,Wsequence-point,
	Wsign-compare,Wuninitialized,Wmaybe-uninitialized,Wunused,
	Wvolatile-register-var): Add LangEnabledBy or EnabledBy.
	* c-opts.c (c_common_handle_option): Remove explicit handling from
	here.
	(c_common_post_options): Likewise.
gcc/
	* opts.c (finish_options): Remove explicit handling from here.


Unfortunately, I cannot remove all Init(-1) because the real Init
value is conditional on the language or a more complex condition:

[...]
      if (!c_dialect_cxx ())
	{
	  /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
	     can turn it off only if it's not explicit.  */
	  if (warn_main == -1)
	    warn_main = (value ? 2 : 0);

	  /* In C, -Wall and -Wc++-compat turns on -Wenum-compare,
	     which we do here.  In C++ it is on by default, which is
	     done in c_common_post_options.  */
          if (warn_enum_compare == -1)
            warn_enum_compare = value;
	}
[...]
    case OPT_Wc___compat:
      /* Because -Wenum-compare is the default in C++, -Wc++-compat
	 implies -Wenum-compare.  */
      if (warn_enum_compare == -1 && value)
	warn_enum_compare = value;
      break;

[...]
   /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
      It is never enabled in C++, as the minimum limit is not normative
      in that standard.  */
   if (warn_overlength_strings == -1 || c_dialect_cxx ())
     warn_overlength_strings = 0;
  /* Wmain is enabled by default in C++ but not in C.  */
  /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
     even if -Wall was given (warn_main will be 2 if set by -Wall, 1
     if set by -Wmain).  */
  if (warn_main == -1)
    warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
  else if (warn_main == 2)
    warn_main = flag_hosted ? 1 : 0;

  /* -Wimplicit-function-declaration is enabled by default for C99.  */
  if (warn_implicit_function_declaration == -1)
    warn_implicit_function_declaration = flag_isoc99;

  if (cxx_dialect >= cxx0x)
    {
      /* If we're allowing C++0x constructs, don't warn about C++98
	 identifiers which are keywords in C++0x.  */
      warn_cxx0x_compat = 0;

      if (warn_narrowing == -1)
	warn_narrowing = 1;
    }
  else if (warn_narrowing == -1)
    warn_narrowing = 0;

Not sure how to encode these dependencies. Ideas?

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

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt	(revision 192515)
+++ gcc/c-family/c.opt	(working copy)
@@ -259,11 +259,11 @@ Warn about things that will change when 
 
 Wpsabi
 C ObjC C++ ObjC++ LTO Var(warn_psabi) Init(1) Undocumented
 
 Waddress
-C ObjC C++ ObjC++ Var(warn_address) Warning
+C ObjC C++ ObjC++ Var(warn_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn about suspicious uses of memory addresses
 
 Wall
 C ObjC C++ ObjC++ Warning
 Enable most warning messages
@@ -295,11 +295,11 @@ Warn about C++ constructs whose meaning 
 Wcast-qual
 C ObjC C++ ObjC++ Var(warn_cast_qual) Warning
 Warn about casts which discard qualifiers
 
 Wchar-subscripts
-C ObjC C++ ObjC++ Var(warn_char_subscripts) Warning
+C ObjC C++ ObjC++ Var(warn_char_subscripts) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn about subscripts whose type is \"char\"
 
 Wclobbered
 C ObjC C++ ObjC++ Var(warn_clobbered) Warning EnabledBy(Wextra)
 Warn about variables that might be changed by \"longjmp\" or \"vfork\"
@@ -318,14 +318,10 @@ Warn for implicit type conversions that 
 
 Wconversion-null
 C++ ObjC++ Var(warn_conversion_null) Init(1) Warning
 Warn for converting NULL from/to a non-pointer type
 
-Wsign-conversion
-C ObjC C++ ObjC++ Var(warn_sign_conversion) Init(-1)
-Warn for implicit type conversions between signed and unsigned integers
-
 Wctor-dtor-privacy
 C++ ObjC++ Var(warn_ctor_dtor_privacy) Warning
 Warn when all constructors and destructors are private
 
 Wdeclaration-after-statement
@@ -410,23 +406,23 @@ Warn whenever type qualifiers are ignore
 Winit-self
 C ObjC C++ ObjC++ Var(warn_init_self) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about variables which are initialized to themselves
 
 Wimplicit
-C ObjC Var(warn_implicit) Init(-1) Warning
+C ObjC Var(warn_implicit) Warning LangEnabledBy(C ObjC,Wall)
 Warn about implicit declarations
 
 Wdouble-promotion
 C ObjC C++ ObjC++ Var(warn_double_promotion) Warning
 Warn about implicit conversions from \"float\" to \"double\"
 
 Wimplicit-function-declaration
-C ObjC Var(warn_implicit_function_declaration) Init(-1) Warning
+C ObjC Var(warn_implicit_function_declaration) Init(-1) Warning LangEnabledBy(C ObjC,Wimplicit)
 Warn about implicit function declarations
 
 Wimplicit-int
-C ObjC Var(warn_implicit_int) Init(-1) Warning
+C ObjC Var(warn_implicit_int) Warning LangEnabledBy(C ObjC,Wimplicit)
 Warn when a declaration does not specify a type
 
 Wimport
 C ObjC C++ ObjC++ Undocumented Ignore
 
@@ -473,11 +469,11 @@ Warn about global functions without prev
 Wmissing-field-initializers
 C ObjC C++ ObjC++ Var(warn_missing_field_initializers) Warning EnabledBy(Wextra)
 Warn about missing fields in struct initializers
 
 Wsizeof-pointer-memaccess
-C ObjC C++ ObjC++ Var(warn_sizeof_pointer_memaccess) Warning
+C ObjC C++ ObjC++ Var(warn_sizeof_pointer_memaccess) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 
 Wsuggest-attribute=format
 C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
 Warn about functions which might be candidates for format attributes
 
@@ -504,13 +500,17 @@ Warn about constructs not instrumented b
 Wmultichar
 C ObjC C++ ObjC++ Warning
 Warn about use of multi-character character constants
 
 Wnarrowing
-C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(-1)
+C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(-1) LangEnabledBy(C++ ObjC++,Wall)
 Warn about narrowing conversions within { } that are ill-formed in C++11
 
+Wnarrowing
+C ObjC C++ ObjC++ LangEnabledBy(C++ ObjC++,Wc++0x-compat)
+;
+
 Wnested-externs
 C ObjC Var(warn_nested_externs) Warning
 Warn about \"extern\" declarations not at file scope
 
 Wnoexcept
@@ -560,11 +560,11 @@ Warn about overriding initializers witho
 Wpacked-bitfield-compat
 C ObjC C++ ObjC++ Var(warn_packed_bitfield_compat) Init(-1) Warning
 Warn about packed bit-fields whose offset changed in GCC 4.4
 
 Wparentheses
-C ObjC C++ ObjC++ Var(warn_parentheses) Warning
+C ObjC C++ ObjC++ Var(warn_parentheses) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn about possibly missing parentheses
 
 Wpedantic
 C ObjC C++ ObjC++ Warning
 ; Documented in common.opt
@@ -575,10 +575,18 @@ Warn when converting the type of pointer
 
 Wpointer-arith
 C ObjC C++ ObjC++ Var(warn_pointer_arith) Warning
 Warn about function pointer arithmetic
 
+Wpointer-sign
+C ObjC Var(warn_pointer_sign) Warning LangEnabledBy(C ObjC,Wall)
+Warn when a pointer differs in signedness in an assignment
+
+Wpointer-sign
+C ObjC LangEnabledBy(C ObjC,Wpedantic)
+;
+
 Wpointer-to-int-cast
 C ObjC Var(warn_pointer_to_int_cast) Init(1) Warning
 Warn when a pointer is cast to an integer of a different size
 
 Wpragmas
@@ -600,25 +608,33 @@ Warn about multiple declarations of the 
 Wreorder
 C++ ObjC++ Var(warn_reorder) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn when the compiler reorders code
 
 Wreturn-type
-C ObjC C++ ObjC++ Var(warn_return_type) Warning
+C ObjC C++ ObjC++ Var(warn_return_type) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn whenever a function's return type defaults to \"int\" (C), or about inconsistent return types (C++)
 
 Wselector
 ObjC ObjC++ Var(warn_selector) Warning
 Warn if a selector has multiple methods
 
 Wsequence-point
-C ObjC C++ ObjC++ Var(warn_sequence_point) Warning
+C ObjC C++ ObjC++ Var(warn_sequence_point) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn about possible violations of sequence point rules
 
 Wsign-compare
-C ObjC C++ ObjC++ Var(warn_sign_compare) Init(-1) Warning
+C ObjC C++ ObjC++ Var(warn_sign_compare) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about signed-unsigned comparisons
 
+Wsign-compare
+C ObjC C++ ObjC++ Var(warn_sign_compare) Warning EnabledBy(Wextra)
+;
+
+Wsign-conversion
+C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
+Warn for implicit type conversions between signed and unsigned integers
+
 Wsign-promo
 C++ ObjC++ Var(warn_sign_promo) Warning
 Warn when overload promotes from unsigned to signed
 
 Wstrict-null-sentinel
@@ -671,18 +687,30 @@ Warn about @selector()s without previous
 
 Wundef
 C ObjC C++ ObjC++ Warning
 Warn if an undefined macro is used in an #if directive
 
+Wuninitialized
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
+;
+
+Wmaybe-uninitialized
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
+;
+
 Wunknown-pragmas
 C ObjC C++ ObjC++ Warning
 Warn about unrecognized pragmas
 
 Wunsuffixed-float-constants
 C ObjC Var(warn_unsuffixed_float_constants) Warning
 Warn about unsuffixed float constants
 
+Wunused
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
+; documented in common.opt
+
 Wunused-local-typedefs
 C ObjC C++ ObjC++ Var(warn_unused_local_typedefs) Warning EnabledBy(Wunused)
 Warn when typedefs locally defined in a function are not used
 
 Wunused-macros
@@ -704,21 +732,17 @@ Warn about questionable usage of the mac
 Wvla
 C ObjC C++ ObjC++ Var(warn_vla) Init(-1) Warning
 Warn if a variable length array is used
 
 Wvolatile-register-var
-C ObjC C++ ObjC++ Var(warn_volatile_register_var) Warning
+C ObjC C++ ObjC++ Var(warn_volatile_register_var) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
 Warn when a register variable is declared volatile
 
 Wwrite-strings
 C ObjC C++ ObjC++ Var(warn_write_strings) Warning
 In C++, nonzero means warn about deprecated conversion from string literals to 'char *'.  In C, similar warning, except that the conversion is of course not deprecated by the ISO C standard.
 
-Wpointer-sign
-C ObjC Var(warn_pointer_sign) Init(-1) Warning
-Warn when a pointer differs in signedness in an assignment
-
 Wzero-as-null-pointer-constant
 C++ ObjC++ Var(warn_zero_as_null_pointer_constant) Warning
 Warn when a literal '0' is used as null pointer
 
 Wuseless-cast
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 192515)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -359,36 +359,18 @@ c_common_handle_option (size_t scode, co
       defer_opt (code, arg);
       break;
 
     case OPT_Wall:
       /* ??? 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;
-      warn_parentheses = value;
-      warn_return_type = value;
-      warn_sequence_point = value;	/* Was C only.  */
       warn_switch = value;
-      warn_sizeof_pointer_memaccess = value;
-      warn_address = value;
       warn_array_bounds = value;
-      warn_volatile_register_var = value;
 
       /* Only warn about unknown pragmas that are not in system
 	 headers.  */
       warn_unknown_pragmas = value;
 
-      warn_uninitialized = value;
-      warn_maybe_uninitialized = value;
-
       if (!c_dialect_cxx ())
 	{
 	  /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
 	     can turn it off only if it's not explicit.  */
 	  if (warn_main == -1)
@@ -398,23 +380,14 @@ c_common_handle_option (size_t scode, co
 	     which we do here.  In C++ it is on by default, which is
 	     done in c_common_post_options.  */
           if (warn_enum_compare == -1)
             warn_enum_compare = value;
 	}
-      else
-	{
-	  /* C++-specific warnings.  */
-          warn_sign_compare = value;
-	  warn_narrowing = value;
-	}
 
       cpp_opts->warn_trigraphs = value;
       cpp_opts->warn_comments = value;
       cpp_opts->warn_num_sign_change = value;
-
-      if (warn_pointer_sign == -1)
-	warn_pointer_sign = value;
       break;
 
     case OPT_Wbuiltin_macro_redefined:
       cpp_opts->warn_builtin_macro_redefined = value;
       break;
@@ -429,14 +402,10 @@ c_common_handle_option (size_t scode, co
       if (warn_enum_compare == -1 && value)
 	warn_enum_compare = value;
       cpp_opts->warn_cxx_operator_names = value;
       break;
 
-    case OPT_Wc__0x_compat:
-      warn_narrowing = value;
-      break;
-
     case OPT_Wdeprecated:
       cpp_opts->cpp_warn_deprecated = value;
       break;
 
     case OPT_Wendif_labels:
@@ -449,24 +418,10 @@ c_common_handle_option (size_t scode, co
 
     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,
-				 c_family_lang_mask, kind, loc, handlers,
-				 global_dc);
-      if (warn_implicit_function_declaration == -1)
-	handle_generated_option (&global_options, &global_options_set,
-				 OPT_Wimplicit_function_declaration, NULL,
-				 value, c_family_lang_mask, kind, loc,
-				 handlers, global_dc);
-      break;
-
     case OPT_Winvalid_pch:
       cpp_opts->warn_invalid_pch = value;
       break;
 
     case OPT_Wliteral_suffix:
@@ -732,12 +687,10 @@ c_common_handle_option (size_t scode, co
 	 c_common_post_options, so that a subsequent -Wno-endif-labels
 	 is not overridden.  */
     case OPT_Wpedantic:
       cpp_opts->cpp_pedantic = 1;
       cpp_opts->warn_endif_labels = 1;
-      if (warn_pointer_sign == -1)
-	warn_pointer_sign = 1;
       if (warn_overlength_strings == -1)
 	warn_overlength_strings = 1;
       if (warn_main == -1)
 	warn_main = 2;
       break;
@@ -922,22 +875,10 @@ c_common_post_options (const char **pfil
   if (flag_objc_sjlj_exceptions < 0)
     flag_objc_sjlj_exceptions = flag_next_runtime;
   if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
     flag_exceptions = 1;
 
-  /* -Wextra implies the following flags
-     unless explicitly overridden.  */
-
-  /* Wsign-compare is also enabled by -Wall in C++. */
-  if (warn_sign_compare == -1)
-    warn_sign_compare = extra_warnings;
-
-  /* -Wpointer-sign is disabled by default, but it is enabled if any
-     of -Wall or -Wpedantic are given.  */
-  if (warn_pointer_sign == -1)
-    warn_pointer_sign = 0;
-
   /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
      It is never enabled in C++, as the minimum limit is not normative
      in that standard.  */
   if (warn_overlength_strings == -1 || c_dialect_cxx ())
     warn_overlength_strings = 0;
@@ -949,16 +890,10 @@ c_common_post_options (const char **pfil
   if (warn_main == -1)
     warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
   else if (warn_main == 2)
     warn_main = flag_hosted ? 1 : 0;
 
-  /* In C, -Wconversion enables -Wsign-conversion (unless disabled
-     through -Wno-sign-conversion). While in C++,
-     -Wsign-conversion needs to be requested explicitly.  */
-  if (warn_sign_conversion == -1)
-    warn_sign_conversion =  (c_dialect_cxx ()) ? 0 : warn_conversion;
-
   /* In C, -Wall and -Wc++-compat enable -Wenum-compare, which we do
      in c_common_handle_option; if it has not yet been set, it is
      disabled by default.  In C++, it is enabled by default.  */
   if (warn_enum_compare == -1)
     warn_enum_compare = c_dialect_cxx () ? 1 : 0;
@@ -985,16 +920,10 @@ c_common_post_options (const char **pfil
 	       "-Wformat-contains-nul ignored without -Wformat");
       warning (OPT_Wformat_security,
 	       "-Wformat-security ignored without -Wformat");
     }
 
-  if (warn_implicit == -1)
-    warn_implicit = 0;
-      
-  if (warn_implicit_int == -1)
-    warn_implicit_int = 0;
-
   /* -Wimplicit-function-declaration is enabled by default for C99.  */
   if (warn_implicit_function_declaration == -1)
     warn_implicit_function_declaration = flag_isoc99;
 
   if (cxx_dialect >= cxx0x)
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 192515)
+++ gcc/opts.c	(working copy)
@@ -827,14 +827,10 @@ finish_options (struct gcc_options *opts
      is disabled.  */
   if (!opts->x_flag_tree_vectorize || !opts->x_flag_tree_loop_if_convert)
     maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
                            opts->x_param_values, opts_set->x_param_values);
 
-  /* This replaces set_Wunused.  */
-  /* Wunused-local-typedefs is enabled by -Wunused or -Wall.  */
-  if (opts->x_warn_unused_local_typedefs == -1)
-    opts->x_warn_unused_local_typedefs = opts->x_warn_unused;
 }
 
 #define LEFT_COLUMN	27
 
 /* Output ITEM, of length ITEM_WIDTH, in the left column,

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

* Re: PR c/53063 Use (Lang)EnabledBy for a bunch of options
  2012-10-17 17:29 PR c/53063 Use (Lang)EnabledBy for a bunch of options Manuel López-Ibáñez
@ 2012-10-19 16:10 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2012-10-19 16:10 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="X-UNKNOWN", Size: 1521 bytes --]

On Wed, 17 Oct 2012, Manuel López-Ibáñez wrote:

> This patch changes most trivial cases to use the new  (Lang)EnabledBy.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu. OK?
> 
> 2012-10-17  Manuel López-Ibáñez  <manu@gcc.gnu.org>
> 
> 	PR c/53063
> 	PR c/40989
> c-family/
> 	* c.opt (Waddress,Wchar-subscripts,Wsign-conversion,Wimplicit,
> 	Wimplicit-function-declaration,Wimplicit-int,Wsizeof-pointer-memaccess,
> 	Wnarrowing,Wparentheses,Wpointer-sign,Wreturn-type,Wsequence-point,
> 	Wsign-compare,Wuninitialized,Wmaybe-uninitialized,Wunused,
> 	Wvolatile-register-var): Add LangEnabledBy or EnabledBy.
> 	* c-opts.c (c_common_handle_option): Remove explicit handling from
> 	here.
> 	(c_common_post_options): Likewise.
> gcc/
> 	* opts.c (finish_options): Remove explicit handling from here.

OK.

> Not sure how to encode these dependencies. Ideas?

No specific suggestions here.  If a particular case isn't common enough to 
have a .opt mechanism for it, then in principle the use of the _set 
structures tracking what was explicitly set could replace the use of -1 
initializers.  But since the _set structures generally correspond to what 
was set directly, whereas implicit setting by another option also replaces 
the -1 value, this might only work given the extension of _set structures 
to record the distance between the option passed by the user and the one 
set, not just whether each option was set directly.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2012-10-19 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-17 17:29 PR c/53063 Use (Lang)EnabledBy for a bunch of options Manuel López-Ibáñez
2012-10-19 16:10 ` 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).