Commit 0d5a06bd by Zack Weinberg Committed by Zack Weinberg

cpphash.c (special_symbol): Represent an empty macro with "\r \r " not just "\r ".

	* cpphash.c (special_symbol): Represent an empty macro with
	"\r \r " not just "\r ".
	(_cpp_macroexpand): Correct condition for the foo ( ) special
	case.
	(unsafe_chars): Handle EOF as second argument.
	(push_macro_expansion): Simplify test for removing escape at
	end.  Do not trim both escapes if there is no text in between.

	* gcc.dg/20000419-1.c: New test.

From-SVN: r33267
parent b13fe8bf
2000-04-19 Zack Weinberg <zack@wolery.cumb.org>
* cpphash.c (special_symbol): Represent an empty macro with
"\r \r " not just "\r ".
(_cpp_macroexpand): Correct condition for the foo ( ) special
case.
(unsafe_chars): Handle EOF as second argument.
(push_macro_expansion): Simplify test for removing escape at
end. Do not trim both escapes if there is no text in between.
2000-04-19 Jim Blandy <jimb@redhat.com> 2000-04-19 Jim Blandy <jimb@redhat.com>
* dwarf2out.c (DWARF2_ADDR_SIZE): New macro. Use it instead * dwarf2out.c (DWARF2_ADDR_SIZE): New macro. Use it instead
......
...@@ -908,7 +908,7 @@ special_symbol (hp, pfile) ...@@ -908,7 +908,7 @@ special_symbol (hp, pfile)
if (!buf) if (!buf)
return; return;
if (*buf == '\0') if (*buf == '\0')
buf = "\r "; buf = "\r \r ";
CPP_PUTS (pfile, buf, strlen (buf)); CPP_PUTS (pfile, buf, strlen (buf));
return; return;
...@@ -1075,14 +1075,14 @@ _cpp_macroexpand (pfile, hp) ...@@ -1075,14 +1075,14 @@ _cpp_macroexpand (pfile, hp)
if (token != CPP_RPAREN) if (token != CPP_RPAREN)
return; return;
/* If we got one arg but it was just whitespace, call that 0 args. */ /* foo ( ) is equivalent to foo () unless foo takes exactly one
if (i == 1) argument, in which case the former is allowed and the latter
is not. XXX C99 is silent on this rule, but it seems
inconsistent to me. */
if (i == 1 && nargs != 1)
{ {
register U_CHAR *bp = ARG_BASE + args[0].raw; register U_CHAR *bp = ARG_BASE + args[0].raw;
register U_CHAR *lim = bp + args[0].raw_length; register U_CHAR *lim = bp + args[0].raw_length;
/* cpp.texi says for foo ( ) we provide one argument.
However, if foo wants just 0 arguments, treat this as 0. */
if (nargs == 0)
while (bp != lim && is_space(*bp)) while (bp != lim && is_space(*bp))
bp++; bp++;
if (bp == lim) if (bp == lim)
...@@ -1410,6 +1410,10 @@ unsafe_chars (pfile, c1, c2) ...@@ -1410,6 +1410,10 @@ unsafe_chars (pfile, c1, c2)
cpp_reader *pfile; cpp_reader *pfile;
int c1, c2; int c1, c2;
{ {
/* If c2 is EOF, that's always safe. */
if (c2 == EOF)
return 0;
switch (c1) switch (c1)
{ {
case EOF: case EOF:
...@@ -1491,14 +1495,13 @@ push_macro_expansion (pfile, xbuf, len, hp) ...@@ -1491,14 +1495,13 @@ push_macro_expansion (pfile, xbuf, len, hp)
/* Likewise, avoid the extra space at the end of the macro expansion /* Likewise, avoid the extra space at the end of the macro expansion
if this is safe. We can do a better job here since we can know if this is safe. We can do a better job here since we can know
what the next char will be. */ what the next char will be. */
if (len >= 3 if (len >= 3 && xbuf[len-2] == '\r' && xbuf[len-1] == ' '
&& xbuf[len-2] == '\r' && !unsafe_chars (pfile, xbuf[len-3], CPP_BUF_PEEK (CPP_BUFFER (pfile))))
&& xbuf[len-1] == ' ')
{
int c = CPP_BUF_PEEK (CPP_BUFFER (pfile));
if (c == EOF || !unsafe_chars (pfile, xbuf[len-3], c))
len -= 2; len -= 2;
}
/* If the total expansion is "\r \r", we must not trim both escapes. */
if (len == 2 && advance_cur)
advance_cur = 0;
mbuf = cpp_push_buffer (pfile, xbuf, len); mbuf = cpp_push_buffer (pfile, xbuf, len);
if (mbuf == NULL) if (mbuf == NULL)
......
2000-04-19 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/20000419-1.c: New test.
Wed Apr 12 10:25:08 2000 Jeffrey A Law (law@cygnus.com) Wed Apr 12 10:25:08 2000 Jeffrey A Law (law@cygnus.com)
* gcc.c-torture/execute/20000412-5.c: New test. * gcc.c-torture/execute/20000412-5.c: New test.
......
/* Test for erroneous deletion of the entire macro expansion when pruning
\r escapes. Problem noted by DJ Delorie <dj@delorie.com>; test case
distilled from GNU libc header files. */
/* { dg-do preprocess } */
#define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
#define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
#define __ASMNAME2(prefix, cname) __STRING (prefix) cname
#define __STRING(x) #x
__REDIRECT (a, b, c)
__ASMNAME2 (__USER_LABEL_PREFIX__, harumph)
/* { dg-bogus "used without args" "no args, 1" { target native } 11 } */
/* { dg-bogus "used without args" "no args, 1" { target native } 12 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment