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]

Re: New bug in cpp, bogus macro redefinition warnings


On Wed, Mar 01, 2000 at 04:24:30PM -0800, Zack Weinberg wrote:
> On Wed, Mar 01, 2000 at 11:56:59PM +0000, grahams wrote:
> > Zack
> > 
> > Here's the test case couldn't be similar! no special
> > options just gcc -c bug.c will do the trick.
> > 
> > Create a source file with the following line (note
> > the space at the beginning of the line it's very
> > important)
> > 
> > --------------bug.c------------------------
> >  #define _LIBC_LIMITS_H_ /* This tells it not to look for another.  */
> > -------------------------------------------
> > 
> > If I remove the leading space(s) before the # it
> > doesn't crash.
> 
> Aha - that's it.  Normally, y'see, there isn't a space before the
> beginning of the buffer, so it stops.
> 
> Please try the appended patch.

Damn.  I should at least run through stage1 before posting patches.

Try *this* one.

Index: cpphash.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpphash.c,v
retrieving revision 1.43
diff -u -p -r1.43 cpphash.c
--- cpphash.c	2000/03/01 19:12:17	1.43
+++ cpphash.c	2000/03/02 00:48:53
@@ -424,6 +424,7 @@ collect_expansion (pfile, arglist)
       continue;
 
     maybe_trad_stringify:
+      last_token = NORM;
       {
 	U_CHAR *base, *p, *limit;
 	struct reflist *tpat;
@@ -487,21 +488,31 @@ 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);
+  if (last_token == START)
+    {
+      /* Empty macro definition.  */
+      exp = xstrdup ("\r \r ");
+      len = 1;
+    }
+  else
+    {
+      /* 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 */
-  exp[0] = '\r';
-  exp[1] = ' ';
-  exp[len + 1] = '\r';
-  exp[len + 2] = ' ';
-  exp[len + 3] = '\0';
-  memcpy (&exp[2], pfile->token_buffer + start, len - 1);
+      CPP_NUL_TERMINATE (pfile);
+      len = CPP_WRITTEN (pfile) - start + 1;
+      exp = xmalloc (len + 4); /* space for no-concat markers at either end */
+      exp[0] = '\r';
+      exp[1] = ' ';
+      exp[len + 1] = '\r';
+      exp[len + 2] = ' ';
+      exp[len + 3] = '\0';
+      memcpy (&exp[2], pfile->token_buffer + start, len - 1);
+    }
+
   CPP_SET_WRITTEN (pfile, start);
 
   defn = (DEFINITION *) xmalloc (sizeof (DEFINITION));

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