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]

[RFA] Silence some warnings [was Re: "introduce no new bootstrap..."]


Hi Zack,

OK, I relent, but only slightly.

Zack Weinberg wrote:-

> I think we can all agree that the ideal situation, from the user's
> point of view, would be:
> 
> /* stdio.h */
> #define printf(format, args...) fprintf(stdout, format, ##args)
> 
> /* user */
> printf("string")
> 
> 	-> No warning about C99 vararg semantics.
> 	   (If the varargs extension is used by a macro defined in a
> 	   system header, suppress the warning.)

"Fixed" below.  I'm still peeved that Ulrich did this without saying
anything, and knowing it would cause floods of warnings.

> /* limits.h */
> #define UINT_MAX 4294967295U
> 
> /* user */
>   if (expression involving UINT_MAX)
> 
> 	-> No warning about 'U' not understood by K+R C.
> 	   (If the numeric token in question originated in a system
> 	   header, suppress the warning.)

"Fixed" below for the common case of object-like macros invoked in a
straight forward way.  See below for more detail on this point.

> /* string.h */
> #define strcmp(a, b) /* monstrous horror */
> 
> /* user */
>   qsort(array, elts, sizeof (char *), strcmp);
> 
> 	-> No warning about function macro used in non-function context.
> 	   (If the function macro in question was defined in a system
> 	   header, suppress the warning.)

Fixed this too.

> /* syslog.h */
> extern void syslog(int, char *, ...)
> 	__attribute__ ((format (printf, 2, 3)));
> 
> /* user */
> 
> syslog(LOG_INFO, "i=%s", 34);
> 
> 	-> Yes, -Wformat warning.
> 	(-Wformat pays no attention to the location of the prototype
> 	for the printflike function.)

This is the case already, so there's nothing to do.

Now, the "strcmp" and "ISO C rest args" warnings are easy to fix -
they're cpplib-internal.  The patch below has cpplib remember which
macros are defined in system headers, and only emit those warnings
for macros which are not defined in system headers.

The UINT_MAX and friends is not really fixable in general, for reasons
I've already outlined.  But, I think it's not hard to catch the vast
majority of cases, say > 90%.

I have exported an interface from cpplib

int cpp_sys_objmacro_p (cpp_reader *);

which returns true if the macro at the top of the macro stack was
defined in a system header, and is an object-like macro.  So "simple"
uses of stuff like UINT_MAX will return true.

I have updated cppexp.c and c-lex.c to check this before giving the
-Wtraditional warning.

However, this is only a very simple check, and (though I haven't
tried) undoubtedly will fail on some things.  It will also fail in the
event of token look-ahead, either by cpplib or front ends.  At
present, only cpplib does look-ahead, and only occasionally and for
single tokens.  The front-ends could well start using this cpplib
facility in the future, in which case we could start getting more
macro uses that have since been "popped" off the macro stack and the
warnings will re-appear.

I really don't think doing any more than this is workable or
realistic.  I hope this makes people that don't like the current
situation a bit happier, and that we examine every new warning to be
"suppressed" along these lines on a case-by-case basis, and with some
scepticism.

Anyway, how does this float people's boat?  It will help silence
gazillions of warnings caused by glibc in recent Linux bootstraps.

I'll post a testcase soon.  Bootstrapping i586 Linux.  OK to commit
this in the slush period?

Neil.

	* c-lex.c (lex_number): Only warn traditionally for U suffix
	outside system macros.
	* cppexp.c (parse_number): Similarly.
	* cpplib.h (NODE_SYSHDR, cpp_sys_objmacro_p): New.
	* cppmacro.c (struct cpp_macro): New member node.
	(parse_args): Only warn about missing rest args if not
	a system macro.
	(funlike_invocation_p): Similarly for uninvoked funlike macros.
	(cpp_sys_objmacro_p): New.
	(_cpp_create_definition): Store the node with the macro defn.
	Remember if the macro is defined in a system header.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.127
diff -u -p -r1.127 c-lex.c
--- c-lex.c	2001/01/13 14:23:03	1.127
+++ c-lex.c	2001/01/15 20:07:33
@@ -1308,7 +1308,8 @@ lex_number (str, len)
 	    case 'u': case 'U':
 	      if (spec_unsigned)
 		error ("two 'u' suffixes on integer constant");
-	      else if (warn_traditional && !in_system_header)
+	      else if (warn_traditional && !in_system_header
+		       && ! cpp_sys_objmacro_p (parse_in))
 		warning ("traditional C rejects the 'u' suffix");
 
 	      spec_unsigned = 1;
Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppexp.c,v
retrieving revision 1.83
diff -u -p -r1.83 cppexp.c
--- cppexp.c	2000/12/07 01:58:22	1.83
+++ cppexp.c	2001/01/15 20:07:37
@@ -204,7 +204,9 @@ parse_number (pfile, tok)
 	goto invalid_suffix;
       op.unsignedp = sufftab[i].u;
 
