cpplex.c (ON_REST_ARG): Correct the test.
authorNeil Booth <neilb@earthling.net>
Fri, 15 Sep 2000 05:55:36 +0000 (05:55 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Fri, 15 Sep 2000 05:55:36 +0000 (05:55 +0000)
* cpplex.c (ON_REST_ARG): Correct the test.
(maybe_paste_with_next): Duplicate a token that fail pasting,
and clear its PASTE_LEFT flag, so that nested pasting attempts
do not occur.
* gcc.dg/cpp/paste10.c: Testcase.

From-SVN: r36424

gcc/ChangeLog
gcc/cpplex.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/paste10.c [new file with mode: 0644]

index 8e6a9d8d016a40e67a4bd44ceeca59aba2085080..455422411244865b0acb105309fbd38a229912e9 100644 (file)
@@ -1,3 +1,10 @@
+Fri 15-Sep-2000 06:49:07 BST  Neil Booth  <NeilB@earthling.net>
+
+       * cpplex.c (ON_REST_ARG): Correct the test.
+       (maybe_paste_with_next): Duplicate a token that fail pasting,
+       and clear its PASTE_LEFT flag, so that nested pasting attempts
+       do not occur.
+
 2000-09-14  Richard Henderson  <rth@cygnus.com>
 
        * calls.c (precompute_register_parameters): Use COSTS_N_INSNS, not 2.
index 5cb6b7f7611f3c25b0513f3e43732b1b8ad62571..56b8543f995dee9cb8f1e8fddf56a5459dc43b1d 100644 (file)
@@ -201,9 +201,9 @@ TOKEN_LEN (token)
 #define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
 #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
 #define ON_REST_ARG(c) \
- (((c)->flags & VAR_ARGS) \
-  && ((c)-1)->u.list->tokens[((c)-1)->posn - 1].val.aux \
-      == (unsigned int) (((c)-1)->u.list->paramc - 1))
+ (((c)->u.list->flags & VAR_ARGS) \
+  && (c)->u.list->tokens[(c)->posn - 1].val.aux \
+      == (unsigned int) ((c)->u.list->paramc - 1))
 
 #define ASSIGN_FLAGS_AND_POS(d, s) \
   do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
@@ -2787,14 +2787,17 @@ maybe_paste_with_next (pfile, token)
                     the special extended semantics (see above).  */
                  if (token->type == CPP_COMMA
                      && IS_ARG_CONTEXT (CURRENT_CONTEXT (pfile))
-                     && ON_REST_ARG (CURRENT_CONTEXT (pfile)))
+                     && ON_REST_ARG (CURRENT_CONTEXT (pfile) - 1))
                    /* no warning */;
                  else
                    cpp_warning (pfile,
                        "pasting would not give a valid preprocessing token");
                }
              _cpp_push_token (pfile, second);
-             return token;
+             /* A short term hack to safely clear the PASTE_LEFT flag.  */
+             pasted = duplicate_token (pfile, token);
+             pasted->flags &= ~PASTE_LEFT;
+             return pasted;
            }
 
          if (type == CPP_NAME || type == CPP_NUMBER)
index 78eec4572571fdb0e18c66527960d7bfd0cd84a7..54d0fa9297b33263eaab1913e06364f8b3804e86 100644 (file)
@@ -1,3 +1,7 @@
+Fri 15-Sep-2000 06:50:11 BST  Neil Booth  <NeilB@earthling.net>
+
+       * gcc.dg/cpp/paste10.c: Testcase for PASTE_LEFT buglet.
+
 Thu Sep 14 16:48:49 2000  Jeffrey A Law  (law@cygnus.com)
 
        * gcc.c-torture/execute/20000914-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/paste10.c b/gcc/testsuite/gcc.dg/cpp/paste10.c
new file mode 100644 (file)
index 0000000..ab3cb90
--- /dev/null
@@ -0,0 +1,15 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+/* This testcase used to produce a bogus "invalid paste" warning, owing
+   to not clearing a PASTE_LEFT flag.  */
+
+#define strcpy(src) __strcpy_small (src)
+
+#define __strcpy_small(src) src
+
+#define tprintf(format, args...) sprintf(format, ## args)
+
+strcpy(tprintf("<%s>", test))