diff mbox

[C++] Restore declarator_obstack in cp_parser_omp_declare_reduction (PR c++/58703)

Message ID 20140204124301.GK12671@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 4, 2014, 12:43 p.m. UTC
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  <jakub@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.


	Jakub

Comments

Jason Merrill Feb. 4, 2014, 4:30 p.m. UTC | #1
How about putting the fail label at the end of the function so the 
cleanup code is only in one place?  OK either way.

Jason
diff mbox

Patch

--- 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" } */