-      if (CPP_WTRADITIONAL (pfile) && sufftab[i].u)
+      if (CPP_WTRADITIONAL (pfile)
+	  && sufftab[i].u
+	  && ! cpp_sys_objmacro_p (pfile))
 	cpp_warning (pfile, "traditional C rejects the `U' suffix");
       if (sufftab[i].l == 2 && CPP_OPTION (pfile, pedantic)
 	  && ! CPP_OPTION (pfile, c99))
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.161
diff -u -p -r1.161 cpplib.h
--- cpplib.h	2001/01/14 22:00:19	1.161
+++ cpplib.h	2001/01/15 20:07:39
@@ -443,6 +443,7 @@ enum cpp_buffer_type {BUF_FAKE, BUF_FILE
 #define NODE_POISONED	(1 << 1)	/* Poisoned identifier.  */
 #define NODE_BUILTIN	(1 << 2)	/* Builtin macro.  */
 #define NODE_DIAGNOSTIC (1 << 3)	/* Possible diagnostic when lexed.  */
+#define NODE_SYSHDR     (1 << 4)	/* Macro defined in system header.  */
 
 /* Different flavors of hash node.  */
 enum node_type
@@ -603,6 +604,7 @@ extern void cpp_forall_identifiers	PARAM
 extern void cpp_scan_buffer_nooutput	PARAMS ((cpp_reader *, int));
 extern void cpp_start_lookahead		PARAMS ((cpp_reader *));
 extern void cpp_stop_lookahead		PARAMS ((cpp_reader *, int));
+extern int  cpp_sys_objmacro_p		PARAMS ((cpp_reader *));
 
 /* In cppfiles.c */
 extern int cpp_included	PARAMS ((cpp_reader *, const char *));
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.38
diff -u -p -r1.38 cppmacro.c
--- cppmacro.c	2001/01/09 09:30:43	1.38
+++ cppmacro.c	2001/01/15 20:07:46
@@ -35,6 +35,7 @@ Foundation, 59 Temple Place - Suite 330,
 
 struct cpp_macro
 {
+  cpp_hashnode *node;		/* The macro node.  */
   cpp_hashnode **params;	/* Parameters, if any.  */
   cpp_token *expansion;		/* First token of replacement list.   */
   const char *file;		/* Defined in file name.  */
@@ -558,7 +559,7 @@ parse_args (pfile, node)
 
       if (argc + 1 == macro->paramc && macro->variadic)
 	{
-	  if (CPP_PEDANTIC (pfile))
+	  if (CPP_PEDANTIC (pfile) && ! (node->flags & NODE_SYSHDR))
 	    cpp_pedwarn (pfile, "ISO C99 requires rest arguments to be used");
 	}
       else
@@ -612,7 +613,7 @@ funlike_invocation_p (pfile, node, list)
 
   if (maybe_paren.type == CPP_OPEN_PAREN)
     args = parse_args (pfile, node);
-  else if (CPP_WTRADITIONAL (pfile))
+  else if (CPP_WTRADITIONAL (pfile) && ! (node->flags & NODE_SYSHDR))
     cpp_warning (pfile,
 	 "function-like macro \"%s\" must be used with arguments in traditional C",
 		 node->name);
@@ -983,6 +984,18 @@ cpp_get_token (pfile, token)
     save_lookahead_token (pfile, token);
 }
 
+/* Returns true if we're expanding an object-like macro that was
+   defined in a system header.  Just checks the macro at the top of
+   the stack.  Used for diagnostic suppression.  */
+int
+cpp_sys_objmacro_p (pfile)
+     cpp_reader *pfile;
+{
+  cpp_macro *macro = pfile->context->macro;
+
+  return macro && !macro->fun_like && (macro->node->flags & NODE_SYSHDR);
+}
+
 /* Read each token in, until EOF.  Directives are transparently
    processed.  */
 void
@@ -1440,6 +1453,7 @@ _cpp_create_definition (pfile, node)
   macro->disabled = (macro->count == 1 && !macro->fun_like
 		     && macro->expansion[0].type == CPP_NAME
 		     && macro->expansion[0].val.node == node);
+  macro->node = node;
 
   /* Commit the memory.  */
   POOL_COMMIT (&pfile->macro_pool, macro->count * sizeof (cpp_token));
@@ -1468,6 +1482,10 @@ _cpp_create_definition (pfile, node)
   /* Enter definition in hash table.  */
   node->type = NT_MACRO;
   node->value.macro = macro;
+
+  /* To suppress some diagnostics.  */
+  if (pfile->buffer->sysp)
+    node->flags |= NODE_SYSHDR;
 
  cleanup:
 

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