Commit 2ce86d2e by Balaji V. Iyer Committed by Balaji V. Iyer

Implemented Cilk Plus Array Notation for C++

Implemented Cilk Plus Array Notation for C++ 
gcc/c-family/ChangeLog
2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * c-common.h (struct cilkplus_an_parts): New structure.
        (struct cilkplus_an_loop_parts): Likewise.
        (cilkplus_extract_an_triplets): New prototype.
        (fix_sec_implicit_args): Likewise.
        * array-notation-common.c (cilkplus_extract_an_triplets): New function.
        (fix_sec_implicit_args): Likewise.

gcc/cp/ChangeLog
2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * call.c (convert_like_real): Added a check if array notation is present
        in expression.  If so, then no conversion of arguments is necessary.
        (build_over_call): Likewise.
        * typeck.c (cp_build_function_call_vec): Likewise.
        (convert_for_assignment): Likewise.
        (cp_build_array_ref): Reject array notations with a rank greater than 1
        as an array's index.
        (cp_build_binary_op): If array notations are preent in op, then call
        find_correct_array_notation_type.
        (cp_build_addr_expr_1): Handle ARRAY_NOTATION_REF similar to ARRAY_REF.
        * cp-array-notation.c: New file.
        * cp-objcp-common.c (cp_common_init_ts): Marked ARRAY_NOTATION_REF tree
        as typed.
        * cp-tree.h (fix_array_notation_exprs): New prototype.
        * semantics.c (finish_return_stmt): Reject array notations as
        return value.
        (cxx_eval_constant_expression): Added ARRAY_NOTATION_REF case.
        (potential_constant_expression_1): Likewise.
        * tree.c (lvalue_kind): Likewise.
        * error.c (dump_decl): Likewise.
        (dump_expr): Likewise.
        * pt.c (ARRAY_NOTATION_REF): Likewise.
        (type_unification_real): Do not unify any arguments if array notations
        are found in arg.
        (instantiate_decl): Added a check for array notaitons inside the
        function body.  If so, then expand them.
        * parser.c (cp_parser_array_notation): New function.
        (cp_parser_postfix_open_square_expression): Added a check for colons
        inside square braces.  If found, then handle the array access as an
        array notation access.  Also, disable auto-correction from a single
        colon to scope when Cilk Plus is enabled.
        (cp_parser_compound_statement): Added a check for array notations
        inside the statement.  If found, then expand them.
        (cp_parser_ctor_initializer_opt_and_function_body): Likewise.
        (cp_parser_function_definition_after_declarator): Likewise.
        (cp_parser_selection_statement): Searched for array notations inside
        condition.  If so, then emit an error.
        (cp_parser_iteration_statement): Likewise.
        (cp_parser_direct_declarator): Reject array notations inside a
        variable or array declaration.
        * Make-lang.in (CXX_AND_OBJCXX_OBJS): Added cp/cp-array-notation.o.

gcc/testsuite/ChangeLog
2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * c-c++-common/cilk-plus/AN/array_test1.c: Make this an execution test.
        Also changed the returns from error as distinct values so that debugging
        can get easier.
        * c-c++-common/cilk-plus/AN/if_test_errors.c (main): Made certain
        errors specific to C, if necessary.  Also added new error hooks for C++.
        * c-c++-common/cilk-plus/AN/misc.c (main): Likewise.
        * c-c++-common/cilk-plus/AN/parser_errors.c (main): Likewise.
        * c-c++-common/cilk-plus/AN/parser_errors2.c (main): Likewise.
        * c-c++-common/cilk-plus/AN/parser_errors3.c (main): Likewise.
        * c-c++-common/cilk-plus/AN/pr57541.c (main): Likewise.
        * c-c++-common/cilk-plus/AN/parser_errors4.c (main): In addition to the
        same changes as parser_errors3.c, spaces were added between colons to
        not confuse C++ compiler with 2 colons as scope.
        * c-c++-common/cilk-plus/AN/vla.c: Make this test C specific.
        * g++.dg/cilk-plus/AN/array_test1_tplt.cc: New test.
        * g++.dg/cilk-plus/AN/array_test2_tplt.cc: Likewise.
        * g++.dg/cilk-plus/AN/array_test_ND_tplt.cc: Likewise.
        * g++.dg/cilk-plus/AN/braced_list.cc: Likewise.
        * g++.dg/cilk-plus/AN/builtin_fn_custom_tplt.cc: Likewise.
        * g++.dg/cilk-plus/AN/builtin_fn_mutating_tplt.cc: Likewise.
        * g++.dg/cilk-plus/AN/fp_triplet_values_tplt.c: Likewise.
        * g++.dg/cilk-plus/AN/preincr_test.cc: Likewise.
        * g++.dg/cilk-plus/AN/postincr_test.cc: Likewise.
        * g++.dg/cilk-plus/cilk-plus.exp: New script.
        * gcc/testsuite/g++.dg/dg.exp: Included Cilk Plus C++ tests in the list.

