This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] cpp token pasting fix
- To: Zack Weinberg <zack at wolery dot cumb dot org>
- Subject: [PATCH] cpp token pasting fix
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 31 Jul 2000 18:59:04 +0200
- Cc: gcc-patches at gcc dot gnu dot org
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
The attached patch fixes the included testcase (originally from soft-fp).
There are no testsuite regressions with this, I'm now going to compile some
gigs of sourcecodes to see whether it really does not break anything.
2000-07-31 Jakub Jelinek <jakub@redhat.com>
* cpplex.c (_cpp_get_token): Don't macro expand a just pasted
token if it was pasted at no_expand_level.
* testsuite/gcc.dg/cpp/paste7.c: New test.
--- gcc/testsuite/gcc.dg/cpp/paste7.c.jj Mon Jul 31 18:18:33 2000
+++ gcc/testsuite/gcc.dg/cpp/paste7.c Mon Jul 31 18:37:18 2000
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+#define D_2 1, 2
+#define C_2(X, I0, I1) X##_a = I0, X##_b = I1
+#define B_2(X, I) C_2(X, I)
+#define A(N, X) B_##N (X, D_##N)
+
+extern void abort(void);
+extern void exit(int);
+
+int x_a, x_b;
+
+int main(void)
+{
+ A(2, x);
+ if (x_a != 1 || x_b != 2)
+ abort();
+ exit(0);
+}
--- gcc/cpplex.c.jj Mon Jul 31 14:13:16 2000
+++ gcc/cpplex.c Mon Jul 31 17:04:03 2000
@@ -3079,7 +3079,7 @@ const cpp_token *
_cpp_get_token (pfile)
cpp_reader *pfile;
{
- const cpp_token *token;
+ const cpp_token *token, *old_token;
cpp_hashnode *node;
/* Loop until we hit a non-macro token. */
@@ -3108,6 +3108,8 @@ _cpp_get_token (pfile)
be taken as a control macro. */
pfile->potential_control_macro = 0;
+ old_token = token;
+
/* See if there's a token to paste with this one. */
if (!pfile->paste_level)
token = maybe_paste_with_next (pfile, token);
@@ -3117,8 +3119,10 @@ _cpp_get_token (pfile)
return token;
/* Is macro expansion disabled in general, or are we in the
- middle of a token paste? */
- if (pfile->no_expand_level == pfile->cur_context || pfile->paste_level)
+ middle of a token paste, or was this token just pasted? */
+ if (pfile->no_expand_level == pfile->cur_context || pfile->paste_level
+ || (old_token != token && pfile->no_expand_level != -1
+ && pfile->no_expand_level + 1 == pfile->cur_context))
return token;
node = token->val.node;
Jakub