Hi!

Apparently at least on invalid #pragma omp declare reduction,
when parsing the type-ids, the parser may allocate some declarators
of the declarator_obstack, which results in ICE at the end of translation
unit when declarator_obstack is not in the initial empty state.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

2014-02-04  Jakub Jelinek  <ja...@redhat.com>

        PR c++/58703
        * parser.c (cp_parser_omp_declare_reduction): Save and free
        declarator_obstack.

        * c-c++-common/gomp/pr58703.c: New test.

--- gcc/cp/parser.c.jj  2014-02-03 08:53:11.000000000 +0100
+++ gcc/cp/parser.c     2014-02-03 14:00:58.569308322 +0100
@@ -30623,6 +30623,10 @@ cp_parser_omp_declare_reduction (cp_pars
   cp_token *first_token;
   cp_token_cache *cp;
   int errs;
+  void *p;
+    
+  /* Get the high-water mark for the DECLARATOR_OBSTACK.  */
+  p = obstack_alloc (&declarator_obstack, 0);
 
   if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
     goto fail;
@@ -30731,6 +30735,9 @@ cp_parser_omp_declare_reduction (cp_pars
     {
      fail:
       cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+
+      /* Free any declarators allocated.  */
+      obstack_free (&declarator_obstack, p);
       return;
     }
 
@@ -30835,6 +30842,9 @@ cp_parser_omp_declare_reduction (cp_pars
     }
 
   cp_parser_require_pragma_eol (parser, pragma_tok);
+
+  /* Free any declarators allocated.  */
+  obstack_free (&declarator_obstack, p);
 }
 
 /* OpenMP 4.0
--- gcc/testsuite/c-c++-common/gomp/pr58703.c.jj        2014-02-03 
14:02:56.735693978 +0100
+++ gcc/testsuite/c-c++-common/gomp/pr58703.c   2014-02-03 14:02:37.000000000 
+0100
@@ -0,0 +1,6 @@
+/* PR c++/58703 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+#pragma omp declare reduction (+ : char[] : omp_out += omp_in) /* { dg-error 
"function or array type" } */
+#pragma omp declare reduction (+ : char() : omp_out += omp_in) /* { dg-error 
"function or array type" } */

        Jakub

Reply via email to