[gomp] Fix placement of TRY_CATCH_EXPR if clauses have ctor/dtors (PR middle-end/27325)

Jakub Jelinek jakub@redhat.com
Fri Apr 28 11:41:00 GMT 2006


Hi!

The following testcase ICEs in find_outermost_region_in_block.
The reason is that TRY_CATCH_EXPR created by maybe_catch_exception doesn't
cover also ctors/dtors, so there really is not an outermost EH region.
The following patch fixes this, ok for trunk?

2006-04-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/27325
	* omp-low.c (lower_omp_sections): Call maybe_catch_exception
	on statement list containing also constructors and destructors.
	(lower_omp_single, lower_omp_for, lower_omp_parallel): Likewise.

	* g++.dg/gomp/pr27325.C: New test.

--- gcc/omp-low.c.jj	2006-04-28 11:09:53.000000000 +0200
+++ gcc/omp-low.c	2006-04-28 12:47:46.000000000 +0200
@@ -3433,7 +3433,6 @@ lower_omp_sections (tree *stmt_p, omp_co
 
   block = make_node (BLOCK);
   bind = build3 (BIND_EXPR, void_type_node, NULL, body, block);
-  maybe_catch_exception (&BIND_EXPR_BODY (bind));
 
   olist = NULL_TREE;
   lower_reduction_clauses (OMP_SECTIONS_CLAUSES (stmt), &olist, ctx);
@@ -3455,6 +3454,8 @@ lower_omp_sections (tree *stmt_p, omp_co
   append_to_statement_list (olist, &new_body);
   append_to_statement_list (dlist, &new_body);
 
+  maybe_catch_exception (&new_body);
+
   t = make_node (OMP_RETURN);
   OMP_RETURN_NOWAIT (t) = !!find_omp_clause (OMP_SECTIONS_CLAUSES (stmt),
 					     OMP_CLAUSE_NOWAIT);
@@ -3590,7 +3591,6 @@ lower_omp_single (tree *stmt_p, omp_cont
   lower_rec_input_clauses (OMP_SINGLE_CLAUSES (single_stmt),
 			   &BIND_EXPR_BODY (bind), &dlist, ctx);
   lower_omp (&OMP_SINGLE_BODY (single_stmt), ctx);
-  maybe_catch_exception (&OMP_SINGLE_BODY (single_stmt));
 
   append_to_statement_list (single_stmt, &BIND_EXPR_BODY (bind));
 
@@ -3603,6 +3603,8 @@ lower_omp_single (tree *stmt_p, omp_cont
 
   append_to_statement_list (dlist, &BIND_EXPR_BODY (bind));
 
+  maybe_catch_exception (&BIND_EXPR_BODY (bind));
+
   t = make_node (OMP_RETURN);
   OMP_RETURN_NOWAIT (t) = !!find_omp_clause (OMP_SINGLE_CLAUSES (single_stmt),
 					     OMP_CLAUSE_NOWAIT);
@@ -3870,7 +3872,6 @@ lower_omp_for (tree *stmt_p, omp_context
 
   append_to_statement_list (stmt, body_p);
 
-  maybe_catch_exception (&OMP_FOR_BODY (stmt));
   append_to_statement_list (OMP_FOR_BODY (stmt), body_p);
 
   t = make_node (OMP_CONTINUE);
@@ -3881,6 +3882,8 @@ lower_omp_for (tree *stmt_p, omp_context
   lower_reduction_clauses (OMP_FOR_CLAUSES (stmt), body_p, ctx);
   append_to_statement_list (dlist, body_p);
 
+  maybe_catch_exception (body_p);
+
   /* Region exit marker goes at the end of the loop body.  */
   t = make_node (OMP_RETURN);
   OMP_RETURN_NOWAIT (t) = fd.have_nowait;
@@ -3918,7 +3921,6 @@ lower_omp_parallel (tree *stmt_p, omp_co
   par_ilist = NULL_TREE;
   lower_rec_input_clauses (clauses, &par_ilist, &par_olist, ctx);
   lower_omp (&par_body, ctx);
-  maybe_catch_exception (&par_body);
   lower_reduction_clauses (clauses, &par_olist, ctx);
 
   /* Declare all the variables created by mapping and the variables
@@ -3954,6 +3956,7 @@ lower_omp_parallel (tree *stmt_p, omp_co
   append_to_statement_list (par_ilist, &new_body);
   append_to_statement_list (par_body, &new_body);
   append_to_statement_list (par_olist, &new_body);
+  maybe_catch_exception (&new_body);
   t = make_node (OMP_RETURN);
   append_to_statement_list (t, &new_body);
   OMP_PARALLEL_BODY (stmt) = new_body;
--- gcc/testsuite/g++.dg/gomp/pr27325.C.jj	2006-04-28 13:26:14.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/pr27325.C	2006-04-28 13:25:37.000000000 +0200
@@ -0,0 +1,25 @@
+// PR middle-end/27325 
+// { dg-do compile }
+// { dg-options "-O2 -fopenmp" }
+
+struct A { A(); ~A(); int i; };
+
+int
+foo ()
+{
+  A a;
+#pragma omp parallel private (a)
+  for (int i = 0; i < 5; ++i)
+    a.i++;
+  return 0;
+}
+
+int
+bar ()
+{
+  A a;
+#pragma omp for private (a)
+  for (int i = 0; i < 5; ++i)
+    a.i++;
+  return 0;
+}

	Jakub



More information about the Gcc-patches mailing list