Fix token pasting with -ftrack-macro-expansion
authorDodji Seketeli <dodji@redhat.com>
Mon, 30 Apr 2012 11:41:21 +0000 (11:41 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Mon, 30 Apr 2012 11:41:21 +0000 (13:41 +0200)
This patch makes token pasting work with -ftrack-macro-expansion
turned on.  It improves some pasting related tests of the gcc.dg/cpp
subdirectory.

Tested and bootstrapped on x86_64-unknown-linux-gnu against trunk.

Note that the bootstrap with -ftrack-macro-expansion exhibits other
separate issues that are addressed in subsequent patches.  This patch
just fixes one class of problems.

The patch does pass bootstrap with -ftrack-macro-expansion turned off,
though.

libcpp/

* macro.c (paste_all_tokens): Put the token resulting from pasting
into an extended token context with -ftrack-macro-location is in
effect.

gcc/testsuite/

* gcc.dg/cpp/paste17.c: New test case for
-ftrack-macro-expansion=2 mode only.
* gcc.dg/cpp/macro-exp-tracking-5.c: Likewise.

From-SVN: r186966

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/paste17.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/macro.c

index 45bda58a0792204b549e19e4fdd12dafc18e5036..c7f6419c652ace56228aa10728e8ba0e6a306504 100644 (file)
@@ -1,3 +1,10 @@
+2012-04-30  Dodji Seketeli  <dodji@redhat.com>
+
+       Fix token pasting with -ftrack-macro-expansion
+       * gcc.dg/cpp/paste17.c: New test case for
+       -ftrack-macro-expansion=2 mode only.
+       * gcc.dg/cpp/macro-exp-tracking-5.c: Likewise.
+
 2012-04-30  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/warn6.ad[sb]: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c b/gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c
new file mode 100644 (file)
index 0000000..7933660
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+  { dg-options "-fshow-column -ftrack-macro-expansion" }
+  { dg-do compile }
+ */
+
+#define PASTED var ## iable /* { dg-error "undeclared" } */
+#define call_foo(p1, p2) \
+  foo (p1,              \
+       p2);  /*  { dg-message "in expansion of macro" } */
+
+void foo(int, char);
+
+void
+bar()
+{
+  call_foo(1,PASTED); /* { dg-message "expanded from here" } */
+}
+
diff --git a/gcc/testsuite/gcc.dg/cpp/paste17.c b/gcc/testsuite/gcc.dg/cpp/paste17.c
new file mode 100644 (file)
index 0000000..9c6506f
--- /dev/null
@@ -0,0 +1,8 @@
+ /* { dg-options "-ftrack-macro-expansion=2" } */
+/* { dg-do preprocess } */
+
+#define do_paste 1.0e ## -1
+
+do_paste
+
+/* { dg-final {scan-file paste17.i "1.0e- 1" } }*/
index c4f7c5af01a69eaaf344fccf9b79d78a27e272fa..189f394418e266d3d4caed523ce106017de52e5a 100644 (file)
@@ -1,5 +1,10 @@
 2012-04-30  Dodji Seketeli  <dodji@redhat.com>
 
+       Fix token pasting with -ftrack-macro-expansion
+       * macro.c (paste_all_tokens): Put the token resulting from pasting
+       into an extended token context with -ftrack-macro-location is in
+       effect.
+
        Fix cpp_sys_macro_p with -ftrack-macro-expansion
        * macro.c (cpp_sys_macro_p):  Support -ftrack-macro-expansion.
 
index 4f8e52f22cfbb12856acf25c78b749b5f909fe9c..f4638c49cd99f0e418ac8e3cad862ffaf5e98c69 100644 (file)
@@ -611,6 +611,21 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs)
 {
   const cpp_token *rhs = NULL;
   cpp_context *context = pfile->context;
+  source_location virt_loc = 0;
+
+  /* We must have been called on a token that appears at the left
+     hand side of a ## operator.  */
+  if (!(lhs->flags & PASTE_LEFT))
+    abort ();
+
+  if (context->tokens_kind == TOKENS_KIND_EXTENDED)
+    /* The caller must have called consume_next_token_from_context
+       right before calling us.  That has incremented the pointer to
+       the current virtual location.  So it now points to the location
+       of the token that comes right after *LHS.  We want the
+       resulting pasted token to have the location of the current
+       *LHS, though.  */
+    virt_loc = context->c.mc->cur_virt_loc[-1];
 
   do
     {
@@ -650,7 +665,18 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs)
   while (rhs->flags & PASTE_LEFT);
 
   /* Put the resulting token in its own context.  */
-  _cpp_push_token_context (pfile, NULL, lhs, 1);
+  if (context->tokens_kind == TOKENS_KIND_EXTENDED)
+    {
+      source_location *virt_locs = NULL;
+      _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs);
+      tokens_buff_add_token (token_buf, virt_locs, lhs,
+                            virt_loc, 0, NULL, 0);
+      push_extended_tokens_context (pfile, context->c.mc->macro_node,
+                                   token_buf, virt_locs,
+                                   (const cpp_token **)token_buf->base, 1);
+    }
+  else
+    _cpp_push_token_context (pfile, NULL, lhs, 1);
 }
 
 /* Returns TRUE if the number of arguments ARGC supplied in an