From-SVN: r200319
parent fa1e55b0
2013-06-21 Balaji V. Iyer <balaji.v.iyer@intel.com>
* c-common.h (struct cilkplus_an_parts): New structure.
(struct cilkplus_an_loop_parts): Likewise.
(cilkplus_extract_an_triplets): New prototype.
(fix_sec_implicit_args): Likewise.
* array-notation-common.c (cilkplus_extract_an_triplets): New function.
(fix_sec_implicit_args): Likewise.
2013-06-20 Balaji V. Iyer <balaji.v.iyer@intel.com>
* array-notation-common.c (find_inv_trees): Removed an unwanted
......
......@@ -560,3 +560,100 @@ find_correct_array_notation_type (tree op)
}
return return_type;
}
/* Extracts all the array notation triplet information from LIST and stores
them in the following fields of the 2-D array NODE(size x rank):
START, LENGTH and STRIDE, holding the starting index, length, and stride,
respectively. In addition, it also sets two bool fields, IS_VECTOR and
COUNT_DOWN, in NODE indicating whether a certain value at a certain field
is a vector and if the array is accessed from high to low. */
void
cilkplus_extract_an_triplets (vec<tree, va_gc> *list, size_t size, size_t rank,
vec<vec<struct cilkplus_an_parts> > *node)
{
vec<vec<tree> > array_exprs = vNULL;
struct cilkplus_an_parts init = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
false };
node->safe_grow_cleared (size);
array_exprs.safe_grow_cleared (size);
for (size_t ii = 0; ii < size; ii++)
for (size_t jj = 0; jj < rank; jj++)
{
(*node)[ii].safe_push (init);
array_exprs[ii].safe_push (NULL_TREE);
}
for (size_t ii = 0; ii < size; ii++)
{
size_t jj = 0;
tree ii_tree = (*list)[ii];
while (ii_tree)
if (TREE_CODE (ii_tree) == ARRAY_NOTATION_REF)
{
array_exprs[ii][jj] = ii_tree;
jj++;
ii_tree = ARRAY_NOTATION_ARRAY (ii_tree);
}
else if (TREE_CODE (ii_tree) == ARRAY_REF)
ii_tree = TREE_OPERAND (ii_tree, 0);
else if (TREE_CODE (ii_tree) == VAR_DECL
|| TREE_CODE (ii_tree) == CALL_EXPR
|| TREE_CODE (ii_tree) == PARM_DECL)
break;
else
gcc_unreachable ();
}
for (size_t ii = 0; ii < size; ii++)
if (TREE_CODE ((*list)[ii]) == ARRAY_NOTATION_REF)
for (size_t jj = 0; jj < rank; jj++)
if (TREE_CODE (array_exprs[ii][jj]) == ARRAY_NOTATION_REF)
{
tree ii_tree = array_exprs[ii][jj];
(*node)[ii][jj].is_vector = true;
(*node)[ii][jj].value = ARRAY_NOTATION_ARRAY (ii_tree);
(*node)[ii][jj].start = ARRAY_NOTATION_START (ii_tree);
(*node)[ii][jj].length =
fold_build1 (CONVERT_EXPR, integer_type_node,
ARRAY_NOTATION_LENGTH (ii_tree));
(*node)[ii][jj].stride =
fold_build1 (CONVERT_EXPR, integer_type_node,
ARRAY_NOTATION_STRIDE (ii_tree));
}
}
/* Replaces all the __sec_implicit_arg functions in LIST with the induction
variable stored in VAR at the appropriate location pointed by the
__sec_implicit_arg's first parameter. Emits an error if the parameter is
not between 0 and RANK. */
vec <tree, va_gc> *
fix_sec_implicit_args (location_t loc, vec <tree, va_gc> *list,
vec<an_loop_parts> an_loop_info, size_t rank,
tree orig_stmt)
{
vec <tree, va_gc> *array_operand = NULL;
for (size_t ii = 0; ii < vec_safe_length (list); ii++)
if (TREE_CODE ((*list)[ii]) == CALL_EXPR
&& TREE_CODE (CALL_EXPR_FN ((*list)[ii])) == ADDR_EXPR
&& is_sec_implicit_index_fn (CALL_EXPR_FN ((*list)[ii])))
{
int idx = extract_sec_implicit_index_arg (loc, (*list)[ii]);
if (idx < (int) rank && idx >= 0)
vec_safe_push (array_operand, an_loop_info[idx].var);
else if (idx == -1)
/* In this case, the returning function would have emitted an
error thus it is not necessary to do so again. */
return NULL;
else
{
error_at (loc, "__sec_implicit_index argument %d must be "
"less than the rank of %qE", idx, orig_stmt);
return NULL;
}
}
else
/* Save the existing value into the array operand. */
vec_safe_push (array_operand, (*list)[ii]);
return array_operand;
}
......@@ -1160,6 +1160,29 @@ struct inv_list
vec<enum tree_code, va_gc> *additional_tcodes;
};
/* This structure holds all the important components that can be extracted
from an ARRAY_NOTATION_REF expression. It is used to pass array notation
information between the functions that are responsible for expansion. */
typedef struct cilkplus_an_parts
{
tree value;
tree start;
tree length;
tree stride;
bool is_vector;
} an_parts;
/* This structure holds the components necessary to create the loop around
the ARRAY_REF that is created using the ARRAY_NOTATION information. */
typedef struct cilkplus_an_loop_parts
{
tree var; /* Loop induction variable. */
tree incr; /* Loop increment/decrement expression. */
tree cmp; /* Loop condition. */
tree ind_init; /* Initialization of the loop induction variable. */
} an_loop_parts;
/* In array-notation-common.c. */
extern HOST_WIDE_INT extract_sec_implicit_index_arg (location_t, tree);
extern bool is_sec_implicit_index_fn (tree);
......@@ -1179,4 +1202,8 @@ extern void replace_array_notations (tree *, bool, vec<tree, va_gc> *,
extern tree find_inv_trees (tree *, int *, void *);
extern tree replace_inv_trees (tree *, int *, void *);
extern tree find_correct_array_notation_type (tree op);
extern void cilkplus_extract_an_triplets (vec<tree, va_gc> *, size_t, size_t,
vec<vec<an_parts> > *);
extern vec <tree, va_gc> *fix_sec_implicit_args
(location_t, vec <tree, va_gc> *, vec<an_loop_parts>, size_t, tree);
#endif /* ! GCC_C_COMMON_H */
2013-06-21 Balaji V. Iyer <balaji.v.iyer@intel.com>
* call.c (convert_like_real): Added a check if array notation is present
in expression. If so, then no conversion of arguments is necessary.
(build_over_call): Likewise.
* typeck.c (cp_build_function_call_vec): Likewise.
(convert_for_assignment): Likewise.
(cp_build_array_ref): Reject array notations with a rank greater than 1
as an array's index.
(cp_build_binary_op): If array notations are preent in op, then call
find_correct_array_notation_type.
(cp_build_addr_expr_1): Handle ARRAY_NOTATION_REF similar to ARRAY_REF.
* cp-array-notation.c: New file.
* cp-objcp-common.c (cp_common_init_ts): Marked ARRAY_NOTATION_REF tree
as typed.
* cp-tree.h (fix_array_notation_exprs): New prototype.
* semantics.c (finish_return_stmt): Reject array notations as
return value.
(cxx_eval_constant_expression): Added ARRAY_NOTATION_REF case.
(potential_constant_expression_1): Likewise.
* tree.c (lvalue_kind): Likewise.
* error.c (dump_decl): Likewise.
(dump_expr): Likewise.
* pt.c (ARRAY_NOTATION_REF): Likewise.
(type_unification_real): Do not unify any arguments if array notations
are found in arg.
(instantiate_decl): Added a check for array notaitons inside the
function body. If so, then expand them.
* parser.c (cp_parser_array_notation): New function.
(cp_parser_postfix_open_square_expression): Added a check for colons
inside square braces. If found, then handle the array access as an
array notation access. Also, disable auto-correction from a single
colon to scope when Cilk Plus is enabled.
(cp_parser_compound_statement): Added a check for array notations
inside the statement. If found, then expand them.
(cp_parser_ctor_initializer_opt_and_function_body): Likewise.
(cp_parser_function_definition_after_declarator): Likewise.
(cp_parser_selection_statement): Searched for array notations inside
condition. If so, then emit an error.
(cp_parser_iteration_statement): Likewise.
(cp_parser_direct_declarator): Reject array notations inside a
variable or array declaration.
* Make-lang.in (CXX_AND_OBJCXX_OBJS): Added cp/cp-array-notation.o.
2013-06-20 Jason Merrill <jason@redhat.com>
PR c++/55149
......
......@@ -80,7 +80,7 @@ CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o \
cp/mangle.o cp/cp-objcp-common.o cp/name-lookup.o cp/cxx-pretty-print.o \
cp/cp-gimplify.o $(CXX_C_OBJS)
cp/cp-gimplify.o cp/cp-array-notation.o $(CXX_C_OBJS)
# Language-specific object files for C++.
CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS)
......@@ -266,6 +266,9 @@ CXX_PRETTY_PRINT_H = cp/cxx-pretty-print.h $(C_PRETTY_PRINT_H)
cp/lex.o: cp/lex.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
$(C_PRAGMA_H) input.h cp/operators.def $(TM_P_H) \
c-family/c-objc.h
cp/cp-array-notation.o: cp/cp-array-notation.c $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TREE_H) $(CXX_TREE_H) $(DIAGNOSTIC_H) tree-iterator.h vec.h \
$(GIMPLE_H) c-family/array-notation-common.o $(C_COMMON_H)
cp/cp-lang.o: cp/cp-lang.c $(CXX_TREE_H) $(TM_H) debug.h langhooks.h \
$(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-cp.h gt-cp-cp-lang.h \
cp/cp-objcp-common.h $(EXPR_H) $(TARGET_H) $(CXX_PARSER_H)
......
......@@ -5858,9 +5858,15 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
break;
}
if (permerror (loc, "invalid conversion from %qT to %qT",
TREE_TYPE (expr), totype)
&& fn)
if (flag_enable_cilkplus
&& (contains_array_notation_expr (expr)
|| contains_array_notation_expr (fn)))
/* If we are using array notations, we fix them up at a later stage
and we will do these checks then. */
;
else if (permerror (loc, "invalid conversion from %qT to %qT",
TREE_TYPE (expr), totype)
&& fn)
inform (DECL_SOURCE_LOCATION (fn),
"initializing argument %P of %qD", argnum, fn);
......@@ -6890,12 +6896,20 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
}
}
val = convert_like_with_context (conv, arg, fn, i-is_method,
conversion_warning
? complain
: complain & (~tf_warning));
/* If the function call is builtin array notation function then no need
to do any type conversion. */
if (flag_enable_cilkplus
&& is_cilkplus_reduce_builtin (fn) != BUILT_IN_NONE)
val = arg;
else
{
val = convert_like_with_context (conv, arg, fn, i - is_method,
conversion_warning
? complain
: complain & (~tf_warning));
val = convert_for_arg_passing (type, val, complain);
val = convert_for_arg_passing (type, val, complain);
}
if (val == error_mark_node)
return error_mark_node;
else
......
......@@ -321,6 +321,7 @@ cp_common_init_ts (void)
MARK_TS_TYPED (USING_STMT);
MARK_TS_TYPED (LAMBDA_EXPR);
MARK_TS_TYPED (CTOR_INITIALIZER);
MARK_TS_TYPED (ARRAY_NOTATION_REF);
}
#include "gt-cp-cp-objcp-common.h"
......@@ -6138,6 +6138,10 @@ extern bool cxx_omp_privatize_by_reference (const_tree);
extern void suggest_alternatives_for (location_t, tree);
extern tree strip_using_decl (tree);
/* In cp/cp-array-notations.c */
extern tree expand_array_notation_exprs (tree);
bool cilkplus_an_triplet_types_ok_p (location_t, tree, tree, tree,
tree);
/* -- end of C++ */
#endif /* ! GCC_CP_TREE_H */
......@@ -1071,6 +1071,17 @@ dump_decl (tree t, int flags)
pp_cxx_right_bracket (cxx_pp);
break;
case ARRAY_NOTATION_REF:
dump_decl (ARRAY_NOTATION_ARRAY (t), flags | TFF_EXPR_IN_PARENS);
pp_cxx_left_bracket (cxx_pp);
dump_decl (ARRAY_NOTATION_START (t), flags | TFF_EXPR_IN_PARENS);
pp_string (cxx_pp, ":");
dump_decl (ARRAY_NOTATION_LENGTH (t), flags | TFF_EXPR_IN_PARENS);
pp_string (cxx_pp, ":");
dump_decl (ARRAY_NOTATION_STRIDE (t), flags | TFF_EXPR_IN_PARENS);
pp_cxx_right_bracket (cxx_pp);
break;
/* So that we can do dump_decl on an aggr type. */
case RECORD_TYPE:
case UNION_TYPE:
......@@ -2057,6 +2068,17 @@ dump_expr (tree t, int flags)
pp_cxx_right_bracket (cxx_pp);
break;
case ARRAY_NOTATION_REF:
dump_expr (ARRAY_NOTATION_ARRAY (t), flags | TFF_EXPR_IN_PARENS);
pp_cxx_left_bracket (cxx_pp);
dump_expr (ARRAY_NOTATION_START (t), flags | TFF_EXPR_IN_PARENS);
pp_string (cxx_pp, ":");
dump_expr (ARRAY_NOTATION_LENGTH (t), flags | TFF_EXPR_IN_PARENS);
pp_string (cxx_pp, ":");
dump_expr (ARRAY_NOTATION_STRIDE (t), flags | TFF_EXPR_IN_PARENS);
pp_cxx_right_bracket (cxx_pp);
break;
case UNARY_PLUS_EXPR:
dump_unary_op ("+", t, flags);
break;
......
......@@ -13753,6 +13753,20 @@ tsubst_copy_and_build (tree t,
RECUR (TREE_OPERAND (t, 1)),
complain|decltype_flag));
case ARRAY_NOTATION_REF:
{
tree start_index, length, stride;
op1 = tsubst_non_call_postfix_expression (ARRAY_NOTATION_ARRAY (t),
args, complain, in_decl);
start_index = RECUR (ARRAY_NOTATION_START (t));
length = RECUR (ARRAY_NOTATION_LENGTH (t));
stride = RECUR (ARRAY_NOTATION_STRIDE (t));
if (!cilkplus_an_triplet_types_ok_p (loc, start_index, length, stride,
TREE_TYPE (op1)))
RETURN (error_mark_node);
RETURN (build_array_notation_ref (EXPR_LOCATION (t), op1, start_index,
length, stride, TREE_TYPE (op1)));
}
case SIZEOF_EXPR:
if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
RETURN (tsubst_copy (t, args, complain, in_decl));
......@@ -15725,6 +15739,9 @@ type_unification_real (tree tparms,
arg = args[ia];
++ia;
if (flag_enable_cilkplus && TREE_CODE (arg) == ARRAY_NOTATION_REF)
return 1;
if (unify_one_argument (tparms, targs, parm, arg, subr, strict,
flags, explain_p))
return 1;
......@@ -19126,6 +19143,11 @@ instantiate_decl (tree d, int defer_ok,
pointer_map_destroy (local_specializations);
local_specializations = saved_local_specializations;
/* We expand all the array notation expressions here. */
if (flag_enable_cilkplus
&& contains_array_notation_expr (DECL_SAVED_TREE (d)))
DECL_SAVED_TREE (d) = expand_array_notation_exprs (DECL_SAVED_TREE (d));
/* Finish the function. */
d = finish_function (0);
expand_or_defer_fn (d);
......
......@@ -779,6 +779,22 @@ finish_return_stmt (tree expr)
tree r;
bool no_warning;
if (flag_enable_cilkplus && contains_array_notation_expr (expr))
{
size_t rank = 0;
if (!find_rank (input_location, expr, expr, false, &rank))
return error_mark_node;
/* If the return expression contains array notations, then flag it as
error. */
if (rank >= 1)
{
error_at (input_location, "array notation expression cannot be "
"used as a return value");
return error_mark_node;
}
}
expr = check_return_expr (expr, &no_warning);
if (flag_openmp && !check_omp_return ())
......@@ -8073,6 +8089,7 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t,
non_constant_p, overflow_p);
break;
case ARRAY_NOTATION_REF:
case ARRAY_REF:
r = cxx_eval_array_reference (call, t, allow_non_constant, addr,
non_constant_p, overflow_p);
......@@ -8884,6 +8901,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
want_rval = true;
/* Fall through. */
case ARRAY_REF:
case ARRAY_NOTATION_REF:
case ARRAY_RANGE_REF:
case MEMBER_REF:
case DOTSTAR_EXPR:
......
......@@ -141,6 +141,7 @@ lvalue_kind (const_tree ref)
case INDIRECT_REF:
case ARROW_EXPR:
case ARRAY_REF:
case ARRAY_NOTATION_REF:
case PARM_DECL:
case RESULT_DECL:
return clk_ordinary;
......
......@@ -3005,6 +3005,22 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
return error_mark_node;
}
/* If an array's index is an array notation, then its rank cannot be
greater than one. */
if (flag_enable_cilkplus && contains_array_notation_expr (idx))
{
size_t rank = 0;
/* If find_rank returns false, then it should have reported an error,
thus it is unnecessary for repetition. */
if (!find_rank (loc, idx, idx, true, &rank))
return error_mark_node;
if (rank > 1)
{
error_at (loc, "rank of the array%'s index is greater than 1");
return error_mark_node;
}
}
if (TREE_TYPE (array) == error_mark_node
|| TREE_TYPE (idx) == error_mark_node)
return error_mark_node;
......@@ -3477,8 +3493,12 @@ cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
params = &allocated;
}
nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
complain);
if (flag_enable_cilkplus
&& is_cilkplus_reduce_builtin (fndecl) != BUILT_IN_NONE)
nargs = (*params)->length ();
else
nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
complain);
if (nargs < 0)
return error_mark_node;
......@@ -3936,8 +3956,15 @@ cp_build_binary_op (location_t location,
}
}
type0 = TREE_TYPE (op0);
type1 = TREE_TYPE (op1);
if (flag_enable_cilkplus && contains_array_notation_expr (op0))
type0 = find_correct_array_notation_type (op0);
else
type0 = TREE_TYPE (op0);
if (flag_enable_cilkplus && contains_array_notation_expr (op1))
type1 = find_correct_array_notation_type (op1);
else
type1 = TREE_TYPE (op1);
/* The expression codes of the data types of the arguments tell us
whether the arguments are integers, floating, pointers, etc. */
......@@ -5140,6 +5167,13 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
gcc_assert (!identifier_p (arg) || !IDENTIFIER_OPNAME_P (arg));
if (flag_enable_cilkplus && TREE_CODE (arg) == ARRAY_NOTATION_REF)
{
val = build_address (arg);
if (TREE_CODE (arg) == OFFSET_REF)
PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
return val;
}
if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
&& !really_overloaded_fn (TREE_OPERAND (arg, 1)))
{
......@@ -7818,6 +7852,13 @@ convert_for_assignment (tree type, tree rhs,
tree rhstype;
enum tree_code coder;
/* If we are dealing with built-in array notation function then we don't need
to convert them. They will be broken up into modify exprs in future,
during which all these checks will be done. */
if (flag_enable_cilkplus
&& is_cilkplus_reduce_builtin (fndecl) != BUILT_IN_NONE)
return rhs;
/* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
rhs = TREE_OPERAND (rhs, 0);
......
2013-06-21 Balaji V. Iyer <balaji.v.iyer@intel.com>
* c-c++-common/cilk-plus/AN/array_test1.c: Make this an execution test.
Also changed the returns from error as distinct values so that debugging
can get easier.
* c-c++-common/cilk-plus/AN/if_test_errors.c (main): Made certain
errors specific to C, if necessary. Also added new error hooks for C++.
* c-c++-common/cilk-plus/AN/misc.c (main): Likewise.
* c-c++-common/cilk-plus/AN/parser_errors.c (main): Likewise.
* c-c++-common/cilk-plus/AN/parser_errors2.c (main): Likewise.
* c-c++-common/cilk-plus/AN/parser_errors3.c (main): Likewise.
* c-c++-common/cilk-plus/AN/pr57541.c (main): Likewise.
* c-c++-common/cilk-plus/AN/parser_errors4.c (main): In addition to the
same changes as parser_errors3.c, spaces were added between colons to
not confuse C++ compiler with 2 colons as scope.
* c-c++-common/cilk-plus/AN/vla.c: Make this test C specific.
* g++.dg/cilk-plus/AN/array_test1_tplt.cc: New test.
* g++.dg/cilk-plus/AN/array_test2_tplt.cc: Likewise.
* g++.dg/cilk-plus/AN/array_test_ND_tplt.cc: Likewise.
* g++.dg/cilk-plus/AN/braced_list.cc: Likewise.
* g++.dg/cilk-plus/AN/builtin_fn_custom_tplt.cc: Likewise.
* g++.dg/cilk-plus/AN/builtin_fn_mutating_tplt.cc: Likewise.
* g++.dg/cilk-plus/AN/fp_triplet_values_tplt.c: Likewise.
* g++.dg/cilk-plus/AN/preincr_test.cc: Likewise.
* g++.dg/cilk-plus/AN/postincr_test.cc: Likewise.
* g++.dg/cilk-plus/cilk-plus.exp: New script.
* gcc/testsuite/g++.dg/dg.exp: Included Cilk Plus C++ tests in the list.
2013-06-21 Joseph Myers <joseph@codesourcery.com>
PR other/53317
......
......@@ -18,19 +18,19 @@ int main (void)
array2[:] = 5;
else
array2[:] = 10;
if (!(array[0:10:1] + array[0:10:1])) /* { dg-error "condition and the then-block" } */
array2d[:][:] = 5;
if (!(array[0:10:1] + array[0:10:1])) /* { dg-error "condition and the then-block" "" { target c } } */
array2d[:][:] = 5; /* { dg-error "rank mismatch with controlling expression of parent" "" { target c++ } } */
else
array2[:] = 10;
if (!(array[0:10:1] + array[0:10:1])) /* { dg-error "condition and the else-block" } */
if (!(array[0:10:1] + array[0:10:1])) /* { dg-error "condition and the else-block" "" { target c } } */
array2[:] = 5;
else
array2d[:][:] = 10;
array2d[:][:] = 10; /* { dg-error "rank mismatch with controlling expression of parent" "" { target c++ } } */
if (TwodArray[:][:] != 10) /* { dg-error "condition and the then-block" } */
array2[:] = 10;
if (TwodArray[:][:] != 10) /* { dg-error "condition and the then-block" "" { target c } } */
array2[:] = 10; /* { dg-error "rank mismatch with controlling expression of parent" "" { target c++ } } */
else
array2[:] = 5;
......@@ -40,8 +40,8 @@ int main (void)
array4[32][:][:][:] = 5;
/* atoi(argv[1]) == 10, so it will convert all 10's to 5's */
if (FourDArray[42][0:10:1][9:10:-1][0:5:2] != 10) /* { dg-error "condition and the then-block" } */
array4[0:10:1][0:5:2][9:10:-1][0:5:2] = 10;
if (FourDArray[42][0:10:1][9:10:-1][0:5:2] != 10) /* { dg-error "condition and the then-block" "" { target c } } */
array4[0:10:1][0:5:2][9:10:-1][0:5:2] = 10; /* { dg-error "rank mismatch with controlling expression of parent" "" { target c++ } } */
else
array4[0:10:1][0:5:2][9:10:-1][0:5:2] = 5;
......
......@@ -73,13 +73,13 @@ int main (void)
while (ii != array2[1:x:3][1:2:1]) /* { dg-error "array notations cannot be used as a condition for while statement" } */
x = 2;
do { /* { dg-error "array notations cannot be used as a condition for a do-while statement" } */
do { /* { dg-error "array notations cannot be used as a condition for a do-while statement" "" { target c } } */
x = 3;
} while (ii != array2[:][:]);
} while (ii != array2[:][:]); /* { dg-error "array notations cannot be used as a condition for a do-while statement" "" { target c++ } } */
do { /* { dg-error "array notations cannot be used as a condition for a do-while statement" } */
do { /* { dg-error "array notations cannot be used as a condition for a do-while statement" "" { target c } } */
x = 2;
} while (ii != (x + array2[:][1:x:2]) + 2);
} while (ii != (x + array2[:][1:x:2]) + 2); /* { dg-error "array notations cannot be used as a condition for a do-while statement" "" { target c++ } } */
do {
x += 3;
......
......@@ -8,4 +8,4 @@ int main (void)
array2[:] = array2[: ; /* { dg-error "expected ']'" } */
return 0;
} /* { dg-error "expected ';' before" } */
} /* { dg-error "expected ';' before" "" { target c } } */
......@@ -5,7 +5,8 @@ int main (void)
{
int array[10][10], array2[10];
array2[:] = array2[1:2:] ; /* { dg-error "expected expression before" } */
array2[:] = array2[1:2:] ; /* { dg-error "expected expression before" "" { target c } } */
/* { dg-error "expected primary-expression before" "" { target c++ } 8 } */
return 0; /* { dg-error "expected ';' before" } */
return 0; /* { dg-error "expected ';' before" "" { target c } } */
}
......@@ -5,7 +5,8 @@ int main (void)
{
int array[10][10], array2[10];
array2[:] = array2[1::] ; /* { dg-error "expected expression before" } */
array2[:] = array2[1: :] ; /* { dg-error "expected expression before" "" { target c } } */
/* { dg-error "expected primary-expression before" "" { target c++ } 8 } */
return 0; /* { dg-error "expected ';' before" } */
return 0; /* { dg-error "expected ';' before" "" { target c } } */
}
......@@ -5,7 +5,7 @@ int main (void)
{
int array[10][10], array2[10];
array2[:] = array2[::] ; /* { dg-error " expected ']' before ':' token" } */
array2[:] = array2[ : : ] ; /* { dg-error " expected ']' before ':' token" } */
return 0;
}
......@@ -4,11 +4,14 @@
int A[10];
int main () {
char c = (char)N; /* { dg-error "undeclared" } */
/* C compiler uses the term "undeclared" whereas C++ compiler uses
"not declared". Thus, grepping for declared seem to be the easiest. */
char c = (char)N; /* { dg-error "declared" } */
short s = (short)N;
long l = (long)N;
A[l:s:c];
}
/* { dg-message "note: each" "defined" { target *-*-* } 7 } */
/* { dg-message "note: each" "defined" { target c } 10 } */
/* { dg-do compile } */
/* { dg-options "-fcilkplus -std=c99" } */
/* { dg-do compile { target c } } */
/* { dg-options "-fcilkplus -std=c99 -w" } */
int func (int x)
{
......
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#include <cstdlib>
#include <string.h>
#if HAVE_IO
#include <cstdio>
#endif
template <class T> int main2 (char **argv);
int main (void)
{
int x = 1, y = 1, z = 1;
char *array[2];
array[0] = strdup ("a.out");
array[1] = strdup ("5");
x = main2<unsigned char> (array);
x += main2<char> (array);
y = main2<short> (array);
y += main2<unsigned short> (array);
y += main2<int> (array);
y += main2<unsigned int> (array);
z = main2<long> (array);
z += main2<long long> (array);
y += main2<float> (array);
z += main2<double> (array);
return x+y+z;
}
template <class T>
int main2 (char **argv)
{
T array[10];
int ii = 0, x = 2, z= 0 , y = 0;
for (ii = 0; ii < 10; ii++)
array[ii] = 10;
array[0:10:1] = (T)15;
for (ii = 0; ii < 10; ii++)
if (array[ii] != (T)15)
return 1;
array[0:5:2] = (T)20;
for (ii = 0; ii < 10; ii += 2)
if (array[ii] != (T)20)
return 2;
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
array[x:5:z] = (T)50;
for (ii = x; ii < 10; ii += z)
if (array[ii] != (T)50)
return 3;
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]); /* (10 - 5) / 5 = 1 */
y = 10-atoi(argv[1]);
array[x:y:z] = (T)52;
#if HAVE_IO
for (ii = atoi ("5"); ii < (atoi ("5") + atoi ("5")); ii += atoi ("1"))
std::printf("%d\t", (int)array[ii]);
std::printf("\n");
#endif
for (ii = x; ii < 10; ii += z)
if (array[ii] != (T)52)
return 4;
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
y = 10-atoi(argv[1]);
array[x:y:((10-atoi(argv[1]))/atoi(argv[1]))] = (T)25;
for (ii = x; ii < 10; ii += z)
if (array[ii] != (T)25)
return 5;
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
y = 10-atoi(argv[1]);
array[atoi(argv[1]):(10-atoi(argv[1])):((10-atoi(argv[1]))/atoi(argv[1]))] =
(T)14;
for (ii = x; ii < 10; ii += z)
if (array[ii] != (T)14)
return 6;
array[atoi("5"):5:1] = (T)65;
for (ii = atoi ("5"); ii < 10; ii++)
if (array[ii] != (T)65)
return 7;
array[atoi("5"):atoi("5"):atoi("1")] = 99;
#if HAVE_IO
for (ii = atoi ("5"); ii < (atoi ("5") + atoi ("5")); ii += atoi ("1"))
std::printf("%d\t", (int)array[ii]);
std::printf("\n");
#endif
for (ii = atoi ("5"); ii < (atoi ("5") + atoi ("5")); ii += atoi ("1"))
if (array[ii] != (T)99)
return 8;
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#include <cstdlib>
#include <string.h>
template <class T> int main2(char **argv);
int main(void)
{
int x = 1, y = 1, z = 1, w = 1;
char *array[2];
array[0] = strdup ("a.out");
array[1] = strdup ("5");
w = main2<short>(array);
w += main2<unsigned short> (array);
x = main2<char> (array);
x += main2<unsigned char> (array);
y = main2<int> (array);
y += main2<unsigned int> (array);
z = main2<long> (array);
z += main2<unsigned long> (array);
z += main2<long long> (array);
return (w+x+y+z);
}
template<class T>
int main2(char **argv)
{
T array[10], array2[10];
int ii = 0, x = 2, z= 0 , y = 0 ;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 10;
array2[ii] = 5000000;
}
array2[0:10:1] = array[0:10:1];
for (ii = 0; ii < 10; ii++)
if (array2[ii] != array[ii])
return 1;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 10;
array2[ii] = 5000000;
}
array2[0:5:2] = array[0:5:2];
for (ii = 0; ii < 10; ii += 2)
if (array[ii] != array2[ii])
return 2;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 10;
array2[ii] = 5000000;
}
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
array2[x:5:z] = array[x:5:z];
for (ii = x; ii < 5; ii += z)
if (array2[ii] != array[ii])
return 3;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 500;
array2[ii] = 1000000;
}
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
y = 10-atoi(argv[1]);
array2[x:y:z] = array[x:y:z];
for (ii = x; ii < 10; ii = ii + z)
if (array2[ii] != array[ii])
return 4;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 500;
array2[ii] = 1000000;
}
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
y = 10-atoi(argv[1]);
array[x:y:((10-atoi(argv[1]))/atoi(argv[1]))] =
array2[x:y:((10-atoi(argv[1]))/atoi(argv[1]))];
for (ii = x; ii < 10; ii += z)
if (array[ii] != array2[ii])
return 6;
x = atoi(argv[1]);
z = (10-atoi(argv[1]))/atoi(argv[1]);
y = 10-atoi(argv[1]);
for (ii = 0; ii < 10; ii++)
{
array[ii] = 500;
array2[ii] = 1000000;
}
array[atoi(argv[1]):(10-atoi(argv[1])):((10-atoi(argv[1]))/atoi(argv[1]))] =
array2[atoi(argv[1]):(10-atoi(argv[1])):((10-atoi(argv[1]))/atoi(argv[1]))];
for (ii = x; ii < 10; ii += z)
if (array[ii] != array2[ii])
return 6;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 4;
array2[ii] = 2;
}
array[atoi("5"):5:1] = array2[atoi("5"):5:1];
for (ii = atoi ("5"); ii < 10; ii++)
if (array[ii] != array2[ii])
return 7;
for (ii = 0; ii < 10; ii++)
{
array[ii] = 5;
array2[ii] = 1;
}
array[atoi("5"):atoi("5"):atoi("1")] = array2[atoi("5"):atoi("5"):atoi("1")];
for (ii = 5; ii < 10; ii++)
if (array2[ii] != array[ii])
return 8;
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#include <cstdlib>
#include<string.h>
template <class T> int main2(char **argv);
int main(void)
{
int x = 1, y=1, z=1, w = 1;
char *array[3];
array[0] = strdup ("a.out");
array[1] = strdup ("10");
array[2] = strdup ("15");
w = main2<char> (array);
w += main2<unsigned char> (array);
x = main2<int> (array);
x += main2<unsigned int> (array);
y = main2<long> (array);
y += main2<unsigned long> (array);
z = main2<short> (array);
z += main2<unsigned short> (array);
return x+y+z;
}
template <class T>
int main2(char **argv)
{
T array[10][15];
T array_2[10][15];
int ii = 0, jj = 0,x = 0, z= 1 , y = 10 ,argc = 3;
for (ii = 0; ii < 10; ii++) {
for (jj = 0; jj< 15; jj++) {
array[ii][jj] = ii+jj;
array_2[ii][jj] = 0;
}
}
array_2[0:5:2][0:5:3] = array[0:5:2][0:5:3] + 1 + 5 + array[0][5] + x;
for (ii = 0; ii < 10; ii += 2)
{
for (jj = 0; jj < 15; jj += 3)
{
if (array_2[ii][jj] != array[ii][jj] + 1 + 5 + array[0][5] + x)
return 1;
}
}
for (ii = 0; ii < 10; ii++) {
for (jj = 0; jj< 15; jj++) {
array[ii][jj] = ii+jj;
array_2[ii][jj] = 0;
}
}
x = atoi(argv[1]);
y = atoi(argv[2]);
array_2[0:x:1][0:y:1] = array[0:x:1][0:y:1] + x + y + array[0:x:1][0:y:1];
for (ii = 0; ii < x; ii++)
{
for (jj = 0; jj < y; jj++)
{
if (array_2[ii][jj] != array[ii][jj] + x + y + array[ii][jj])
return 2;
}
}
for (ii = 0; ii < 10; ii++) {
for (jj = 0; jj< 15; jj++) {
array[ii][jj] = ii+jj;
array_2[ii][jj] = 0;
}
}
x = atoi(argv[1]);
y = atoi(argv[2]);
z = (20- atoi (argv[1]))/atoi(argv[1]);
/* (20-10)/10 evaluates to 1 all the time :-). */
array_2[0:x:z][0:y:z] = array[0:x:z][0:y:z] + array[0:x:z][0:y:z] + y + z;
for (ii = 0; ii < x; ii += z)
{
for (jj = 0; jj < y; jj += z)
{
if (array_2[ii][jj] != array[ii][jj] + array[ii][jj] + y + z)
return 3;
}
}
for (ii = 0; ii < 10; ii++) {
for (jj = 0; jj< 15; jj++) {
array[ii][jj] = ii+jj;
array_2[ii][jj] = 0;
}
}
x = argc-3;
y = 20-atoi(argv[1]);
z = (20- atoi (argv[1]))/atoi(argv[1]);
/* (20-10)/10 evaluates to 1 all the time :-). */
array_2[(argc-3):(20-atoi(argv[1])):(20-atoi(argv[1]))/atoi(argv[1])][(argc-3):(30-atoi(argv[2])): ((30-atoi(argv[2]))/atoi(argv[2]))] = array[(argc-3):20-atoi(argv[1]):(20-atoi(argv[1]))/atoi(argv[1])][(argc-3):(30-atoi(argv[2])): (30-atoi(argv[2]))/atoi(argv[2])] + array[(argc-3):20-atoi(argv[1]):(20-atoi(argv[1]))/atoi(argv[1])][(argc-3):(30-atoi(argv[2])): (30-atoi(argv[2]))/atoi(argv[2])] * array[(argc-3):20-atoi(argv[1]):(20-atoi(argv[1]))/atoi(argv[1])][(argc-3):(30-atoi(argv[2])): (30-atoi(argv[2]))/atoi(argv[2])];
for (ii = 0; ii < 10; ii++)
{
for (jj = 0; jj < 15; jj++)
{
if (array_2[ii][jj] != array[ii][jj] + array[ii][jj] * array[ii][jj])
return 4;
}
}
return 0;
}
/* { dg-do compile } */
/* { dg-options "-fcilkplus -std=c++11 " } */
int main (void)
{
int Array[100], Array2[100];
Array[{1,2}:2] = 5; /* { dg-error "braced list index is not allowed" } */
Array[1:{1,2}:2] = 5; /* { dg-error "expected primary-expression before" } */
Array[1:10:{1,2}] = 5; /* { dg-error "expected primary-expression before" } */
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus " } */
#if HAVE_IO
#include <cstdio>
#endif
#include <cstdlib>
template <class T>
T my_func (T x, T y)
{
if (x > y)
return x;
else
return y;
}
template <class T>
T main_func (T *array, T *array2, T identity_val, int size)
{
T result;
result = __sec_reduce (identity_val, array[0:size:1] * array2[0:size:1],
my_func); // my_func (identity_val, array[5] * array2[5]);
return result;
}
int main (void)
{
int i_index = 0, f_index = 0, d_index = 0, l_index = 0;
int iarray[10], iarray2[10], i_result, i_max;
long larray[10], larray2[10], l_result, l_max;
float farray[10], farray2[10], f_result, f_max;
double darray[10], darray2[10], d_result, d_max;
for (int ii = 0; ii < 10; ii++)
{
if (ii%2 && ii)
{
darray[ii] = (double)(1.0000/(double)ii);
farray[ii] = (float)(1.00/(float)ii);
}
else
{
darray[ii] = (double) ii + 0.10;
farray[ii] = (float) (1.00/((float)(ii+1.000)));
}
darray2[ii] = (double) (1.00000/ (double)(ii+1));
farray2[ii] = (float) (1.00/ (float)(ii+1));
}
for (int ii = 0; ii < 10; ii++)
{
iarray[ii] = ii;
larray[ii] = (long)ii;
}
for (int ii = 0; ii < 10; ii++)
{
iarray2[ii] = (ii-5);
larray2[ii] = long (ii-5);
}
#if HAVE_IO
printf("Int: ");
for (int ii=0; ii < 10; ii++)
{
printf("%2d ", iarray[ii] * iarray2[ii]);
}
printf("\nfloat: ");
for (int ii=0; ii < 10; ii++)
{
printf("%4.3f ", farray[ii] * farray2[ii]);
}
printf("\nlong: ");
for (int ii=0; ii < 10; ii++)
{
printf("%2d ", larray[ii] * larray2[ii]);
}
printf("\ndouble: ");
for (int ii=0; ii < 10; ii++)
{
printf("%4.3f ", (float) (darray[ii] * darray2[ii]));
}
printf("\n");
#endif
i_result = main_func<int> (iarray, iarray2, iarray[0] * iarray2[0], 10);
f_result = main_func<float>(farray, farray2, 0.00, 10);
d_result = main_func<double>(darray, darray2, 0.0000, 10);
l_result = main_func<long>(larray, larray2, 0, 10);
#if HAVE_IO
printf("int result = %2d\n", i_result);
printf ("long result = %2d\n", l_result);
printf("float result = %4.3f\n", f_result);
printf("double result = %4.3lf\n", d_result);
#endif
i_max = iarray[0] * iarray2[0];
f_max = farray[0] * farray2[0];
d_max = darray[0] * darray2[0];
l_max = larray[0] * larray2[0];
for (int ii = 0; ii < 10; ii++)
{
if (i_max < iarray[ii] * iarray2[ii])
i_max = iarray[ii] * iarray2[ii];
if (f_max < farray[ii] * farray2[ii])
f_max = farray[ii] * farray2[ii];
if (d_max < darray[ii] * darray2[ii])
d_max = darray[ii] * darray2[ii];
if (l_max < larray[ii] * larray2[ii])
l_max = larray[ii] * larray2[ii];
}
if (i_max != i_result)
return 1;
if (f_max != f_result)
return 2;
if (d_max != d_result)
return 3;
if (l_max != l_result)
return 4;
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#if HAVE_IO
#include <cstdio>
#include<iostream>
#endif
#include <cstdlib>
template <class T>
T my_func (T *x, T y)
{
if (*x < y)
*x = y;
else
*x = *x;
}
template <class T> T my_func (T *x, T y);
template <class T>
T main_func (T *array, T *array2, T identity_val, int size)
{
T result = identity_val;
__sec_reduce_mutating (&result, array[0:size] * array2[0:size:1], my_func);
#if HAVE_IO
std::cout << "Result = " << result << std::endl;
#endif
return result;
}
int main (void)
{
int iarray[10], iarray2[10], i_result = 0, i_max;
long larray[10], larray2[10], l_result = 0, l_max;
float farray[10], farray2[10], f_result = 0, f_max;
double darray[10], darray2[10], d_result = 0, d_max;
for (int ii = 0; ii < 10; ii++)
{
if (ii%2 && ii)
{
darray[ii] = (double)(1.0000/(double)(ii));
farray[ii] = (float)(1.00/(float)(ii));
}
else
{
darray[ii] = (double) ii + 0.10;
farray[ii] = (float) (1.00/((float)(ii) + 0.10));
}
darray2[ii] = (double) (1.00000/ (double)(ii+1));
farray2[ii] = (float) (1.00/ (float)(ii+1));
}
for (int ii = 0; ii < 10; ii++)
{
iarray[ii] = ii;
larray[ii] = (long)ii;
}
for (int ii = 0; ii < 10; ii++)
{
iarray2[ii] = (ii-5);
larray2[ii] = (long)ii-5;
}
#if HAVE_IO
printf("\nInt: ");
for (int ii=0; ii < 10; ii++)
{
printf("%2d ", iarray[ii] * iarray2[ii]);
}
printf("\nfloat: ");
for (int ii=0; ii < 10; ii++)
{
printf("%3.2f ", farray[ii] * farray2[ii]);
}
printf("\nlong: ");
for (int ii=0; ii < 10; ii++)
{
printf("%2d ", larray[ii] * larray2[ii]);
}
printf("\ndouble: ");
for (int ii=0; ii < 10; ii++)
{
printf("%4.3lf ", (float) (darray[ii] * darray2[ii]));
}
printf("\n");
#endif
i_result = main_func<int> (iarray, iarray2, 0, 10);
l_result = main_func<long>(larray, larray2, 0, 10);
f_result = main_func<float>(farray, farray2, 0.00, 10);
d_result = main_func<double>(darray, darray2, 0.0000, 10);
i_max = iarray[0] * iarray2[0];
d_max = darray[0] * darray2[0];
f_max = farray[0] * farray2[0];
l_max = larray[0] * larray2[0];
for (int ii = 0; ii < 10; ii++)
{
if (iarray[ii] * iarray2[ii] > i_max)
i_max = iarray[ii] * iarray2[ii];
if (darray[ii] * darray2[ii] > d_max)
d_max = darray[ii] * darray2[ii];
if (farray[ii] * farray2[ii] > f_max)
f_max = farray[ii] * farray2[ii];
if (larray[ii] * larray2[ii] > l_max)
l_max = larray[ii] * larray2[ii];
}
#if HAVE_IO
printf("int result = %2d\n", i_max);
printf("long result = %2d\n", l_max);
printf("float result = %4.3f\n", f_max);
printf("double result = %4.3lf\n", (float)d_max);
#endif
if (i_max != i_result)
return 1;
if (f_max != f_result)
return 2;
if (l_max != l_result)
return 3;
if (d_max != d_result)
return 4;
return 0;
}
/* { dg-do compile } */
/* { dg-options "-fcilkplus" } */
float q;
void func (int *x)
{
*x = 5;
}
template <class T> int main2 (T x, T y, T z);
int main (void)
{
main2 <float> (1.5, 2.3, 3.443);
main2 <double> (1.34393, 2.38383, 4.38383);
return 0;
}
template <class T>
int main2 (T x, T y, T z)
{
int array[10], array2[10];
array2[:] = array[x:2]; /* { dg-error "start-index of array notation triplet is not an integer" } */
array2[:] = array[1:y]; /* { dg-error "length of array notation triplet is not an integer" } */
array2[1:2:z] = array[:]; /* { dg-error "stride of array notation triplet is not an integer" } */
func (&array2[1:x:3]); /* { dg-error "length of array notation triplet is not an integer" } */
array2[y:9]++; /* { dg-error "start-index of array notation triplet is not an integer" } */
array2[1:x]++; /* { dg-error "length of array notation triplet is not an integer" } */
array2[1:9:x]++; /* { dg-error "stride of array notation triplet is not an integer" } */
++array2[1:q:3]; /* { dg-error "length of array notation triplet is not an integer" } */
array2[:] = array[q:1:3]; /* { dg-error "start-index of array notation triplet is not an integer" } */
array2[:] = array[1:q:3]; /* { dg-error "length of array notation triplet is not an integer" } */
array2[:] = array[1:3:q]; /* { dg-error "stride of array notation triplet is not an integer" } */
func (&array2[1:q:3]); /* { dg-error "length of array notation triplet is not an integer" } */
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#define HAVE_IO 0
#if HAVE_IO
#include <cstdio>
#endif
#include <cstdlib>
template <class T> int main2(int argc);
int main (void)
{
return (main2<int>(1) + main2<long> (1) + main2<long long> (1));
}
#if HAVE_IO
template <class T> int print_array (T *array, int size);
template <class T> int print_array (T *array, int size)
{
for (int ii = 0; ii < size; ii++)
printf("%d ", array[ii]);
printf("\n");
return 0;
}
#endif
template <class T>
int main2(int argc)
{
T array[10], array_serial[10];
for (int ii = 0; ii < 10; ii++) {
array[ii] = 0;
array_serial[ii] = 0;
}
array[:] = 19383;
for (int ii = 0; ii < 10; ii++)
array_serial[ii] = 19383;
array[:]++;
for (int ii = 0; ii < 10; ii++)
array_serial[ii]++;
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 1;
for (int ii = 0; ii < 10; ii++)
array[:]++;
for (int ii = 0; ii < 10; ii++)
for (int jj = 0; jj < 10; jj++)
array_serial[jj]++;
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 2;
if (argc == 2)
array[0:10:1]++;
if (argc == 2)
{
for (int ii = 0; ii < 10; ii++)
array_serial[ii]++;
}
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 3;
array[0:10/argc:argc]++;
for (int ii = 0; ii < 10; ii += argc)
array_serial[ii]++;
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 4;
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcilkplus" } */
#define HAVE_IO 0
#if HAVE_IO
#include <cstdio>
#endif
#include <cstdlib>
template <class T> int main2(int argc);
int main (void)
{
return (main2<int>(1) + main2<long> (1) + main2<long long> (1));
}
#if HAVE_IO
template <class T> int print_array (T *array, int size);
template <class T> int print_array (T *array, int size)
{
for (int ii = 0; ii < size; ii++)
printf("%d ", array[ii]);
printf("\n");
return 0;
}
#endif
template <class T>
int main2(int argc)
{
int array[10], array_serial[10];
for (int ii = 0; ii < 10; ii++) {
array[ii] = 0;
array_serial[ii] = 0;
}
array[:] = 19383;
for (int ii = 0; ii < 10; ii++)
array_serial[ii] = 19383;
++array[:];
for (int ii = 0; ii < 10; ii++)
++array_serial[ii];
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 1;
for (int ii = 0; ii < 10; ii++)
++array[:];
for (int ii = 0; ii < 10; ii++)
for (int jj = 0; jj < 10; jj++)
++array_serial[jj];
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 2;
if (argc == 2)
++array[0:10:1];
if (argc == 2)
{
for (int ii = 0; ii < 10; ii++)
++array_serial[ii];
}
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 3;
++array[0:10/argc:argc];
for (int ii = 0; ii < 10; ii += argc)
{
++array_serial[ii];
}
#if HAVE_IO
print_array<T>(array, 10);
print_array<T>(array_serial, 10);
#endif
for (int ii = 0; ii < 10; ii++)
if (array_serial[ii] != array[ii])
return 4;
return 0;
}
# Copyright (C) 2013 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# Written by Balaji V. Iyer <balaji.v.iyer@intel.com>
load_lib g++-dg.exp
dg-init
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O0 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O1 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O2 -ftree-vectorize -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O3 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O0 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O1 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O2 -ftree-vectorize -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O3 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O3 -ftree-vectorize -fcilkplus -g" " "
dg-finish
dg-init
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -O0 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -O1 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -O2 -ftree-vectorize -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -O3 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -g -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -g -O0 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -g -O1 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -g -O2 -ftree-vectorize -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -g -O3 -fcilkplus" " "
dg-runtest [lsort [glob -nocomplain $srcdir/g++.dg/cilk-plus/AN/*.cc]] " -O3 -ftree-vectorize -fcilkplus -g" " "
dg-finish
......@@ -33,6 +33,7 @@ dg-init
set tests [lsort [find $srcdir/$subdir *.C]]
set tests [prune $tests $srcdir/$subdir/bprob/*]
set tests [prune $tests $srcdir/$subdir/charset/*]
set tests [prune $tests $srcdir/$subdir/cilk-plus/AN/*]
set tests [prune $tests $srcdir/$subdir/compat/*]
set tests [prune $tests $srcdir/$subdir/debug/*]
set tests [prune $tests $srcdir/$subdir/dfp/*]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment