New bug in cpp, bogus macro redefinition warnings

Zack Weinberg zack@wolery.cumb.org
Wed Mar 1 11:12:00 GMT 2000


On Wed, Mar 01, 2000 at 09:37:34AM -0800, Zack Weinberg wrote:
> On Wed, Mar 01, 2000 at 11:24:37AM -0500, Kaveh R. Ghazi wrote:
> > Bootstrapping last night's snapshot on sparc-sun-solaris2.7 exposed a
> > new bug in cpp.  I get large amounts of macro redefinition warnings
> > (~1200) from the system headers.
> > 
> > They come from macros defined to the same value more than once, but
> > one instance is followed by a comment.  E.g. you can see what I mean
> > in the following two line file.
> > 
> >  > #define FOO 10 /* sdf */
> >  > #define FOO 10
> > 
> > (Perhaps you want to install this as a test case.)
> > 
> > With last night's "gcc version 2.96 20000229 (experimental)", it gives:
> > 
> >  > foo.c:2:14: warning: `FOO' redefined
> >  > foo.c:1:11: warning: this is the location of the previous definition
> 
> Aaargh.  Yes, I see the problem.  Please try this patch - will commit,
> with test case, once it completes bootstrap.

That wasn't quite the right patch.

I have committed this, which should fix the bug.

zw

	* cpphash.c (collect_expansion): Trim trailing white space
	from macro definitions, but don't go past the last insertion
	point.
	* gcc.dg/cpp-redef.c: New test.
===================================================================
Index: cpphash.c
--- cpphash.c	2000/03/01 00:57:08	1.42
+++ cpphash.c	2000/03/01 19:10:01
@@ -487,6 +487,12 @@ collect_expansion (pfile, arglist)
   else if (last_token == PASTE)
     cpp_error (pfile, "`##' at end of macro definition");
 
+  /* Trim trailing white space from definition.  */
+  here = CPP_WRITTEN (pfile);
+  while (here > last && is_hspace (pfile->token_buffer [here-1]))
+    here--;
+  CPP_SET_WRITTEN (pfile, here);
+  
   CPP_NUL_TERMINATE (pfile);
   len = CPP_WRITTEN (pfile) - start + 1;
   exp = xmalloc (len + 4); /* space for no-concat markers at either end */
===================================================================
Index: testsuite/gcc.dg/cpp-redef.c
--- testsuite/gcc.dg/cpp-redef.c	Tue May  5 13:32:27 1998
+++ testsuite/gcc.dg/cpp-redef.c	Wed Mar  1 11:10:03 2000
@@ -0,0 +1,19 @@
+/* Test for redefining macros with insignificant (i.e. whitespace)
+   differences.  */
+
+/* { dg-do preprocess } */
+
+#define foo bar
+#define /* x */ foo /* x */ bar /* x */
+
+#define quux(thud) a one and a thud and a two
+#define /**/ quux( thud ) /**/ a one and a /**/ thud /**/ and /**/ a two
+#define quux(thud) a one	and a thud and a 	two /* bah */
+
+/* { dg-bogus "redefined" "foo redefined"	{ target *-*-* } 7 } */
+/* { dg-bogus "redefined" "quux redefined"	{ target *-*-* } 10 } */
+/* { dg-bogus "redefined" "quux redefined"	{ target *-*-* } 11 } */
+
+/* { dg-bogus "previous def" "foo prev def"	{ target *-*-* } 6 } */
+/* { dg-bogus "previous def" "quux prev def"	{ target *-*-* } 9 } */
+/* { dg-bogus "previous def" "quux prev def"	{ target *-*-* } 10 } */


More information about the Gcc-bugs mailing list