This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix -ftrack-macro-expansion preprocessing of A######A (PR preprocessor/58844)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>, Dodji Seketeli <dseketel at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 18 Feb 2014 18:29:12 +0100
- Subject: [PATCH] Fix -ftrack-macro-expansion preprocessing of A######A (PR preprocessor/58844)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The following testcase build with -ftrack-macro-expansion=0,
but don't build otherwise. The problem seems to be that
the libcpp for macro redefinition warning/error purposes if it sees
more than one paste operator adds those extra CPP_PASTE tokens at the end,
after normal tokens from the macro. For -ftrack-macro-expansion=0 we were
using macro_real_token_count (macro) to only use the real tokens for macro
expansion purposes, but for track_macro_expansion it used macro->count,
which includes also the extra tokens.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk (and after a while for 4.8)?
2014-02-18 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/58844
* macro.c (enter_macro_context): Only push
macro_real_token_count (macro) tokens rather than
macro->count tokens, regardless of
CPP_OPTION (pfile, track-macro-expansion).
* c-c++-common/cpp/pr58844-1.c: New test.
* c-c++-common/cpp/pr58844-2.c: New test.
--- libcpp/macro.c.jj 2014-01-03 11:42:25.000000000 +0100
+++ libcpp/macro.c 2014-02-18 12:20:30.679451456 +0100
@@ -1115,21 +1115,22 @@ enter_macro_context (cpp_reader *pfile,
if (macro->paramc == 0)
{
+ unsigned tokens_count = macro_real_token_count (macro);
if (CPP_OPTION (pfile, track_macro_expansion))
{
- unsigned int i, count = macro->count;
+ unsigned int i;
const cpp_token *src = macro->exp.tokens;
const struct line_map *map;
source_location *virt_locs = NULL;
- _cpp_buff *macro_tokens =
- tokens_buff_new (pfile, count, &virt_locs);
+ _cpp_buff *macro_tokens
+ = tokens_buff_new (pfile, tokens_count, &virt_locs);
/* Create a macro map to record the locations of the
tokens that are involved in the expansion. LOCATION
is the location of the macro expansion point. */
- map = linemap_enter_macro (pfile->line_table,
- node, location, count);
- for (i = 0; i < count; ++i)
+ map = linemap_enter_macro (pfile->line_table,
+ node, location, tokens_count);
+ for (i = 0; i < tokens_count; ++i)
{
tokens_buff_add_token (macro_tokens, virt_locs,
src, src->src_loc,
@@ -1141,16 +1142,12 @@ enter_macro_context (cpp_reader *pfile,
virt_locs,
(const cpp_token **)
macro_tokens->base,
- count);
- num_macro_tokens_counter += count;
+ tokens_count);
}
else
- {
- unsigned tokens_count = macro_real_token_count (macro);
- _cpp_push_token_context (pfile, node, macro->exp.tokens,
- tokens_count);
- num_macro_tokens_counter += tokens_count;
- }
+ _cpp_push_token_context (pfile, node, macro->exp.tokens,
+ tokens_count);
+ num_macro_tokens_counter += tokens_count;
}
if (pragma_buff)
--- gcc/testsuite/c-c++-common/cpp/pr58844-1.c.jj 2014-02-18 12:18:40.501075448 +0100
+++ gcc/testsuite/c-c++-common/cpp/pr58844-1.c 2014-02-18 12:18:12.000000000 +0100
@@ -0,0 +1,8 @@
+/* PR preprocessor/58844 */
+/* { dg-do compile } */
+/* { dg-options "-ftrack-macro-expansion=0" } */
+
+#define A x######x
+int A = 1;
+#define A x######x /* { dg-message "previous definition" } */
+#define A x##x /* { dg-warning "redefined" } */
--- gcc/testsuite/c-c++-common/cpp/pr58844-2.c.jj 2014-02-18 12:18:47.415034981 +0100
+++ gcc/testsuite/c-c++-common/cpp/pr58844-2.c 2014-02-18 12:18:53.375009859 +0100
@@ -0,0 +1,8 @@
+/* PR preprocessor/58844 */
+/* { dg-do compile } */
+/* { dg-options "-ftrack-macro-expansion=2" } */
+
+#define A x######x
+int A = 1;
+#define A x######x /* { dg-message "previous definition" } */
+#define A x##x /* { dg-warning "redefined" } */
Jakub