From 57717943ca13457d835a2ead6ad131d0c359edee Mon Sep 17 00:00:00 2001 From: bviyer Date: Tue, 20 Aug 2013 01:10:56 +0000 Subject: Fix for PR c/57490. gcc/c/ChangeLog +2013-08-19 Balaji V. Iyer + + PR c/57490 + * c-array-notation.c (fix_conditional_array_notations_1): Added a + check for truth values. + (expand_array_notation_exprs): Added truth values case. Removed an + unwanted else. Added for-loop to walk through subtrees in default + case. + gcc/cp/ChangeLog +2013-08-19 Balaji V. Iyer + + PR c/57490 + * cp-array-notation.c (cp_expand_cond_array_notations): Added a + check for truth values. + (expand_array_notation_exprs): Added truth values case. Removed an + unwanted else. Added for-loop to walk through subtrees in default + case. + * call.c (build_cxx_call): Inherited the type of the array notation for + certain built-in array notation functions. + gcc/testsuite/ChangeLog +2013-08-19 Balaji V. Iyer + + PR c/57490 + * c-c++-common/cilk-plus/AN/pr57490.c: New test. + git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201867 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 11 +++++++++++ gcc/cp/call.c | 27 +++++++++++++++++++++++++++ gcc/cp/cp-array-notation.c | 21 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) (limited to 'gcc/cp') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e4bf66994bb..d4099b0a28d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2013-08-19 Balaji V. Iyer + + PR c/57490 + * cp-array-notation.c (cp_expand_cond_array_notations): Added a + check for truth values. + (expand_array_notation_exprs): Added truth values case. Removed an + unwanted else. Added for-loop to walk through subtrees in default + case. + * call.c (build_cxx_call): Inherited the type of the array notation for + certain built-in array notation functions. + 2013-08-19 Paolo Carlini * parser.c (cp_parser_lambda_introducer, cp_parser_decltype_expr): diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e493a7947be..df87d8f4d8d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7177,6 +7177,33 @@ build_cxx_call (tree fn, int nargs, tree *argarray, && !check_builtin_function_arguments (fndecl, nargs, argarray)) return error_mark_node; + /* If it is a built-in array notation function, then the return type of + the function is the element type of the array passed in as array + notation (i.e. the first parameter of the function). */ + if (flag_enable_cilkplus && TREE_CODE (fn) == CALL_EXPR) + { + enum built_in_function bif = + is_cilkplus_reduce_builtin (CALL_EXPR_FN (fn)); + if (bif == BUILT_IN_CILKPLUS_SEC_REDUCE_ADD + || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MUL + || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MAX + || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN + || bif == BUILT_IN_CILKPLUS_SEC_REDUCE + || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING) + { + /* for bif == BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_ZERO or + BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_ZERO or + BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_NONZERO or + BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_NONZERO or + BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND or + BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND + The pre-defined return-type is the correct one. */ + tree array_ntn = CALL_EXPR_ARG (fn, 0); + TREE_TYPE (fn) = TREE_TYPE (array_ntn); + return fn; + } + } + /* Some built-in function calls will be evaluated at compile-time in fold (). Set optimize to 1 when folding __builtin_constant_p inside a constexpr function so that fold_builtin_1 doesn't fold it to 0. */ diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c index eb6a70d835c..f4581f01e57 100644 --- a/gcc/cp/cp-array-notation.c +++ b/gcc/cp/cp-array-notation.c @@ -857,6 +857,19 @@ cp_expand_cond_array_notations (tree orig_stmt) return error_mark_node; } } + else if (truth_value_p (TREE_CODE (orig_stmt))) + { + size_t left_rank = 0, right_rank = 0; + tree left_expr = TREE_OPERAND (orig_stmt, 0); + tree right_expr = TREE_OPERAND (orig_stmt, 1); + if (!find_rank (EXPR_LOCATION (left_expr), left_expr, left_expr, true, + &left_rank) + || !find_rank (EXPR_LOCATION (right_expr), right_expr, right_expr, + true, &right_rank)) + return error_mark_node; + if (right_rank == 0 && left_rank == 0) + return orig_stmt; + } if (!find_rank (EXPR_LOCATION (orig_stmt), orig_stmt, orig_stmt, true, &rank)) @@ -1213,6 +1226,12 @@ expand_array_notation_exprs (tree t) if (TREE_OPERAND (t, 0) == error_mark_node) return TREE_OPERAND (t, 0); return t; + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + case TRUTH_XOR_EXPR: + case TRUTH_NOT_EXPR: case COND_EXPR: t = cp_expand_cond_array_notations (t); if (TREE_CODE (t) == COND_EXPR) @@ -1222,8 +1241,6 @@ expand_array_notation_exprs (tree t) COND_EXPR_ELSE (t) = expand_array_notation_exprs (COND_EXPR_ELSE (t)); } - else - t = expand_array_notation_exprs (t); return t; case FOR_STMT: if (contains_array_notation_expr (FOR_COND (t))) -- cgit v1.2.1