]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/60197 (ICE with _Cilk_spawn in expression)
authorMarek Polacek <polacek@redhat.com>
Thu, 6 Mar 2014 13:41:46 +0000 (13:41 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 6 Mar 2014 13:41:46 +0000 (13:41 +0000)
PR c/60197
c-family/
* cilk.c (contains_cilk_spawn_stmt): New function.
(contains_cilk_spawn_stmt_walker): Likewise.
(recognize_spawn): Give error on invalid use of _Cilk_spawn.
* c-common.h (contains_cilk_spawn_stmt): Add declaration.
c/
* c-typeck.c (c_finish_return): Call contains_cilk_spawn_stmt instead
of checking tree code.
cp/
* typeck.c (check_return_expr): Call contains_cilk_spawn_stmt instead
of checking tree code.
testsuite/
* c-c++-common/cilk-plus/CK/pr60197.c: New test.
* c-c++-common/cilk-plus/CK/pr60197-2.c: New test.

From-SVN: r208382

gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/cilk.c
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197.c [new file with mode: 0644]

index a775d4c33817fd514b4b7e7cdf730fe2debb3aa2..0c22f894aef6196aebb23e8a96ef286ced9ad6d7 100644 (file)
@@ -1,3 +1,11 @@
+2014-03-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60197
+       * cilk.c (contains_cilk_spawn_stmt): New function.
+       (contains_cilk_spawn_stmt_walker): Likewise.
+       (recognize_spawn): Give error on invalid use of _Cilk_spawn.
+       * c-common.h (contains_cilk_spawn_stmt): Add declaration.
+
 2014-03-03  Jakub Jelinek  <jakub@redhat.com>
 
        * c-pragma.c (c_pp_lookup_pragma): Handle PRAGMA_CILK_SIMD.
index f074ab1887bc758ffcf4dd777732518e6f438b72..1099b108950822e11a50e6f3c41eebd9066323ae 100644 (file)
@@ -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 */
index f2179dfc128a9b7ee6f7ab9cc657211680111953..6a7bf4f1efa2f626815937e1e73b81c9bd22f7a4 100644 (file)
@@ -235,6 +235,9 @@ recognize_spawn (tree exp, tree *exp0)
       walk_tree (exp0, unwrap_cilk_spawn_stmt, NULL, NULL);
       spawn_found = true;
     }
+  /* _Cilk_spawn can't be wrapped in expression such as PLUS_EXPR.  */
+  else if (contains_cilk_spawn_stmt (exp))
+    error ("invalid use of %<_Cilk_spawn%>");
   return spawn_found;
 }
 
@@ -1292,3 +1295,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;
+}
index 5e482a3a22ad3f876d92f98ebf44ac0f56642c4c..e9d25d5b86660e0cf2f571748525403b669674fb 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60197
+       * c-typeck.c (c_finish_return): Call contains_cilk_spawn_stmt instead
+       of checking tree code.
+
 2014-02-19  Prathamesh Kulkarni  <bilbotheelffriend@gmail.com>
 
        * c-parser.c (c_parser_declspecs): Replace call to error by error_at.
index 2b542903ba9a9d76a42d62300bc90d8f21a13b21..7c4ba0eb2254422269ba99c92579046bb5946666 100644 (file)
@@ -9140,7 +9140,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");
index 70db35c1de9991ca2fa7fbdc3505115d4016e74b..4aa9c2b75118348f15549eeae4f8428aaa8935fd 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60197
+       * typeck.c (check_return_expr): Call contains_cilk_spawn_stmt instead
+       of checking tree code.
+
 2014-03-06  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * parser.c (cp_lexer_set_source_position): New.
index 29f9e9daaee9022be979efe156de78da5526a55b..ae2e5038e18aa95b1b75e3211768a8f2c96e12a7 100644 (file)
@@ -8332,7 +8332,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");
index d9e6105d70d3ec2ba99b6b666bb5052c7d77e55b..779fa96a737ae3796d7a60ee50e976b152de4b36 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60197
+       * c-c++-common/cilk-plus/CK/pr60197.c: New test.
+       * c-c++-common/cilk-plus/CK/pr60197-2.c: New test.
+
 2014-03-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/58595
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197-2.c b/gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197-2.c
new file mode 100644 (file)
index 0000000..1e5ca00
--- /dev/null
@@ -0,0 +1,35 @@
+/* PR c/60197 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+extern int foo (void);
+
+int
+fn1 (void)
+{
+  int i;
+  i = (_Cilk_spawn foo ()) + 1; /* { dg-error "invalid use of" } */
+  return i;
+}
+
+int
+fn2 (void)
+{
+  int i = (_Cilk_spawn foo ()) + 1; /* { dg-error "invalid use of" } */
+  return i;
+}
+
+int
+fn3 (int j, int k, int l)
+{
+  int i = (((((_Cilk_spawn foo ()) + 1) - l) * k) / j); /* { dg-error "invalid use of" } */
+  return i;
+}
+
+int
+fn4 (int j, int k, int l)
+{
+  int i;
+  i = (((((_Cilk_spawn foo ()) + 1) - l) * k) / j); /* { dg-error "invalid use of" } */
+  return i;
+}
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197.c b/gcc/testsuite/c-c++-common/cilk-plus/CK/pr60197.c
new file mode 100644 (file)
index 0000000..2b47d1e
--- /dev/null
@@ -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" } */
+}