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]

more warning control patches


A few more trivial OPT_W* patches, plus a new option -Wpragmas to
control all the pragma warnings not already controlled by
-Wunknown-pragmas.  Haven't checked to see where to put the doc bit,
so it's included right after the ChangeLog.  Look reasonable so far?

(no, no bootstrap yet.  Just asking if I'm headed in the right
direction.  Bootstraps take far longer than actually patching :-P so I
don't want to waste them, but I will bootstrap before committing.)

2005-07-15  DJ Delorie  <dj@redhat.com>

	* toplev.h: Add comment about the first parameter for warning().
	* errors.h: Likewise.

	* c.opt (Wpragmas): New.
	* doc/invoke.texi: Document it.
	
	* function.c (do_warn_unused_parameter): Add warning control to
	warning call.
	* c-decl.c (warn_if_shadowing): Likewise.
	* c-lex.c (cb_def_pragma): Likewise.
	* c-pragma.c (GCC_BAD, GCC_BAD2): Likewise.
	(pop_alignment): Likewise.
	(handle_pragma_pack): Likewise.
	(apply_pragma_weak): Likewise.
	(handle_pragma_weak): Likewise.
	(handle_pragma_redefine_extname): Likewise.
	(add_to_renaming_pragma_list): Likewise.
	(handle_pragma_extern_prefix): Likewise.
	(maybe_apply_renaming_pragma): Likewise.
	(handle_pragma_visibility): Likewise.
	
	* config/c4x/c4x-c.c (BAD): Likewise.
	(c4x_parse_pragma): Likewise.
	* config/ia64/ia64-c.c (ia64_hpux_handle_builtin_pragma): Likewise.
	* config/rs6000/rs6000-c.c (SYNTAX_ERROR): Likewise.
	(rs6000_pragma_longcall): Likewise.
	* config/v850/v850-c.c (pop_data_area): Likewise.
	(ghs_pragma_section): Likewise.
	(ghs_pragma_section): Likewise.
	(ghs_pragma_interrupt): Likewise.
	(ghs_pragma_starttda): Likewise.
	(ghs_pragma_startsda): Likewise.
	(ghs_pragma_startzda): Likewise.
	(ghs_pragma_endtda): Likewise.
	(ghs_pragma_endsda): Likewise.
	(ghs_pragma_endzda): Likewise.


@item -Wpragmas
@opindex Wpragmas

Warn about misuses of pragmas, such as incorrect parameters, invalid
syntax, or conflicts between pragmas.  See also
@samp{-Wunknown-pragmas}.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.675
diff -p -U3 -r1.675  c-decl.c
--- c-decl.c	8 Jul 2005 23:36:35 -0000	1.675
+++ c-decl.c	15 Jul 2005 21:43:12 -0000
@@ -1908,27 +1908,28 @@ warn_if_shadowing (tree new_decl)
 
 	if (old_decl == error_mark_node)
 	  {
-	    warning (0, "declaration of %q+D shadows previous non-variable",
-		     new_decl);
+	    warning (OPT_Wshadow, "declaration of %q+D shadows previous "
+		     "non-variable", new_decl);
 	    break;
 	  }
 	else if (TREE_CODE (old_decl) == PARM_DECL)
-	  warning (0, "declaration of %q+D shadows a parameter", new_decl);
-	else if (DECL_FILE_SCOPE_P (old_decl))
-	  warning (0, "declaration of %q+D shadows a global declaration",
+	  warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
 		   new_decl);
+	else if (DECL_FILE_SCOPE_P (old_decl))
+	  warning (OPT_Wshadow, "declaration of %q+D shadows a global "
+		   "declaration", new_decl);
 	else if (TREE_CODE (old_decl) == FUNCTION_DECL
 		 && DECL_BUILT_IN (old_decl))
 	  {
-	    warning (0, "declaration of %q+D shadows a built-in function",
-		     new_decl);
+	    warning (OPT_Wshadow, "declaration of %q+D shadows "
+		     "a built-in function", new_decl);
 	    break;
 	  }
 	else
-	  warning (0, "declaration of %q+D shadows a previous local",
+	  warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
 		   new_decl);
 
-	warning (0, "%Jshadowed declaration is here", old_decl);
+	warning (OPT_Wshadow, "%Jshadowed declaration is here", old_decl);
 
 	break;
       }
Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.250
diff -p -U3 -r1.250  c-lex.c
--- c-lex.c	25 Jun 2005 01:59:20 -0000	1.250
+++ c-lex.c	15 Jul 2005 21:43:12 -0000
@@ -299,7 +299,8 @@ cb_def_pragma (cpp_reader *pfile, source
 	    name = cpp_token_as_text (pfile, s);
 	}
 
