This is the mail archive of the gcc@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]

Re: named warnings & individual warning control


> Looks plausible to me, except that I think you should be using a 
> logarithmic method to find the matching string, not a linear method.

Attached.  opts.c has a find_opt() but (1) it's static, and (2) it's
too subtle for our purposes.  I copied the little bit of binary search
and adapted it.

> >Also, -O[23] tends to confuse this as they defer the use of warning
> >flags until after the whole file is parsed, so pragmas between
> >function definitions don't do what you expect :-(
>
> I'm not sure what to say about the problem in the last paragraph; that's 
> clearly a serious user interface issue.  This is part of why I have long 
> argued that only front ends should be permitted to issue warnings, and 
> that all attempts to use back-end data flow analysis to issue warnings 
> are mistaken, no matter how clever they seem.

Barring huge changes in the design of the internals of gcc, I'm happy
with documenting that such pragmas should come before any functions in
the source or else they may not apply.  That's in line with the "the
user shouldn't be doing this unless they absolutely have to" theory.

Index: c-pragma.c
===================================================================
RCS file: /greed/dj/gnu/gcc/repository/gcc/gcc/c-pragma.c,v
retrieving revision 1.71
diff -p -C2 -r1.71 c-pragma.c
*** c-pragma.c	22 Jun 2004 06:51:50 -0000	1.71
--- c-pragma.c	25 Jun 2004 18:19:18 -0000
*************** Software Foundation, 59 Temple Place - S
*** 36,39 ****
--- 36,40 ----
  #include "tm_p.h"
  #include "target.h"
+ #include "opts.h"
  
  #define GCC_BAD(msgid) do { warning (msgid); return; } while (0)
*************** c_register_pragma (const char *space, co
*** 576,579 ****
--- 577,648 ----
  }
  
+ static void
+ handle_pragma_gcc_warning (cpp_reader *dummy ATTRIBUTE_UNUSED)
+ {
+   tree type, x;
+   const char *ts;
+   char *ent;
+   int len, flag_val, comp;
+   unsigned int i, mn, mx, md;
+   static int list_printed = 0;
+ 
+   if (c_lex (&type) != CPP_STRING)
+     {
+       warning ("malformed #pragma GCC warning, ignored");
+       return;
+     }
+   ts = TREE_STRING_POINTER (type);
+   if (c_lex (&x) != CPP_EOF)
+     warning ("junk at end of #pragma GCC warning");
+ 
+   len = strlen (ts);
+   ent = (char *) xmalloc (len + 3);
+   ent[0] = '-';
+   ent[1] = 'W';
+   if (strncmp (ts, "no-", 3) == 0)
+     {
+       flag_val = 0;
+       strcpy (ent+2, ts+3);
+     }
+   else
+     {
+       flag_val = 1;
+       strcpy (ent+2, ts);
+     }
+ 
+ 
+   mn = 0;
+   mx = cl_options_count;
+   while (mx - mn > 1)
+     {
+       md = (mn + mx) / 2;
+       comp = strcmp (ent, cl_options[md].opt_text);
+ 
+       if (cl_options[md].flag_var
+ 	  && comp == 0)
+ 	{
+ 	  *cl_options[md].flag_var = flag_val;
+ 	  return;
+ 	}
+ 
+       if (comp < 0)
+ 	mx = md;
+       else
+ 	mn = md;
+     }
+ 
+   warning ("pragma GCC warning: `%s' not found, ignored", ent);
+ 
+   if (list_printed)
+     return;
+   list_printed = 1;
+ 
+   inform ("Available warnings are:");
+   for (i=0; i<cl_options_count; i++)
+     if (cl_options[i].flag_var
+ 	&& strncmp (cl_options[i].opt_text, "-W", 2) == 0)
+       inform ("  %s", cl_options[i].opt_text);
+ }
+ 
  /* Set up front-end pragmas.  */
  void
*************** init_pragma (void)
*** 595,598 ****
--- 664,669 ----
    REGISTER_TARGET_PRAGMAS ();
  #endif
+ 
+   c_register_pragma ("GCC", "warning", handle_pragma_gcc_warning);
  }
  


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