From 179652df338a0dfe4e121cb6b88164a723d91528 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 19 Feb 2014 07:05:55 +0100 Subject: [PATCH] re PR preprocessor/58844 (ICE with invalid use of ##) 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. From-SVN: r207871 --- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/c-c++-common/cpp/pr58844-1.c | 8 +++++++ gcc/testsuite/c-c++-common/cpp/pr58844-2.c | 8 +++++++ libcpp/ChangeLog | 8 +++++++ libcpp/macro.c | 25 ++++++++++------------ 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/cpp/pr58844-1.c create mode 100644 gcc/testsuite/c-c++-common/cpp/pr58844-2.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6ca256022a5..f64bb4f0170 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-02-19 Jakub Jelinek + + PR preprocessor/58844 + * c-c++-common/cpp/pr58844-1.c: New test. + * c-c++-common/cpp/pr58844-2.c: New test. + 2014-02-18 Paolo Carlini PR c++/60225 diff --git a/gcc/testsuite/c-c++-common/cpp/pr58844-1.c b/gcc/testsuite/c-c++-common/cpp/pr58844-1.c new file mode 100644 index 00000000000..3abf8a76803 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr58844-1.c @@ -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" } */ diff --git a/gcc/testsuite/c-c++-common/cpp/pr58844-2.c b/gcc/testsuite/c-c++-common/cpp/pr58844-2.c new file mode 100644 index 00000000000..1e219152fc5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr58844-2.c @@ -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" } */ diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index b7f2011190e..44736e0b9f1 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2014-02-19 Jakub Jelinek + + 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). + 2014-02-07 Jakub Jelinek PR preprocessor/56824 diff --git a/libcpp/macro.c b/libcpp/macro.c index 1700ac0ddfe..11e50f4849c 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1115,21 +1115,22 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, 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, cpp_hashnode *node, 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)