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]

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


Kaveh R. Ghazi wrote:-

> One nit I noticed is that you handled the integer 'U' suffix but not
> the floating point 'L' or 'F' ones, which could arise in e.g. a
> FLT_MAX macro.  IMHO, you should handle these too.

Thanks, I've fixed this.  It doesn't affect cpp, only c-lex.c from
what I can see.

> For testcases, look at gcc.dg/wtr-suffix-1.c and
> gcc.dg/cpp/tr-warn2.c, you can copy those as a starting point for the
> -Wtraditional warnings you've fixed.  (Call them wtr-suffix-2.c and
> tr-warn7.c.)  I don't know offhand where the c99 varargs stuff is
> currently tested.  Jsm might.

I want to keep these all together.  I've got a sysmac1.c for testing
CPP, and am working on a sysmac2.c for compiler tests.

The implementation below is improved - it doesn't add a node field to
the cpp_macro structure.  I'm bootstrapping again - I noticed I had
one of my conditionals the wrong way round after the initial bootstrap
of this improved version :-(

Neil.

	* c-lex.c (lex_number): Only warn traditionally for suffixes
        outside system macros.
        * cppexp.c (parse_number): Similarly.
        * cpplib.h (cpp_sys_objmacro_p): New.
        * cppmacro.c (struct cpp_macro): New member syshdr.
        (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): 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 21:43:34
@@ -1224,7 +1224,8 @@ lex_number (str, len)
 	  case 'f': case 'F':
 	    if (fflag)
 	      ERROR ("more than one 'f' suffix on floating 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 'f' suffix");
 
 	    fflag = 1;
@@ -1233,7 +1234,8 @@ lex_number (str, len)
 	  case 'l': case 'L':
 	    if (lflag)
 	      ERROR ("more than one 'l' suffix on floating 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 'l' suffix");
 
 	    lflag = 1;
@@ -1308,7 +1310,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 21:43: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 21:43:44
@@ -603,6 +603,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 21:43:54
@@ -44,6 +44,7 @@ struct cpp_macro
   unsigned int fun_like : 1;	/* If a function-like macro.  */
   unsigned int variadic : 1;	/* If a variadic macro.  */
   unsigned int disabled : 1;	/* If macro is disabled.  */
+  unsigned int syshdr   : 1;	/* If macro defined in system header.  */
 };
 
 typedef struct macro_arg macro_arg;
@@ -558,7 +559,7 @@ parse_args (pfile, node)
 
       if (argc + 1 == macro->paramc && macro->variadic)
 	{
-	  if (CPP_PEDANTIC (pfile))
+	  if (CPP_PEDANTIC (pfile) && ! macro->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->value.macro->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->syshdr;
+}
+
 /* Read each token in, until EOF.  Directives are transparently
    processed.  */
 void
@@ -1440,6 +1453,9 @@ _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);
+
+  /* To suppress some diagnostics.  */
+  macro->syshdr = pfile->buffer->sysp != 0;
 
   /* Commit the memory.  */
   POOL_COMMIT (&pfile->macro_pool, macro->count * sizeof (cpp_token));

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