]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR preprocessor/58844 (ICE with invalid use of ##)
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Mar 2014 08:10:08 +0000 (09:10 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 6 Mar 2014 08:10:08 +0000 (09:10 +0100)
Backport from mainline
2014-02-19  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.

From-SVN: r208370

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cpp/pr58844-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/cpp/pr58844-2.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/macro.c

index 425cbf690faf334e52e47c0d0ee8fb586f72d5cc..253b0a65b18d0969a03d2cb88c8fcea039a9d1dd 100644 (file)
@@ -1,6 +1,12 @@
 2014-03-06  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2014-02-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/58844
+       * c-c++-common/cpp/pr58844-1.c: New test.
+       * c-c++-common/cpp/pr58844-2.c: New test.
+
        2014-02-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/43546
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 (file)
index 0000000..3abf8a7
--- /dev/null
@@ -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 (file)
index 0000000..1e21915
--- /dev/null
@@ -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" } */
index 9fc829cf47f0668e2c80b30fed88e10831f2e26d..8ab4511ec08b43a63f006caec407036beb2cb5f0 100644 (file)
@@ -1,6 +1,14 @@
 2014-03-06  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2014-02-19  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).
+
        2014-02-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/56824
index 6d46027e4ea4a0e36ff0b98d18ee071917ddf7cf..f2b7d0b9079fbc910ab802c1936d31d59985aace 100644 (file)
@@ -1108,21 +1108,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,
@@ -1134,16 +1135,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)