This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

warning message control: jumbo patch so far


This patch is the so-far for all my pending warning control patches:

* Lets warning() itself decide if the warning is printed.
* Amends each warning with the option which controls it.

Tested with a c/bootstrap/bubblestrap but I have a full bootstrap
running just in case.

I include three conversions of calls to warning() just so that the
functionality can be demonstrated; they're not intended to be
exhaustive but IMHO they could be approved as-is anyway.

See http://gcc.gnu.org/wiki/Warning%20Message%20Control

If this is approved, the remaining items for this project are:

* Convert all callers of warning() to pass the (or a new) option.
* [optional] Add limited #pragma support for invoking these options.
* [optional] Add individual control of the type of diagnostic (warn vs error).


$ ./cc1 -quiet -Wold-style-definition -Waggregate-return -Wuninitialized -fdiagnostics-show-option -O1 dj.c
dj.c: In function 'foo':
dj.c:6: warning: function returns an aggregate [-Waggregate-return]
dj.c:8: warning: 'a.b' is used uninitialized in this function
dj.c: In function 'bar':
dj.c:14: warning: old-style function definition [-Wold-style-definition]


2005-05-02  DJ Delorie  <dj@redhat.com>

	* c-decl.c (store_parm_decls_oldstyle): Let diagnostic machinery
	decide if the warning will be printed.
	* calls.c (expand_call): Likewise.
	* function.c (init-function_start): Likewise.

	* common.opt (-fdiagnostics-show-option): New.
	* opts.c (option_enabled): Accept the option index instead of a
	pointer to the option descriptor.
	* opts.h (option_enabled): Likewise.
	* toplev.c (print_switch_values): Pass option index, not option
	descriptor.
	* diagnostic.h (diagnostic_info): Add option_index.
	* diagnostic.c: Include opts.h.
	(diagnostic_set_info): Initialize option_index.
	(diagnostic_report_diagnostic): Amend option name if appropriate.
	(warning): Check to see if the specified warning is enabled.
	Store option index.
	* doc/invoke.texi (-fdiagnostics-show-options): Document.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.650
diff -p -U3 -r1.650  c-decl.c
--- c-decl.c	27 Apr 2005 00:46:51 -0000	1.650
+++ c-decl.c	2 May 2005 20:39:03 -0000
@@ -5950,8 +5950,8 @@ store_parm_decls_oldstyle (tree fndecl, 
     gcc_assert (TREE_CODE (b->decl) != PARM_DECL || !DECL_WEAK (b->decl));
 #endif
 
-  if (warn_old_style_definition && !in_system_header)
-    warning (0, "%Jold-style function definition", fndecl);
+  if (!in_system_header)
+    warning (OPT_Wold_style_definition, "%Jold-style function definition", fndecl);
 
   /* Match each formal parameter name with its declaration.  Save each
      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
Index: calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.386
diff -p -U3 -r1.386  calls.c
--- calls.c	23 Apr 2005 21:27:36 -0000	1.386
+++ calls.c	2 May 2005 20:39:05 -0000
@@ -1934,8 +1934,8 @@ expand_call (tree exp, rtx target, int i
 
   /* Warn if this value is an aggregate type,
      regardless of which calling convention we are using for it.  */
-  if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
-    warning (0, "function call has aggregate value");
+  if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
+    warning (OPT_Waggregate_return, "function call has aggregate value");
 
   /* If the result of a pure or const function call is ignored (or void),
      and none of its arguments are volatile, we can avoid expanding the
Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.68
diff -p -U3 -r1.68  common.opt
--- common.opt	9 Apr 2005 01:37:21 -0000	1.68
+++ common.opt	2 May 2005 20:39:05 -0000
@@ -336,6 +336,10 @@ fdiagnostics-show-location=
 Common Joined RejectNegative
 -fdiagnostics-show-location=[once|every-line]	How often to emit source location at the beginning of line-wrapped diagnostics
 
+fdiagnostics-show-option
+Common Var(diagnostics_show_options)
+Amend appropriate diagnostic messages with the command line option that controls them.
+
 fdump-
 Common Joined RejectNegative
 -fdump-<type>	Dump various compiler internals to a file
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.c,v
retrieving revision 1.149
diff -p -U3 -r1.149  diagnostic.c
--- diagnostic.c	23 Apr 2005 21:27:38 -0000	1.149
+++ diagnostic.c	2 May 2005 20:39:05 -0000
@@ -40,6 +40,7 @@ Software Foundation, 59 Temple Place - S
 #include "diagnostic.h"
 #include "langhooks.h"
 #include "langhooks-def.h"
+#include "opts.h"
 
 
 /* Prototypes.  */
@@ -120,6 +121,7 @@ diagnostic_set_info (diagnostic_info *di
   diagnostic->message.format_spec = _(msgid);
   diagnostic->location = location;
   diagnostic->kind = kind;
+  diagnostic->option_index = 0;
 }
 
 /* Return a malloc'd string describing a location.  The caller is
@@ -333,6 +335,11 @@ diagnostic_report_diagnostic (diagnostic
 
   if (diagnostic_count_diagnostic (context, diagnostic))
     {
+      if (diagnostics_show_options && diagnostic->option_index)
+	diagnostic->message.format_spec
+	  = ACONCAT ((diagnostic->message.format_spec,
+		      " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
+
       pp_prepare_to_format (context->printer, &diagnostic->message,
 			    &diagnostic->location);
       (*diagnostic_starter (context)) (context, diagnostic);
@@ -412,13 +419,18 @@ inform (const char *msgid, ...)
 /* A warning.  Use this for code which is correct according to the
    relevant language specification but is likely to be buggy anyway.  */
 void
-warning (int opt ATTRIBUTE_UNUSED, const char *msgid, ...)
+warning (int opt, const char *msgid, ...)
 {
   diagnostic_info diagnostic;
   va_list ap;
 
+  if (opt && ! option_enabled (opt))
+    return;
+
   va_start (ap, msgid);
   diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_WARNING);
+  diagnostic.option_index = opt;
+
   report_diagnostic (&diagnostic);
   va_end (ap);
 }