-      warning (0, "%Hignoring #pragma %s %s", &fe_loc, space, name);
+      warning (OPT_Wunknown_pragmas, "%Hignoring #pragma %s %s",
+	       &fe_loc, space, name);
     }
 }
 
Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.90
diff -p -U3 -r1.90  c-pragma.c
--- c-pragma.c	3 Jul 2005 21:07:47 -0000	1.90
+++ c-pragma.c	15 Jul 2005 21:43:12 -0000
@@ -37,9 +37,10 @@ Software Foundation, 51 Franklin Street,
 #include "vec.h"
 #include "target.h"
 
-#define GCC_BAD(gmsgid) do { warning (0, gmsgid); return; } while (0)
+#define GCC_BAD(gmsgid) \
+  do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
 #define GCC_BAD2(gmsgid, arg) \
-  do { warning (0, gmsgid, arg); return; } while (0)
+  do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
 
 typedef struct align_stack GTY(())
 {
@@ -110,7 +111,7 @@ pop_alignment (tree id)
 	    break;
 	  }
       if (entry == NULL)
-	warning (0, "\
+	warning (OPT_Wpragmas, "\
 #pragma pack(pop, %s) encountered without matching #pragma pack(push, %s)"
 		 , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (id));
     }
@@ -203,7 +204,7 @@ handle_pragma_pack (cpp_reader * ARG_UNU
     GCC_BAD ("malformed %<#pragma pack%> - ignored");
 
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of %<#pragma pack%>");
+    warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
 
   if (flag_pack_struct)
     GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
@@ -259,8 +260,8 @@ apply_pragma_weak (tree decl, tree value
   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
       && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma.  */
       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
-    warning (0, "applying #pragma weak %q+D after first use results "
-             "in unspecified behavior", decl);
+    warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
+             "results in unspecified behavior", decl);
 
   declare_weak (decl);
 }
@@ -342,7 +343,7 @@ handle_pragma_weak (cpp_reader * ARG_UNU
       t = c_lex (&x);
     }
   if (t != CPP_EOF)
-    warning (0, "junk at end of #pragma weak");
+    warning (OPT_Wpragmas, "junk at end of #pragma weak");
 
   decl = identifier_global_value (name);
   if (decl && DECL_P (decl))
