summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbviyer <bviyer@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-18 18:02:23 +0000
committerbviyer <bviyer@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-18 18:02:23 +0000
commitbcea3322f5fdbff3002cf44a428900315be91038 (patch)
tree2da177398f263ce678caee796fb6fdf05658cd93
parent446c4f542e75b2262fde21cde04bc81f79090313 (diff)
downloadgcc-bcea3322f5fdbff3002cf44a428900315be91038.tar.gz
Fixed a couple bugs:
1. Fixed bug of switching true and false in reduction functions. 2. Also fixed a bug of having reduction functions as parms for reduction functions in C. gcc/cp/ChangeLog.cilkplus +2013-04-18 Balaji V. Iyer <balaji.v.iyer@intel.com> + + * cp-array-notation.c (fix_builtin_array_notation_fn): Fixed a bug of + switching the true and false condition in array notation reduction + functions. + gcc/ChangeLog.cilkplus +2013-04-18 Balaji V. Iyer <balaji.v.iyer@intel.com> + + * c/c-array-notation.c (fix_builtin_array_notation_fn): Added a check + for array notation functions inside array notations. If so, return an + error. + (build_array_notation_expr): Fixed a bug and popped a statement list. + git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/cilkplus@198062 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog.cilkplus7
-rw-r--r--gcc/c/c-array-notation.c23
-rw-r--r--gcc/cp/ChangeLog.cilkplus6
-rw-r--r--gcc/cp/cp-array-notation.c10
-rw-r--r--gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.cc25
-rw-r--r--gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/execute/sec_red_zero_test.cc26
-rw-r--r--gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.c27
7 files changed, 116 insertions, 8 deletions
diff --git a/gcc/ChangeLog.cilkplus b/gcc/ChangeLog.cilkplus
index ec682815808..b973bae1e35 100644
--- a/gcc/ChangeLog.cilkplus
+++ b/gcc/ChangeLog.cilkplus
@@ -1,3 +1,10 @@
+2013-04-18 Balaji V. Iyer <balaji.v.iyer@intel.com>
+
+ * c/c-array-notation.c (fix_builtin_array_notation_fn): Added a check
+ for array notation functions inside array notations. If so, return an
+ error.
+ (build_array_notation_expr): Fixed a bug and popped a statement list.
+
2013-04-17 Balaji V. Iyer <balaji.v.iyer@intel.com>
* c/c-array-notation.c (build_array_notation_expr): Added a check for
diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index 7bdbcc8c67f..941cc682ef7 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -466,7 +466,10 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
{
builtin_loop = fix_builtin_array_notation_fn (rhs_node, &new_var);
if (builtin_loop == error_mark_node)
- return error_mark_node;
+ {
+ pop_stmt_list (loop);
+ return error_mark_node;
+ }
else if (builtin_loop)
{
add_stmt (builtin_loop);
@@ -1884,12 +1887,26 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
|| TREE_CODE (func_parm) == NOP_EXPR)
func_parm = TREE_OPERAND (func_parm, 0);
- find_rank (an_builtin_fn, true, &rank);
+ find_rank (func_parm, false, &rank);
location = EXPR_LOCATION (an_builtin_fn);
if (rank == 0)
- return an_builtin_fn;
+ {
+ if (an_type == REDUCE_ADD || an_type == REDUCE_MUL
+ || an_type == REDUCE_MAX || an_type == REDUCE_MIN
+ || an_type == REDUCE_ALL_ZEROS || an_type == REDUCE_ANY_ZEROS
+ || an_type == REDUCE_ANY_NONZEROS || an_type == REDUCE_ALL_NONZEROS
+ || an_type == REDUCE_MAX_INDEX || an_type == REDUCE_MIN_INDEX
+ || an_type == REDUCE_CUSTOM || an_type == REDUCE_MUTATING)
+ {
+ error_at (location, "array notation builtin functions cannot have"
+ " array notation parameter with zero rank");
+ return error_mark_node;
+ }
+ else
+ return an_builtin_fn;
+ }
else if (rank > 1
&& (an_type == REDUCE_MAX_INDEX || an_type == REDUCE_MIN_INDEX))
{
diff --git a/gcc/cp/ChangeLog.cilkplus b/gcc/cp/ChangeLog.cilkplus
index 4f64132079a..fc5d326c054 100644
--- a/gcc/cp/ChangeLog.cilkplus
+++ b/gcc/cp/ChangeLog.cilkplus
@@ -1,3 +1,9 @@
+2013-04-18 Balaji V. Iyer <balaji.v.iyer@intel.com>
+
+ * cp-array-notation.c (fix_builtin_array_notation_fn): Fixed a bug of
+ switching the true and false condition in array notation reduction
+ functions.
+
2013-04-17 Balaji V. Iyer <balaji.v.iyer@intel.com>
* cp-array-notation.c (build_x_array_notation_expr): Added a check for
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index 44dd76f68ce..742911b560d 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -2096,7 +2096,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
|| TREE_CODE (func_parm) == NOP_EXPR)
func_parm = TREE_OPERAND (func_parm, 0);
- find_rank (an_builtin_fn, false, &rank);
+ find_rank (func_parm, true, &rank);
location = EXPR_LOCATION (an_builtin_fn);
@@ -2477,10 +2477,10 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
/* Initially we assume there are NO zeros in the list. When we find a
non-zero, we keep the previous value. If we find a zero, we set the
value to true. */
- new_no_expr = build_x_modify_expr
+ new_yes_expr = build_x_modify_expr
(location, *new_var, NOP_EXPR,
build_one_cst (TREE_TYPE (*new_var)), 1);
- new_yes_expr = build_x_modify_expr (location, *new_var, NOP_EXPR,
+ new_no_expr = build_x_modify_expr (location, *new_var, NOP_EXPR,
*new_var, 1);
if (ARITHMETIC_TYPE_P (TREE_TYPE (func_parm)))
comp_node = build_zero_cst (TREE_TYPE (func_parm));
@@ -2501,10 +2501,10 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
/* Initially we assume there are NO non-zeros in the list. When we find a
zero, we keep the previous value. If we find a zero, we set the value
to true. */
- new_no_expr = build_x_modify_expr
+ new_yes_expr = build_x_modify_expr
(location, *new_var, NOP_EXPR,
build_one_cst (TREE_TYPE (*new_var)), 1);
- new_yes_expr = build_x_modify_expr (location, *new_var, NOP_EXPR,
+ new_no_expr = build_x_modify_expr (location, *new_var, NOP_EXPR,
*new_var, 1);
if (ARITHMETIC_TYPE_P (TREE_TYPE (func_parm)))
comp_node = build_zero_cst (TREE_TYPE (func_parm));
diff --git a/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.cc b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.cc
new file mode 100644
index 00000000000..05e00ef2188
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.cc
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+int A[256];
+
+int add( int x, int y)
+{
+ return x+y;
+}
+
+void
+check () {
+ int a;
+ a = __sec_reduce_min_ind (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_max_ind (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_any_zero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_any_nonzero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_all_nonzero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_max (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_min (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_mul (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_add (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce (0, __sec_reduce_min_ind (A[:]), add); /* { dg-error "cannot have array notation parameter with zero" } */
+ __sec_reduce_mutating (&a, __sec_reduce_min_ind (A[:]), add); /* { dg-error "cannot have array notation parameter with zero" } */
+}
+
diff --git a/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/execute/sec_red_zero_test.cc b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/execute/sec_red_zero_test.cc
new file mode 100644
index 00000000000..0b264fecace
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/execute/sec_red_zero_test.cc
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-options "-fcilkplus" } */
+
+#if HAVE_IO
+#include <iostream>
+#endif
+int A[16];
+
+int main () {
+ A[:] = 5;
+#if HAVE_IO
+ std::cout << __sec_reduce_any_zero(A[:]) << "\n";
+#else
+ if (__sec_reduce_any_zero (A[:]))
+ return 1;
+#endif
+ A[:] = 0;
+#if HAVE_IO
+ std::cout << __sec_reduce_any_nonzero(A[:]) << "\n";
+#else
+ if (__sec_reduce_any_nonzero (A[:]))
+ return 1;
+#endif
+ return 0;
+}
+
diff --git a/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.c b/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.c
new file mode 100644
index 00000000000..33fd8b525d6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/errors/sec_inside_sec2.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+int A[256];
+
+int add( int x, int y)
+{
+ return x+y;
+}
+
+void
+check () {
+ int a;
+ a = __sec_reduce_min_ind (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_max_ind (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_any_zero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_any_nonzero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_all_nonzero (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_max (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_min (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_mul (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce_add (__sec_reduce_min_ind (A[:])); /* { dg-error "cannot have array notation parameter with zero" } */
+ a = __sec_reduce (0, __sec_reduce_min_ind (A[:]), add); /* { dg-error "cannot have array notation parameter with zero" } */
+ __sec_reduce_mutating (&a, __sec_reduce_min_ind (A[:]), add); /* { dg-error "cannot have array notation parameter with zero" } */
+}
+
+
+