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: check for enabled warnings


> 2. Write the code to do something with those non-zero values.

Here it is:

	* 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.c: Include opts.h.
	(warning): Check to see if the specified warning is enabled.

An example of how to use the warning flag would be like this:
 
-  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);

Note that we pass the OPT_* value and not the variable; this allows us
to later specify boolean options that don't have a variable, and also
supports existing options that set a bit in the variable rather than
set the whole variable.

Yes, I know the argument about performance.  One solution to that is
to have a group-type warning that is checked first, and specific
warning options for each message, which is the case that this project
adds which we couldn't do before anyway.  The example is just an
example; using it efficiently and usefully is an exercise left to the
programmer ;-) Note that the use of CLVC_BIT_SET allows you to test a
group of options with one comparison, with a little work to support
bits outside of target_flags.

Another option is to allow a set of -Wno-foo-* to correspond to a
single -Wfoo when you have a class of warnings, some members of which
you may want to individually disable without being able to
individually enable.

A possible future extension is to allow -Wno-foo-program-c to disable
warning "foo" in file "program.c", or to use #pragmas to invoke -W*
options.  This step, at least, allows us to start replacing those
zeros with meaningful values now.


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	25 Apr 2005 21:26:45 -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.  */
@@ -412,11 +413,14 @@ 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);
   report_diagnostic (&diagnostic);
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.104
diff -p -U3 -r1.104 opts.c
--- opts.c	23 Apr 2005 21:27:47 -0000	1.104
+++ opts.c	25 Apr 2005 21:26:45 -0000
@@ -1391,8 +1391,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	25 Apr 2005 21:26:45 -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.952
diff -p -U3 -r1.952 toplev.c
--- toplev.c	24 Apr 2005 22:11:49 -0000	1.952
+++ toplev.c	25 Apr 2005 21:26:48 -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]