@@ -415,7 +416,7 @@ handle_pragma_redefine_extname (cpp_read
     GCC_BAD ("malformed #pragma redefine_extname, ignored");
   t = c_lex (&x);
   if (t != CPP_EOF)
-    warning (0, "junk at end of #pragma redefine_extname");
+    warning (OPT_Wpragmas, "junk at end of #pragma redefine_extname");
 
   if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
     {
@@ -438,8 +439,8 @@ handle_pragma_redefine_extname (cpp_read
 	  name = targetm.strip_name_encoding (name);
 
 	  if (strcmp (name, IDENTIFIER_POINTER (newname)))
-	    warning (0, "#pragma redefine_extname ignored due to conflict with "
-		     "previous rename");
+	    warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+		     "conflict with previous rename");
 	}
       else
 	change_decl_assembler_name (decl, newname);
@@ -461,8 +462,8 @@ add_to_renaming_pragma_list (tree oldnam
   if (previous)
     {
       if (TREE_VALUE (previous) != newname)
-	warning (0, "#pragma redefine_extname ignored due to conflict with "
-		 "previous #pragma redefine_extname");
+	warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
+		 "conflict with previous #pragma redefine_extname");
       return;
     }
   
@@ -483,7 +484,7 @@ handle_pragma_extern_prefix (cpp_reader 
     GCC_BAD ("malformed #pragma extern_prefix, ignored");
   t = c_lex (&x);
   if (t != CPP_EOF)
-    warning (0, "junk at end of #pragma extern_prefix");
+    warning (OPT_Wpragmas, "junk at end of #pragma extern_prefix");
 
   if (targetm.handle_pragma_extern_prefix)
     /* Note that the length includes the null terminator.  */
@@ -516,7 +517,7 @@ maybe_apply_renaming_pragma (tree decl, 
       oldname = targetm.strip_name_encoding (oldname);
 
       if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
-	  warning (0, "asm declaration ignored due to "
+	  warning (OPT_Wpragmas, "asm declaration ignored due to "
 		   "conflict with previous rename");
 
       /* Take any pending redefine_extname off the list.  */
@@ -525,7 +526,7 @@ maybe_apply_renaming_pragma (tree decl, 
 	  {
 	    /* Only warn if there is a conflict.  */
 	    if (strcmp (IDENTIFIER_POINTER (TREE_VALUE (t)), oldname))
-	      warning (0, "#pragma redefine_extname ignored due to "
+	      warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
 		       "conflict with previous rename");
 
 	    *p = TREE_CHAIN (t);
@@ -547,7 +548,7 @@ maybe_apply_renaming_pragma (tree decl, 
 	  {
 	    if (strcmp (TREE_STRING_POINTER (asmname),
 			IDENTIFIER_POINTER (newname)) != 0)
-	      warning (0, "#pragma redefine_extname ignored due to "
+	      warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
 		       "conflict with __asm__ declaration");
 	    return asmname;
 	  }
@@ -661,7 +662,7 @@ handle_pragma_visibility (cpp_reader *du
         }
     }
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of %<#pragma GCC visibility%>");
+    warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
 }
 
 #endif
Index: c.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c.opt,v
retrieving revision 1.49
diff -p -U3 -r1.49  c.opt
--- c.opt	3 Jul 2005 21:07:47 -0000	1.49
+++ c.opt	15 Jul 2005 21:43:12 -0000
@@ -331,6 +331,10 @@ Wpointer-to-int-cast
 C ObjC Var(warn_pointer_to_int_cast) Init(1)
 Warn when a pointer is cast to an integer of a different size
 
+Wpragmas
+C ObjC C++ ObjC++ Var(warn_pragmas) Init(1)
+Warn about misuses of pragmas
+
 Wprotocol
 ObjC ObjC++ Var(warn_protocol) Init(1)
 Warn if inherited methods are unimplemented
Index: errors.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/errors.h,v
retrieving revision 1.17
diff -p -U3 -r1.17  errors.h
--- errors.h	25 Jun 2005 01:59:46 -0000	1.17
+++ errors.h	15 Jul 2005 21:43:12 -0000
@@ -30,6 +30,10 @@ Software Foundation, 51 Franklin Street,
 #ifndef GCC_ERRORS_H
 #define GCC_ERRORS_H
 
+/* The first parameter is for compatibility with the non-generator
+   version of warning().  For those, you'd pass an OPT_W* value from
+   options.h, but in generator programs it has no effect, so it's OK
+   to just pass zero for calls from generator-only files.  */
 extern void warning (int, const char *, ...) ATTRIBUTE_PRINTF_2;
 extern void error (const char *, ...) ATTRIBUTE_PRINTF_1;
 extern void fatal (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.636
diff -p -U3 -r1.636  function.c
--- function.c	14 Jul 2005 07:39:51 -0000	1.636
+++ function.c	15 Jul 2005 21:43:12 -0000
@@ -4315,7 +4315,7 @@ do_warn_unused_parameter (tree fn)
        decl; decl = TREE_CHAIN (decl))
     if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
 	&& DECL_NAME (decl) && !DECL_ARTIFICIAL (decl))
-      warning (0, "unused parameter %q+D", decl);
+      warning (OPT_Wunused_parameter, "unused parameter %q+D", decl);
 }
 
 static GTY(()) rtx initial_trampoline;
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.139
diff -p -U3 -r1.139  toplev.h
--- toplev.h	5 Jul 2005 16:20:22 -0000	1.139
+++ toplev.h	15 Jul 2005 21:43:13 -0000
@@ -57,6 +57,7 @@ extern void _fatal_insn (const char *, r
 extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
 extern void warning0 (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+/* Pass one of the OPT_W* from options.h as the first parameter.  */
 extern void warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
Index: config/c4x/c4x-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/c4x/c4x-c.c,v
retrieving revision 1.9
diff -p -U3 -r1.9  config/c4x/c4x-c.c
--- config/c4x/c4x-c.c	25 Jun 2005 01:20:59 -0000	1.9
+++ config/c4x/c4x-c.c	15 Jul 2005 21:43:13 -0000
@@ -57,7 +57,8 @@ static int c4x_parse_pragma (const char 
    the STRING_CST node of the string.  If SECT is null, then this
    pragma doesn't take a section string.  Returns 0 for a good pragma,
    -1 for a malformed pragma.  */
-#define BAD(gmsgid, arg) do { warning (0, gmsgid, arg); return -1; } while (0)
+#define BAD(gmsgid, arg) \
+  do { warning (OPT_Wpragmas, gmsgid, arg); return -1; } while (0)
 
 static int
 c4x_parse_pragma (name, func, sect)
@@ -86,7 +87,7 @@ c4x_parse_pragma (name, func, sect)
     BAD ("missing ')' for '#pragma %s' - ignored", name);
 
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of '#pragma %s'", name);
+    warning (OPT_Wpragmas, "junk at end of '#pragma %s'", name);
 
   *func = f;
   return 0;
Index: config/ia64/ia64-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/ia64/ia64-c.c,v
retrieving revision 1.10
diff -p -U3 -r1.10  config/ia64/ia64-c.c
--- config/ia64/ia64-c.c	25 Jun 2005 01:21:26 -0000	1.10
+++ config/ia64/ia64-c.c	15 Jul 2005 21:43:13 -0000
@@ -49,7 +49,7 @@ ia64_hpux_handle_builtin_pragma (cpp_rea
 	type = c_lex (&x);
     }
   if (type != CPP_EOF)
-    warning (0, "malformed #pragma builtin");
+    warning (OPT_Wpragmas, "malformed #pragma builtin");
 }
 
 /* List of standard math functions which do not set matherr by default
Index: config/rs6000/rs6000-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000-c.c,v
retrieving revision 1.21
diff -p -U3 -r1.21  config/rs6000/rs6000-c.c
--- config/rs6000/rs6000-c.c	25 Jun 2005 01:22:07 -0000	1.21
+++ config/rs6000/rs6000-c.c	15 Jul 2005 21:43:13 -0000
@@ -50,10 +50,10 @@ static tree altivec_resolve_overloaded_b
    whether or not new function declarations receive a longcall
    attribute by default.  */
 
-#define SYNTAX_ERROR(gmsgid) do {			\
-  warning (0, gmsgid);					\
-  warning (0, "ignoring malformed #pragma longcall");	\
-  return;						\
+#define SYNTAX_ERROR(gmsgid) do {					\
+  warning (OPT_Wpragmas, gmsgid);					\
+  warning (OPT_Wpragmas, "ignoring malformed #pragma longcall");	\
+  return;								\
 } while (0)
 
 void
@@ -75,7 +75,7 @@ rs6000_pragma_longcall (cpp_reader *pfil
     SYNTAX_ERROR ("number must be 0 or 1");
 
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma longcall");
+    warning (OPT_Wpragmas, "junk at end of #pragma longcall");
 
   rs6000_default_long_calls = (n == integer_one_node);
 }
Index: config/v850/v850-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/v850/v850-c.c,v
retrieving revision 1.11
diff -p -U3 -r1.11  config/v850/v850-c.c
--- config/v850/v850-c.c	25 Jun 2005 01:22:36 -0000	1.11
+++ config/v850/v850-c.c	15 Jul 2005 21:43:13 -0000
@@ -64,9 +64,11 @@ static int
 pop_data_area (v850_data_area data_area)
 {
   if (data_area_stack == NULL)
-    warning (0, "#pragma GHS endXXXX found without previous startXXX");
+    warning (OPT_Wpragmas, "#pragma GHS endXXXX found without "
+	     "previous startXXX");
   else if (data_area != data_area_stack->data_area)
-    warning (0, "#pragma GHS endXXX does not match previous startXXX");
+    warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
+	     "previous startXXX");
   else
     {
       data_area_stack_element * elem;
@@ -144,7 +146,7 @@ ghs_pragma_section (cpp_reader * pfile A
       if (type == CPP_COMMA)
 	repeat = 1;
       else if (type != CPP_EOF)
-	warning (0, "junk at end of #pragma ghs section");
+	warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
       
       if      (streq (sect, "data"))    kind = GHS_SECTION_KIND_DATA;
       else if (streq (sect, "text"))    kind = GHS_SECTION_KIND_TEXT;
@@ -176,7 +178,7 @@ ghs_pragma_section (cpp_reader * pfile A
   return;
 
  bad:
-  warning (0, "malformed #pragma ghs section");
+  warning (OPT_Wpragmas, "malformed #pragma ghs section");
   return;
 
  reset:
@@ -195,7 +197,7 @@ ghs_pragma_interrupt (cpp_reader * pfile
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs interrupt");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
   
   mark_current_function_as_interrupt ();
 }
@@ -206,7 +208,7 @@ ghs_pragma_starttda (cpp_reader * pfile 
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs starttda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
   
   push_data_area (DATA_AREA_TDA);
 }
@@ -217,7 +219,7 @@ ghs_pragma_startsda (cpp_reader * pfile 
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs startsda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
   
   push_data_area (DATA_AREA_SDA);
 }
@@ -228,7 +230,7 @@ ghs_pragma_startzda (cpp_reader * pfile 
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs startzda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
   
   push_data_area (DATA_AREA_ZDA);
 }
@@ -239,7 +241,7 @@ ghs_pragma_endtda (cpp_reader * pfile AT
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs endtda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
   
   pop_data_area (DATA_AREA_TDA);
 }
@@ -250,7 +252,7 @@ ghs_pragma_endsda (cpp_reader * pfile AT
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs endsda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
   
   pop_data_area (DATA_AREA_SDA);
 }
@@ -261,7 +263,7 @@ ghs_pragma_endzda (cpp_reader * pfile AT
   tree x;
   
   if (c_lex (&x) != CPP_EOF)
-    warning (0, "junk at end of #pragma ghs endzda");
+    warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
   
   pop_data_area (DATA_AREA_ZDA);
 }


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