Index: diagnostic.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.h,v
retrieving revision 1.72
diff -p -U3 -r1.72  diagnostic.h
--- diagnostic.h	8 Mar 2005 12:48:53 -0000	1.72
+++ diagnostic.h	2 May 2005 20:39:05 -0000
@@ -43,6 +43,8 @@ typedef struct
   location_t location;
   /* The kind of diagnostic it is about.  */
   diagnostic_t kind;
+  /* Which OPT_* directly controls this diagnostic.  */
+  int option_index;
 } diagnostic_info;
 
 #define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.614
diff -p -U3 -r1.614  function.c
--- function.c	28 Apr 2005 05:03:05 -0000	1.614
+++ function.c	2 May 2005 20:39:06 -0000
@@ -4017,9 +4017,8 @@ init_function_start (tree subr)
 
   /* Warn if this value is an aggregate type,
      regardless of which calling convention we are using for it.  */
-  if (warn_aggregate_return
-      && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
-    warning (0, "function returns an aggregate");
+  if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
+    warning (OPT_Waggregate_return, "function returns an aggregate");
 }
 
 /* Make sure all values used by the optimization passes have sane
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.105
diff -p -U3 -r1.105  opts.c
--- opts.c	27 Apr 2005 21:35:19 -0000	1.105
+++ opts.c	2 May 2005 20:39:06 -0000
@@ -1400,8 +1400,9 @@ wrap_help (const char *help, const char 
    a simple on-off switch.  */
 
 int
-option_enabled (const struct cl_option *option)
+option_enabled (int opt_idx)
 {
+  const struct cl_option *option = &(cl_options[opt_idx]);
   if (option->flag_var)
     switch (option->var_cond)
       {
Index: opts.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.h,v
retrieving revision 1.20
diff -p -U3 -r1.20  opts.h
--- opts.h	18 Mar 2005 15:24:19 -0000	1.20
+++ opts.h	2 May 2005 20:39:06 -0000
@@ -71,7 +71,7 @@ extern const char **in_fnames;
 extern unsigned num_in_fnames;
 
 extern void decode_options (unsigned int argc, const char **argv);
-extern int option_enabled (const struct cl_option *);
+extern int option_enabled (int opt_idx);
 extern void print_filtered_help (unsigned int);
 
 #endif
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.953
diff -p -U3 -r1.953  toplev.c
--- toplev.c	26 Apr 2005 00:23:54 -0000	1.953
+++ toplev.c	2 May 2005 20:39:06 -0000
@@ -1360,7 +1360,7 @@ print_switch_values (FILE *file, int pos
 
   for (j = 0; j < cl_options_count; j++)
     if ((cl_options[j].flags & CL_REPORT)
-	&& option_enabled (&cl_options[j]) > 0)
+	&& option_enabled (j) > 0)
       pos = print_single_switch (file, pos, max, indent, sep, term,
 				 "", cl_options[j].opt_text);
 
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.610
diff -p -U3 -r1.610  doc/invoke.texi
--- doc/invoke.texi	25 Apr 2005 14:42:29 -0000	1.610
+++ doc/invoke.texi	2 May 2005 20:39:10 -0000
@@ -206,7 +206,8 @@ Objective-C and Objective-C++ Dialects}.
 @item Language Independent Options
 @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
 @gccoptlist{-fmessage-length=@var{n}  @gol
--fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]}}
+-fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]}} @gol
+-fdiagnostics-show-options
 
 @item Warning Options
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
@@ -2082,6 +2083,13 @@ messages reporter to emit the same sourc
 prefix) for physical lines that result from the process of breaking
 a message which is too long to fit on a single line.
 
+@item -fdiagnostics-show-options
+@opindex fdiagnostics-show-options
+This option instructs the diagnostic machinery to add text to each
+diagnostic emitted, which indicates which command line option directly
+controls that diagnostic, when such an option is known to the
+diagnostic machinery.
+
 @end table
 
 @node Warning Options


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]