[warnings] attribs.c

DJ Delorie dj@redhat.com
Thu May 12 21:07:00 GMT 2005


> If all that is changed in a particular case is that control of a
> warning is moved from an "if" condition to an argument to "warning",
> and there is already a test for that warning option, then new tests
> shouldn't be needed.  If the control is changed for a warning option
> with no tests at all then I think a testcase should be added (which
> passes before and after the patch, to demonstrate the patch hasn't
> broken that option).

Here's a patch that converts all the simplest cases of "if (warn...)
warning()".  The options involved, and whether the testsuite already
tests them, are listed.  Let me know if this is "basically right" and
I'll do the full testsuite/bootstrap/regression/changelog cycle (even
with an amd64, it still takes a long time, I'd rather not do it twice
;).

X	OPT_Wconversion
N	OPT_Wdisabled_optimization
N	OPT_Wdiv_by_zero
N	OPT_Wfloat_equal
Y	OPT_Wformat_extra_args
X	OPT_Wformat_nonliteral
X	OPT_Wformat_security
X	OPT_Wformat_y2k
Y	OPT_Wformat_zero_length
Y	OPT_Wmissing_format_attribute
X	OPT_Wpadded
X	OPT_Wparentheses
X	OPT_Wreturn_type
X	OPT_Wshadow
X	OPT_Wswitch_default
X	OPT_Wtraditional
X	OPT_Wuninitialized
X	OPT_Wunknown_pragmas
X	OPT_Wunreachable_code

N=not mentioned, Y=mentioned, X=explicitly tested

Note that I didn't see any tests that explicitly tested -Wfoo,
-Wno-foo, and default for any -Wfoo.  I didn't look *that* hard
either, though.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.627
diff -p -U3 -r1.627 c-common.c
--- c-common.c	2 May 2005 16:02:10 -0000	1.627
+++ c-common.c	12 May 2005 20:08:58 -0000
@@ -957,8 +957,8 @@ unsigned_conversion_warning (tree result
       if (!int_fits_type_p (operand, c_common_signed_type (type)))
 	/* This detects cases like converting -129 or 256 to unsigned char.  */
 	warning (0, "large integer implicitly truncated to unsigned type");
-      else if (warn_conversion)
-	warning (0, "negative integer implicitly converted to unsigned type");
+      else
+	warning (OPT_Wconversion, "negative integer implicitly converted to unsigned type");
     }
 }
 
@@ -2482,8 +2482,8 @@ c_common_truthvalue_conversion (tree exp
       break;
 
     case MODIFY_EXPR:
-      if (warn_parentheses && !TREE_NO_WARNING (expr))
-	warning (0, "suggest parentheses around assignment used as truth value");
+      if (!TREE_NO_WARNING (expr))
+	warning (OPT_Wparentheses, "suggest parentheses around assignment used as truth value");
       break;
 
     default:
@@ -3737,8 +3737,8 @@ c_do_switch_warnings (splay_tree cases, 
     return;
 
   default_node = splay_tree_lookup (cases, (splay_tree_key) NULL);
-  if (warn_switch_default && !default_node)
-    warning (0, "%Hswitch missing default case", &switch_location);
+  if (!default_node)
+    warning (OPT_Wswitch_default, "%Hswitch missing default case", &switch_location);
 
   /* If the switch expression was an enumerated type, check that
      exactly all enumeration literals are covered by the cases.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.654
diff -p -U3 -r1.654 c-decl.c
--- c-decl.c	11 May 2005 07:33:30 -0000	1.654
+++ c-decl.c	12 May 2005 20:09:00 -0000
@@ -1162,8 +1162,8 @@ diagnose_mismatched_decls (tree newdecl,
       else if (TREE_PUBLIC (newdecl))
 	warning (0, "%Jbuilt-in function %qD declared as non-function",
 		 newdecl, newdecl);
-      else if (warn_shadow)
-	warning (0, "%Jdeclaration of %qD shadows a built-in function",
+      else
+	warning (OPT_Wshadow, "%Jdeclaration of %qD shadows a built-in function",
 		 newdecl, newdecl);
       return false;
     }
@@ -1278,9 +1278,8 @@ diagnose_mismatched_decls (tree newdecl,
 	      || (DECL_INITIAL (newdecl)
 		  && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
 	{
-	  if (warn_shadow)
-	    warning (0, "%Jdeclaration of %qD shadows a built-in function",
-		     newdecl, newdecl);
+	  warning (OPT_Wshadow, "%Jdeclaration of %qD shadows a built-in function",
+		   newdecl, newdecl);
 	  /* Discard the old built-in function.  */
 	  return false;
 	}
@@ -2551,8 +2550,8 @@ define_label (location_t location, tree 
 	    /*invisible=*/false, /*nested=*/false);
     }
 
