diff options
author | Balaji V. Iyer <balaji.v.iyer@intel.com> | 2012-12-14 20:17:42 +0000 |
---|---|---|
committer | Balaji V. Iyer <balaji.v.iyer@intel.com> | 2012-12-14 20:17:42 +0000 |
commit | 1125812c02bef51600ff0ca7c7d15284aa1acbe9 (patch) | |
tree | 0ed4bf47c81b7f5f280fc8e99d13037cd27a942d | |
parent | 453e017cda6ec2e434029ac20a3d13007696b7be (diff) |
Reject const, volatile induction vars and invalid comparisons in Cilk_for.
+++ gcc/testsuite/ChangeLog.cilkplus
+2012-12-14 Balaji V. Iyer <balaji.v.iyer@intel.com>
+
+ * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c:
+ New test.
+ * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c:
+ Likewise.
+
+++ gcc/ChangeLog.cilkplus (working copy)
@@ -1,3 +1,11 @@
+2012-12-14 Balaji V. Iyer <balaji.v.iyer@intel.com>
+
+ * c/c-parser.c (c_parser_cilk_for_statement): Replaced unknown location with the
+ correct location value.
+ * c/c-typeck.c (c_finish_cilk_loop): Checked if the increment is one of
+ the following: !=, <=, <, >=, or >. Report error otherwise. Also
+ report error if the induction variable is constant or volatile.
+
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/cilkplus@194507 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog.cilkplus | 8 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 2 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 32 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog.cilkplus | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c | 18 |
6 files changed, 79 insertions, 5 deletions
diff --git a/gcc/ChangeLog.cilkplus b/gcc/ChangeLog.cilkplus index bd210e35205..2afb0830848 100644 --- a/gcc/ChangeLog.cilkplus +++ b/gcc/ChangeLog.cilkplus @@ -1,3 +1,11 @@ +2012-12-14 Balaji V. Iyer <balaji.v.iyer@intel.com> + + * c/c-parser.c (c_parser_cilk_for_statement): Replaced unknown location with the + correct location value. + * c/c-typeck.c (c_finish_cilk_loop): Checked if the increment is one of + the following: !=, <=, <, >=, or >. Report error otherwise. Also + report error if the induction variable is constant or volatile. + 2012-12-13 Balaji V. Iyer <balaji.v.iyer@intel.com> * tree-vect-loop.c (vect_determine_vectorization_factor): Added a diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 25ee5a381dc..d8e1eb0db2e 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -11918,7 +11918,7 @@ c_parser_cilk_for_statement (c_parser *parser, tree grain) c_cont_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_finish_cilk_loop (loc, cvar, cond, incr, body, c_cont_label, grain); - add_stmt (c_end_compound_stmt (UNKNOWN_LOCATION, block, true)); + add_stmt (c_end_compound_stmt (loc, block, true)); c_break_label = save_break; c_cont_label = save_cont; } diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index d39714967b7..144f057e095 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10970,7 +10970,7 @@ c_build_va_arg (location_t loc, tree expr, tree type) } void -c_finish_cilk_loop (location_t start_locus ATTRIBUTE_UNUSED, tree cvar, +c_finish_cilk_loop (location_t start_locus, tree cvar, tree cond, tree incr, tree body, tree clab, tree grain) { tree init; @@ -10982,12 +10982,12 @@ c_finish_cilk_loop (location_t start_locus ATTRIBUTE_UNUSED, tree cvar, if (!cond) { - error ("_Cilk_for missing condition"); + error_at (start_locus, "_Cilk_for missing condition"); return; } if (!incr) { - error ("_Cilk_for missing increment"); + error_at (start_locus, "_Cilk_for missing increment"); return; } @@ -10999,7 +10999,7 @@ c_finish_cilk_loop (location_t start_locus ATTRIBUTE_UNUSED, tree cvar, } if (!cvar) { - error ("missing control variable"); + error_at (start_locus, "missing control variable"); return; } if (clab) @@ -11007,7 +11007,31 @@ c_finish_cilk_loop (location_t start_locus ATTRIBUTE_UNUSED, tree cvar, error_at (EXPR_LOCATION (clab), "_Cilk_for has continue"); return; } + + /* Checks if cond expr is one of the following: !=, <=, <, >=, or >. */ + if (TREE_CODE (cond) != NE_EXPR + && TREE_CODE (cond) != LT_EXPR + && TREE_CODE (cond) != LE_EXPR + && TREE_CODE (cond) != GT_EXPR + && TREE_CODE (cond) != GE_EXPR) + { + error_at (EXPR_LOCATION (cond), "_Cilk_for condition must be one of the " + "following: !=, <=, <, >= or >"); + return; + } + /* Checks if the induction variable is volatile or constant. */ + if (TREE_THIS_VOLATILE (cvar)) + { + error_at (start_locus, "_Cilk_for induction variable cannot be volatile"); + return; + } + else if (TREE_CONSTANT (cvar) || TREE_READONLY (cvar)) + { + error_at (start_locus, "_Cilk_for induction variable cannot be constant or " + "readonly"); + return; + } init = DECL_INITIAL (cvar); c_tree = build_stmt (UNKNOWN_LOCATION, CILK_FOR_STMT, NULL_TREE, NULL_TREE, diff --git a/gcc/testsuite/ChangeLog.cilkplus b/gcc/testsuite/ChangeLog.cilkplus index 85959df6983..47149962c26 100644 --- a/gcc/testsuite/ChangeLog.cilkplus +++ b/gcc/testsuite/ChangeLog.cilkplus @@ -1,3 +1,10 @@ +2012-12-14 Balaji V. Iyer <balaji.v.iyer@intel.com> + + * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c: + New test. + * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c: + Likewise. + 2012-12-12 Balaji V. Iyer <balaji.v.iyer@intel.com> * gcc.dg/cilk-plus/cilk_keywords_test/errors/goto_inside_cilkfor.c: diff --git a/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c b/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c new file mode 100644 index 00000000000..6f6db1bc5a0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c @@ -0,0 +1,17 @@ +/* <feature> + The operator denoted OP shall be one of !=, <=, <, >=, or > + </feature> +*/ + +#define ARRAY_SIZE 10000 + +int a[ARRAY_SIZE]; + +int main (void) +{ + int ii; + _Cilk_for(ii = 0; ii == ARRAY_SIZE; ii++) /* { dg-error "_Cilk_for condition must be one of the" } */ + { + a[ii] = ii; + } +} diff --git a/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c b/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c new file mode 100644 index 00000000000..214027ab9d6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c @@ -0,0 +1,18 @@ +/* <feature> + The variable may not be const or volatile + </feature> +*/ +#define SMALL_INT_ARRAY_SIZE 10000 +int a[SMALL_INT_ARRAY_SIZE]; + +int main (void) +{ + volatile int ii; + const int jj; + + + _Cilk_for(ii = 0; ii < SMALL_INT_ARRAY_SIZE; ii++) /* { dg-error "_Cilk_for induction variable cannot be volatile." } */ + { + a[ii] = ii; + } +} |