This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: New bug in cpp, bogus macro redefinition warnings
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.
zw
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:22:51
@@ -487,21 +487,28 @@ 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 ");
+ 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));