This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] fix c++24451


The RESULT_DECL associated with the RETURN_EXPR isn't present in
the function we split out from the parallel, leading to the ICE.
Easiest solution is not to add the return on error.  The C front
end structured block scan already deletes the statement.


r~


        * decl.c (check_omp_return): Return false on error.
        * cp-tree.h (check_omp_return): Update decl.
        * semantics.c (finish_return_stmt): Avoid adding return on error.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1144.4.15
diff -u -p -d -r1.1144.4.15 cp-tree.h
--- cp/cp-tree.h	21 Oct 2005 21:41:09 -0000	1.1144.4.15
+++ cp/cp-tree.h	21 Oct 2005 22:03:25 -0000
@@ -3807,7 +3807,7 @@ extern tree push_using_decl			(tree, tre
 extern tree declare_local_label			(tree);
 extern tree define_label			(location_t, tree);
 extern void check_goto				(tree);
-extern void check_omp_return			(void);
+extern bool check_omp_return			(void);
 extern tree make_typename_type			(tree, tree, enum tag_types, tsubst_flags_t);
 extern tree make_unbound_class_template		(tree, tree, tree, tsubst_flags_t);
 extern tree check_for_out_of_scope_variable	(tree);
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1403.4.11
diff -u -p -d -r1.1403.4.11 decl.c
--- cp/decl.c	21 Oct 2005 21:41:10 -0000	1.1403.4.11
+++ cp/decl.c	21 Oct 2005 22:03:27 -0000
@@ -2413,9 +2413,9 @@ check_goto (tree decl)
 }
 
 /* Check that a return is ok wrt OpenMP structured blocks.
-   Called by finish_return_stmt.  */
+   Called by finish_return_stmt.  Returns true if all is well.  */
 
-void
+bool
 check_omp_return (void)
 {
   struct cp_binding_level *b;
@@ -2423,8 +2423,9 @@ check_omp_return (void)
     if (b->kind == sk_omp)
       {
 	error ("invalid exit from OpenMP structured block");
-	return;
+	return false;
       }
+  return true;
 }
 
 /* Define a label, specifying the location in the source file.
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.475.4.14
diff -u -p -d -r1.475.4.14 semantics.c
--- cp/semantics.c	21 Oct 2005 21:41:10 -0000	1.475.4.14
+++ cp/semantics.c	21 Oct 2005 22:03:28 -0000
@@ -759,8 +759,8 @@ finish_return_stmt (tree expr)
 	  return finish_goto_stmt (cdtor_label);
 	}
     }
-  if (flag_openmp)
-    check_omp_return ();
+  if (flag_openmp && !check_omp_return ())
+    return error_mark_node;
 
   r = build_stmt (RETURN_EXPR, expr);
   TREE_NO_WARNING (r) |= no_warning;
Index: testsuite/g++.dg/gomp/block-8.C
===================================================================
RCS file: testsuite/g++.dg/gomp/block-8.C
diff -N testsuite/g++.dg/gomp/block-8.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/gomp/block-8.C	21 Oct 2005 22:03:30 -0000
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// PR 24451
+
+int foo()
+{
+  int i;
+
+  #pragma omp parallel for
+  for (i = 0; i < 10; ++i)
+    return 0;			// { dg-error "invalid exit" }
+}
Index: testsuite/gcc.dg/gomp/block-8.c
===================================================================
RCS file: testsuite/gcc.dg/gomp/block-8.c
diff -N testsuite/gcc.dg/gomp/block-8.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/gomp/block-8.c	21 Oct 2005 22:03:33 -0000
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// PR 24451
+
+int foo()
+{
+  int i;
+
+  #pragma omp parallel for
+  for (i = 0; i < 10; ++i)
+    return 0;			// { dg-error "invalid exit" }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]