-  if (warn_traditional && !in_system_header && lookup_name (name))
-    warning (0, "%Htraditional C lacks a separate namespace for labels, "
+  if (!in_system_header && lookup_name (name))
+    warning (Wtraditional, "%Htraditional C lacks a separate namespace for labels, "
              "identifier %qE conflicts", &location, name);
 
   nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
@@ -4279,8 +4278,8 @@ grokdeclarator (const struct c_declarato
 		   them for noreturn functions.  */
 		if (VOID_TYPE_P (type) && really_funcdef)
 		  pedwarn ("function definition has qualified void return type");
-		else if (warn_return_type)
-		  warning (0, "type qualifiers ignored on function return type");
+		else
+		  warning (OPT_Wreturn_type, "type qualifiers ignored on function return type");
 		
 		type = c_build_qualified_type (type, type_quals);
 	      }
Index: c-format.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-format.c,v
retrieving revision 1.74
diff -p -U3 -r1.74 c-format.c
--- c-format.c	26 Apr 2005 23:57:55 -0000	1.74
+++ c-format.c	12 May 2005 20:09:00 -0000
@@ -1140,8 +1140,8 @@ check_format_info (function_format_info 
 	{
 	  /* For strftime-like formats, warn for not checking the format
 	     string; but there are no arguments to check.  */
-	  if (warn_format_nonliteral)
-	    warning (0, "format not a string literal, format string not checked");
+	  warning (OPT_Wformat_nonliteral,
+		   "format not a string literal, format string not checked");
 	}
       else if (info->first_arg_num != 0)
 	{
@@ -1154,10 +1154,13 @@ check_format_info (function_format_info 
 	      params = TREE_CHAIN (params);
 	      ++arg_num;
 	    }
-	  if (params == 0 && (warn_format_nonliteral || warn_format_security))
-	    warning (0, "format not a string literal and no format arguments");
-	  else if (warn_format_nonliteral)
-	    warning (0, "format not a string literal, argument types not checked");
+	  if (params == 0 && warn_format_security)
+	    warning (OPT_Wformat_security, "format not a string literal and no format arguments");
+	  if (params == 0 && warn_format_nonliteral)
+	    warning (OPT_Wformat_nonliteral, "format not a string literal and no format arguments");
+	  else
+	    warning (OPT_Wformat_nonliteral,
+		     "format not a string literal, argument types not checked");
 	}
     }
 
Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.247
diff -p -U3 -r1.247 c-lex.c
--- c-lex.c	23 Apr 2005 21:27:31 -0000	1.247
+++ c-lex.c	12 May 2005 20:09:00 -0000
@@ -599,8 +599,9 @@ interpret_integer (const cpp_token *toke
 		  itk = itk_u;
 		  warning (0, "this decimal constant is unsigned only in ISO C90");
 		}
-	      else if (warn_traditional)
-		warning (0, "this decimal constant would be unsigned in ISO C90");
+	      else
+		warning (OPT_Wtraditional,
+			 "this decimal constant would be unsigned in ISO C90");
 	    }
 	}
     }
