diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-04-19 20:53:06 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-04-19 20:53:06 +0000 |
commit | 0d5a06bd0b6e6b8a71fe8707ce0a93915c5a86e3 (patch) | |
tree | c18dfee98cd0004a33f644025c4dfb4c94a3a231 /gcc | |
parent | b13fe8bfb261f1f8239507d4316cd2d0b158d990 (diff) | |
download | gcc-0d5a06bd0b6e6b8a71fe8707ce0a93915c5a86e3.zip gcc-0d5a06bd0b6e6b8a71fe8707ce0a93915c5a86e3.tar.gz gcc-0d5a06bd0b6e6b8a71fe8707ce0a93915c5a86e3.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cpphash.c | 31 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/20000419-1.c | 15 |
4 files changed, 46 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d2661d2..86d0cb3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +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> * dwarf2out.c (DWARF2_ADDR_SIZE): New macro. Use it instead diff --git a/gcc/cpphash.c b/gcc/cpphash.c index 6f28295..70d1147 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -908,7 +908,7 @@ special_symbol (hp, pfile) if (!buf) return; if (*buf == '\0') - buf = "\r "; + buf = "\r \r "; CPP_PUTS (pfile, buf, strlen (buf)); return; @@ -1075,14 +1075,14 @@ _cpp_macroexpand (pfile, hp) if (token != CPP_RPAREN) return; - /* If we got one arg but it was just whitespace, call that 0 args. */ - if (i == 1) + /* foo ( ) is equivalent to foo () unless foo takes exactly one + 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 *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)) bp++; if (bp == lim) @@ -1410,6 +1410,10 @@ unsafe_chars (pfile, c1, c2) cpp_reader *pfile; int c1, c2; { + /* If c2 is EOF, that's always safe. */ + if (c2 == EOF) + return 0; + switch (c1) { case EOF: @@ -1491,14 +1495,13 @@ push_macro_expansion (pfile, xbuf, len, hp) /* 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 what the next char will be. */ - if (len >= 3 - && xbuf[len-2] == '\r' - && xbuf[len-1] == ' ') - { - int c = CPP_BUF_PEEK (CPP_BUFFER (pfile)); - if (c == EOF || !unsafe_chars (pfile, xbuf[len-3], c)) - len -= 2; - } + if (len >= 3 && xbuf[len-2] == '\r' && xbuf[len-1] == ' ' + && !unsafe_chars (pfile, xbuf[len-3], CPP_BUF_PEEK (CPP_BUFFER (pfile)))) + 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); if (mbuf == NULL) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3dd9f9..58dc414 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +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) * gcc.c-torture/execute/20000412-5.c: New test. diff --git a/gcc/testsuite/gcc.dg/20000419-1.c b/gcc/testsuite/gcc.dg/20000419-1.c new file mode 100644 index 0000000..1e1b660 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20000419-1.c @@ -0,0 +1,15 @@ +/* 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 } */ |