@@ -1389,4 +1389,5 @@ extern tree make_cilk_frame (tree);
extern tree create_cilk_function_exit (tree, bool, bool);
extern tree cilk_install_body_pedigree_operations (tree);
extern void cilk_outline (tree, tree *, void *);
+extern bool contains_cilk_spawn_stmt (tree);
#endif /* ! GCC_C_COMMON_H */
@@ -1292,3 +1292,25 @@ build_cilk_sync (void)
TREE_SIDE_EFFECTS (sync) = 1;
return sync;
}
+
+/* Helper for contains_cilk_spawn_stmt, callback for walk_tree. Return
+ non-null tree if TP contains CILK_SPAWN_STMT. */
+
+static tree
+contains_cilk_spawn_stmt_walker (tree *tp, int *, void *)
+{
+ if (TREE_CODE (*tp) == CILK_SPAWN_STMT)
+ return *tp;
+ else
+ return NULL_TREE;
+}
+
+/* Returns true if EXPR or any of its subtrees contain CILK_SPAWN_STMT
+ node. */
+
+bool
+contains_cilk_spawn_stmt (tree expr)
+{
+ return walk_tree (&expr, contains_cilk_spawn_stmt_walker, NULL, NULL)
+ != NULL_TREE;
+}
@@ -9134,7 +9134,7 @@ c_finish_return (location_t loc, tree retval, tree origtype)
return error_mark_node;
}
}
- if (flag_cilkplus && retval && TREE_CODE (retval) == CILK_SPAWN_STMT)
+ if (flag_cilkplus && retval && contains_cilk_spawn_stmt (retval))
{
error_at (loc, "use of %<_Cilk_spawn%> in a return statement is not "
"allowed");
@@ -8328,7 +8328,7 @@ check_return_expr (tree retval, bool *no_warning)
*no_warning = false;
- if (flag_cilkplus && retval && TREE_CODE (retval) == CILK_SPAWN_STMT)
+ if (flag_cilkplus && retval && contains_cilk_spawn_stmt (retval))
{
error_at (EXPR_LOCATION (retval), "use of %<_Cilk_spawn%> in a return "
"statement is not allowed");
@@ -0,0 +1,66 @@
+/* PR c/60197 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+extern int foo (void);
+extern int bar (int);
+
+int
+fn1 (void)
+{
+ return (_Cilk_spawn foo ()) * 2; /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn2 (void)
+{
+ return (_Cilk_spawn foo ()) > 2; /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn3 (int i, int j, int k)
+{
+ return ((((((_Cilk_spawn foo () + i) - j) * k) / j) | i) ^ k) ; /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn4 (int i, int j, int k)
+{
+ return (((((i - _Cilk_spawn foo ()) * k) / j) | i) ^ k); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn5 (void)
+{
+ return _Cilk_spawn foo (); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn6 (void)
+{
+ return _Cilk_spawn foo () + _Cilk_spawn foo (); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn7 (void)
+{
+ return 5 % _Cilk_spawn foo (); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn8 (void)
+{
+ return !_Cilk_spawn foo (); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn9 (void)
+{
+ return foo () && _Cilk_spawn foo (); /* { dg-error "in a return statement is not allowed" } */
+}
+
+int
+fn10 (void)
+{
+ return bar (_Cilk_spawn foo ()); /* { dg-error "in a return statement is not allowed" } */
+}