@@ -763,8 +764,9 @@ lex_string (const cpp_token *tok, tree *
   if (concats)
     strs = (cpp_string *) obstack_finish (&str_ob);
 
-  if (concats && !objc_string && warn_traditional && !in_system_header)
-    warning (0, "traditional C rejects string constant concatenation");
+  if (concats && !objc_string && !in_system_header)
+    warning (OPT_Wtraditional,
+	     "traditional C rejects string constant concatenation");
 
   if ((c_lex_string_translate
        ? cpp_interpret_string : cpp_interpret_string_notranslate)
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.143
diff -p -U3 -r1.143 c-opts.c
--- c-opts.c	2 May 2005 04:21:56 -0000	1.143
+++ c-opts.c	12 May 2005 20:09:00 -0000
@@ -982,18 +982,21 @@ c_common_post_options (const char **pfil
 
   /* Special format checking options don't work without -Wformat; warn if
      they are used.  */
-  if (warn_format_y2k && !warn_format)
-    warning (0, "-Wformat-y2k ignored without -Wformat");
-  if (warn_format_extra_args && !warn_format)
-    warning (0, "-Wformat-extra-args ignored without -Wformat");
-  if (warn_format_zero_length && !warn_format)
-    warning (0, "-Wformat-zero-length ignored without -Wformat");
-  if (warn_format_nonliteral && !warn_format)
-    warning (0, "-Wformat-nonliteral ignored without -Wformat");
-  if (warn_format_security && !warn_format)
-    warning (0, "-Wformat-security ignored without -Wformat");
-  if (warn_missing_format_attribute && !warn_format)
-    warning (0, "-Wmissing-format-attribute ignored without -Wformat");
+  if (!warn_format)
+    {
+      warning (OPT_Wformat_y2k,
+	       "-Wformat-y2k ignored without -Wformat");
+      warning (OPT_Wformat_extra_args,
+	       "-Wformat-extra-args ignored without -Wformat");
+      warning (OPT_Wformat_zero_length,
+	       "-Wformat-zero-length ignored without -Wformat");
+      warning (OPT_Wformat_nonliteral,
+	       "-Wformat-nonliteral ignored without -Wformat");
+      warning (OPT_Wformat_security,
+	       "-Wformat-security ignored without -Wformat");
+      warning (OPT_Wmissing_format_attribute,
+	       "-Wmissing-format-attribute ignored without -Wformat");
+    }
 
   /* C99 requires special handling of complex multiplication and division;
      -ffast-math and -fcx-limited-range are handled in process_options.  */
Index: c-parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parser.c,v
retrieving revision 2.13
diff -p -U3 -r2.13 c-parser.c
--- c-parser.c	9 May 2005 20:48:33 -0000	2.13
+++ c-parser.c	12 May 2005 20:09:01 -0000
@@ -4518,8 +4518,8 @@ c_parser_unary_expression (c_parser *par
       return ret;
     case CPP_PLUS:
       c_parser_consume_token (parser);
-      if (!c_dialect_objc () && warn_traditional && !in_system_header)
-	warning (0, "traditional C rejects the unary plus operator");
+      if (!c_dialect_objc () && !in_system_header)
+	warning (OPT_Wtraditional, "traditional C rejects the unary plus operator");
       return parser_build_unary_op (CONVERT_EXPR,
 				    c_parser_cast_expression (parser, NULL));
     case CPP_MINUS:
Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.84
diff -p -U3 -r1.84 c-pragma.c
--- c-pragma.c	28 Apr 2005 05:38:30 -0000	1.84
+++ c-pragma.c	12 May 2005 20:09:01 -0000
@@ -418,7 +418,7 @@ handle_pragma_redefine_extname (cpp_read
   if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
     {
       if (warn_unknown_pragmas > in_system_header)
-	warning (0, "#pragma redefine_extname not supported on this target");
+	warning (OPT_Wunknown_pragmas, "#pragma redefine_extname not supported on this target");
       return;
     }
 
@@ -486,7 +486,7 @@ handle_pragma_extern_prefix (cpp_reader 
     /* Note that the length includes the null terminator.  */
     pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
   else if (warn_unknown_pragmas > in_system_header)
-    warning (0, "#pragma extern_prefix not supported on this target");
+    warning (OPT_Wunknown_pragmas, "#pragma extern_prefix not supported on this target");
 }
 
 /* Hook from the front ends to apply the results of one of the preceding
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.441
diff -p -U3 -r1.441 c-typeck.c
--- c-typeck.c	10 May 2005 13:46:38 -0000	1.441
+++ c-typeck.c	12 May 2005 20:09:02 -0000
@@ -7475,8 +7475,8 @@ build_binary_op (enum tree_code code, tr
     case EXACT_DIV_EXPR:
       /* Floating point division by zero is a legitimate way to obtain
 	 infinities and NaNs.  */
-      if (warn_div_by_zero && skip_evaluation == 0 && integer_zerop (op1))
-	warning (0, "division by zero");
+      if (skip_evaluation == 0 && integer_zerop (op1))
+	warning (OPT_Wdiv_by_zero, "division by zero");
 
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
 	   || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
@@ -7514,8 +7514,8 @@ build_binary_op (enum tree_code code, tr
 
     case TRUNC_MOD_EXPR:
     case FLOOR_MOD_EXPR:
-      if (warn_div_by_zero && skip_evaluation == 0 && integer_zerop (op1))
-	warning (0, "division by zero");
+      if (skip_evaluation == 0 && integer_zerop (op1))
+	warning (OPT_Wdiv_by_zero, "division by zero");
 
       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
 	{
@@ -7607,8 +7607,8 @@ build_binary_op (enum tree_code code, tr
 
     case EQ_EXPR:
     case NE_EXPR:
-      if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
-	warning (0, "comparing floating point with == or != is unsafe");
+      if (code0 == REAL_TYPE || code1 == REAL_TYPE)
+	warning (OPT_Wfloat_equal, "comparing floating point with == or != is unsafe");
       /* Result of comparison is always int,
 	 but don't convert the args to int!  */
       build_type = integer_type_node;
Index: gcse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcse.c,v
retrieving revision 1.341
diff -p -U3 -r1.341 gcse.c
--- gcse.c	9 May 2005 17:52:16 -0000	1.341
+++ gcse.c	12 May 2005 20:09:02 -0000
@@ -6529,9 +6529,9 @@ is_too_expensive (const char *pass)
      graceful degradation.  */
   if (n_edges > 20000 + n_basic_blocks * 4)
     {
-      if (warn_disabled_optimization)
-	warning (0, "%s: %d basic blocks and %d edges/basic block",
-		 pass, n_basic_blocks, n_edges / n_basic_blocks);
+      warning (OPT_Wdisabled_optimization,
+	       "%s: %d basic blocks and %d edges/basic block",
+	       pass, n_basic_blocks, n_edges / n_basic_blocks);
 
       return true;
     }
@@ -6542,9 +6542,9 @@ is_too_expensive (const char *pass)
        * SBITMAP_SET_SIZE (max_reg_num ())
        * sizeof (SBITMAP_ELT_TYPE)) > MAX_GCSE_MEMORY)
     {
-      if (warn_disabled_optimization)
-	warning (0, "%s: %d basic blocks and %d registers",
-		 pass, n_basic_blocks, max_reg_num ());
+      warning (OPT_Wdisabled_optimization,
+	       "%s: %d basic blocks and %d registers",
+	       pass, n_basic_blocks, max_reg_num ());
 
       return true;
     }
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.107
diff -p -U3 -r1.107 opts.c
--- opts.c	4 May 2005 01:36:13 -0000	1.107
+++ opts.c	12 May 2005 20:09:02 -0000
@@ -659,8 +659,8 @@ decode_options (unsigned int argc, const
       /* The c_decode_option function and decode_option hook set
 	 this to `2' if -Wall is used, so we can avoid giving out
 	 lots of errors for people who don't realize what -Wall does.  */
-      if (warn_uninitialized == 1)
-	warning (0, "-Wuninitialized is not supported without -O");
+      warning (OPT_Wuninitialized,
+	       "-Wuninitialized is not supported without -O");
     }
 
   if (flag_really_no_inline == 2)
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.231
diff -p -U3 -r1.231 stor-layout.c
--- stor-layout.c	11 May 2005 12:24:43 -0000	1.231
+++ stor-layout.c	12 May 2005 20:09:03 -0000
@@ -869,8 +869,7 @@ place_field (record_layout_info rli, tre
       /* No, we need to skip space before this field.
 	 Bump the cumulative size to multiple of field alignment.  */
 
-      if (warn_padded)
-	warning (0, "%Jpadding struct to align %qD", field, field);
+      warning (OPT_Wpadded, "%Jpadding struct to align %qD", field, field);
 
       /* If the alignment is still within offset_align, just align
 	 the bit position.  */
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.185
diff -p -U3 -r2.185 tree-cfg.c
--- tree-cfg.c	10 May 2005 22:33:27 -0000	2.185
+++ tree-cfg.c	12 May 2005 20:09:04 -0000
@@ -2000,11 +2000,11 @@ remove_bb (basic_block bb)
      loop above, so the last statement we process is the first statement
      in the block.  */
 #ifdef USE_MAPPED_LOCATION
-  if (warn_notreached && loc > BUILTINS_LOCATION)
-    warning (0, "%Hwill never be executed", &loc);
+  if (loc > BUILTINS_LOCATION)
+    warning (OPT_Wunreachable_code, "%Hwill never be executed", &loc);
 #else
-  if (warn_notreached && loc)
-    warning (0, "%Hwill never be executed", loc);
+  if (loc)
+    warning (OPT_Wunreachable_code, "%Hwill never be executed", loc);
 #endif
 
   remove_phi_nodes_and_edges_for_unreachable_block (bb);



More information about the Gcc-patches mailing list