static tree java_build_function_call_expr (tree fn, tree orig_call) { int nargs = call_expr_nargs (orig_call); switch (nargs) { /* Although we could handle the 0-3 argument cases using the general logic in the default case, splitting them out permits folding to be performed without constructing a temporary CALL_EXPR. */ case 0: return build_call_expr (fn, 0); case 1: return build_call_expr (fn, 1, CALL_EXPR_ARG (orig_call, 0)); case 2: return build_call_expr (fn, 2, CALL_EXPR_ARG (orig_call, 0), CALL_EXPR_ARG (orig_call, 1)); case 3: return build_call_expr (fn, 3, CALL_EXPR_ARG (orig_call, 0), CALL_EXPR_ARG (orig_call, 1), CALL_EXPR_ARG (orig_call, 2)); default: { tree fntype = TREE_TYPE (fn); fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn); return fold (build_call_array (TREE_TYPE (fntype), fn, nargs, CALL_EXPR_ARGP (orig_call))); } } }
void ubsan_maybe_instrument_member_call (tree stmt, bool is_ctor) { if (call_expr_nargs (stmt) == 0) return; tree op = CALL_EXPR_ARG (stmt, 0); if (op == error_mark_node || !POINTER_TYPE_P (TREE_TYPE (op))) return; op = ubsan_maybe_instrument_reference_or_call (EXPR_LOCATION (stmt), op, TREE_TYPE (op), is_ctor ? UBSAN_CTOR_CALL : UBSAN_MEMBER_CALL); if (op) CALL_EXPR_ARG (stmt, 0) = op; }
static tree get_frame_arg (tree call) { tree arg, argtype; gcc_assert (call_expr_nargs (call) >= 1); arg = CALL_EXPR_ARG (call, 0); argtype = TREE_TYPE (arg); gcc_assert (TREE_CODE (argtype) == POINTER_TYPE); argtype = TREE_TYPE (argtype); /* If it is passed in as an address, then just use the value directly since the function is inlined. */ if (TREE_CODE (arg) == ADDR_EXPR) return TREE_OPERAND (arg, 0); return arg; }
void parseCallExprNode(CallExprNode *node) { fillType(node); fillExprLocation(node); Log::dump(node); // not recommended // fillExprOperands(node); if (CALL_EXPR_FN(node->gccNode) != NULL_TREE) { node->function = createParseNode( node, CALL_EXPR_FN(node->gccNode), "function"); } else { node->functionName = internal_fn_name(CALL_EXPR_IFN (node->gccNode)); Log::dump(node, "- function: %s", node->functionName.c_str()); } // if (node->parseChilds <= 0) // return; const int argsCount = call_expr_nargs(node->gccNode); for (int f = 0; f < argsCount; f ++) { node->args.push_back(createParseNode( node, CALL_EXPR_ARG(node->gccNode, f), "arg")); } node->chain = createParseNode( node, CALL_EXPR_STATIC_CHAIN(node->gccNode), "chain"); if (node->functionName == "LOAD_LANES") return; }
void cp_ubsan_maybe_instrument_member_call (tree stmt) { if (call_expr_nargs (stmt) == 0) return; tree *opp = &CALL_EXPR_ARG (stmt, 0); tree op = *opp; if (op == error_mark_node || !POINTER_TYPE_P (TREE_TYPE (op))) return; while (TREE_CODE (op) == COMPOUND_EXPR) { opp = &TREE_OPERAND (op, 1); op = *opp; } op = cp_ubsan_maybe_instrument_vptr (EXPR_LOCATION (stmt), op, TREE_TYPE (TREE_TYPE (op)), true, UBSAN_MEMBER_CALL); if (op) *opp = op; }
static tree fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) { tree new_var_type = NULL_TREE, func_parm, new_expr, new_yes_expr, new_no_expr; tree array_ind_value = NULL_TREE, new_no_ind, new_yes_ind, new_no_list; tree new_yes_list, new_cond_expr, new_var_init = NULL_TREE; tree new_exp_init = NULL_TREE; vec<tree, va_gc> *array_list = NULL, *array_operand = NULL; size_t list_size = 0, rank = 0, ii = 0; tree loop_init, array_op0; tree identity_value = NULL_TREE, call_fn = NULL_TREE, new_call_expr, body; location_t location = UNKNOWN_LOCATION; tree loop_with_init = alloc_stmt_list (); vec<vec<an_parts> > an_info = vNULL; vec<an_loop_parts> an_loop_info = vNULL; enum built_in_function an_type = is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn)); if (an_type == BUILT_IN_NONE) return NULL_TREE; /* Builtin call should contain at least one argument. */ if (call_expr_nargs (an_builtin_fn) == 0) { error_at (EXPR_LOCATION (an_builtin_fn), "Invalid builtin arguments"); return error_mark_node; } if (an_type == BUILT_IN_CILKPLUS_SEC_REDUCE || an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING) { call_fn = CALL_EXPR_ARG (an_builtin_fn, 2); if (TREE_CODE (call_fn) == ADDR_EXPR) call_fn = TREE_OPERAND (call_fn, 0); identity_value = CALL_EXPR_ARG (an_builtin_fn, 0); func_parm = CALL_EXPR_ARG (an_builtin_fn, 1); } else func_parm = CALL_EXPR_ARG (an_builtin_fn, 0); /* Fully fold any EXCESSIVE_PRECISION EXPR that can occur in the function parameter. */ func_parm = c_fully_fold (func_parm, false, NULL); if (func_parm == error_mark_node) return error_mark_node; location = EXPR_LOCATION (an_builtin_fn); if (!find_rank (location, an_builtin_fn, an_builtin_fn, true, &rank)) return error_mark_node; if (rank == 0) { error_at (location, "Invalid builtin arguments"); return error_mark_node; } else if (rank > 1 && (an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND || an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND)) { error_at (location, "__sec_reduce_min_ind or __sec_reduce_max_ind cannot" " have arrays with dimension greater than 1"); return error_mark_node; } extract_array_notation_exprs (func_parm, true, &array_list); list_size = vec_safe_length (array_list); switch (an_type) { case BUILT_IN_CILKPLUS_SEC_REDUCE_ADD: case BUILT_IN_CILKPLUS_SEC_REDUCE_MUL: case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX: case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN: new_var_type = TREE_TYPE ((*array_list)[0]); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_ZERO: case BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_NONZERO: case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_ZERO: case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_NONZERO: new_var_type = integer_type_node; break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND: case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND: new_var_type = integer_type_node; break; case BUILT_IN_CILKPLUS_SEC_REDUCE: if (call_fn && identity_value) new_var_type = TREE_TYPE ((*array_list)[0]); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING: new_var_type = NULL_TREE; break; default: gcc_unreachable (); } an_loop_info.safe_grow_cleared (rank); cilkplus_extract_an_triplets (array_list, list_size, rank, &an_info); loop_init = alloc_stmt_list (); for (ii = 0; ii < rank; ii++) { an_loop_info[ii].var = create_tmp_var (integer_type_node); an_loop_info[ii].ind_init = build_modify_expr (location, an_loop_info[ii].var, TREE_TYPE (an_loop_info[ii].var), NOP_EXPR, location, build_int_cst (TREE_TYPE (an_loop_info[ii].var), 0), TREE_TYPE (an_loop_info[ii].var)); } array_operand = create_array_refs (location, an_info, an_loop_info, list_size, rank); replace_array_notations (&func_parm, true, array_list, array_operand); create_cmp_incr (location, &an_loop_info, rank, an_info); if (an_type != BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING) { *new_var = build_decl (location, VAR_DECL, NULL_TREE, new_var_type); gcc_assert (*new_var && *new_var != error_mark_node); } else *new_var = NULL_TREE; if (an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND || an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND) array_ind_value = build_decl (location, VAR_DECL, NULL_TREE, TREE_TYPE (func_parm)); array_op0 = (*array_operand)[0]; if (TREE_CODE (array_op0) == INDIRECT_REF) array_op0 = TREE_OPERAND (array_op0, 0); switch (an_type) { case BUILT_IN_CILKPLUS_SEC_REDUCE_ADD: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (new_var_type), new_var_type); new_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), PLUS_EXPR, location, func_parm, TREE_TYPE (func_parm)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MUL: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_one_cst (new_var_type), new_var_type); new_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), MULT_EXPR, location, func_parm, TREE_TYPE (func_parm)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_ZERO: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_one_cst (new_var_type), new_var_type); /* Initially you assume everything is zero, now if we find a case where it is NOT true, then we set the result to false. Otherwise we just keep the previous value. */ new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (TREE_TYPE (*new_var)), TREE_TYPE (*new_var)); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_cond_expr = build2 (NE_EXPR, TREE_TYPE (func_parm), func_parm, build_zero_cst (TREE_TYPE (func_parm))); new_expr = build_conditional_expr (location, new_cond_expr, false, new_yes_expr, TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_NONZERO: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_one_cst (new_var_type), new_var_type); /* Initially you assume everything is non-zero, now if we find a case where it is NOT true, then we set the result to false. Otherwise we just keep the previous value. */ new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (TREE_TYPE (*new_var)), TREE_TYPE (*new_var)); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_cond_expr = build2 (EQ_EXPR, TREE_TYPE (func_parm), func_parm, build_zero_cst (TREE_TYPE (func_parm))); new_expr = build_conditional_expr (location, new_cond_expr, false, new_yes_expr, TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_ZERO: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (new_var_type), new_var_type); /* 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_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_one_cst (new_var_type), new_var_type); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_cond_expr = build2 (EQ_EXPR, TREE_TYPE (func_parm), func_parm, build_zero_cst (TREE_TYPE (func_parm))); new_expr = build_conditional_expr (location, new_cond_expr, false, new_yes_expr, TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_NONZERO: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (new_var_type), new_var_type); /* 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 non-zero, we set the value to true. */ new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_one_cst (new_var_type), new_var_type); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_cond_expr = build2 (NE_EXPR, TREE_TYPE (func_parm), func_parm, build_zero_cst (TREE_TYPE (func_parm))); new_expr = build_conditional_expr (location, new_cond_expr, false, new_yes_expr, TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX: if (TYPE_MIN_VALUE (new_var_type)) new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, TYPE_MIN_VALUE (new_var_type), new_var_type); else new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, new_var_type); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, TREE_TYPE (*new_var)); new_expr = build_conditional_expr (location, build2 (LT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false, new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN: if (TYPE_MAX_VALUE (new_var_type)) new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, TYPE_MAX_VALUE (new_var_type), new_var_type); else new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, new_var_type); new_no_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, TREE_TYPE (*new_var)); new_expr = build_conditional_expr (location, build2 (GT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false, new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (new_var_type), new_var_type); new_exp_init = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_TYPE (func_parm)); new_no_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_no_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, array_ind_value, TREE_TYPE (array_ind_value)); if (list_size > 1) { new_yes_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, an_loop_info[0].var, TREE_TYPE (an_loop_info[0].var)); new_yes_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_TYPE ((*array_operand)[0])); } else { new_yes_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, TREE_OPERAND (array_op0, 1), TREE_TYPE (TREE_OPERAND (array_op0, 1))); new_yes_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_OPERAND (array_op0, 1)); } new_yes_list = alloc_stmt_list (); append_to_statement_list (new_yes_ind, &new_yes_list); append_to_statement_list (new_yes_expr, &new_yes_list); new_no_list = alloc_stmt_list (); append_to_statement_list (new_no_ind, &new_no_list); append_to_statement_list (new_no_expr, &new_no_list); new_expr = build_conditional_expr (location, build2 (LE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, func_parm), false, new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, build_zero_cst (new_var_type), new_var_type); new_exp_init = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_TYPE (func_parm)); new_no_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, *new_var, TREE_TYPE (*new_var)); new_no_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, array_ind_value, TREE_TYPE (array_ind_value)); if (list_size > 1) { new_yes_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, an_loop_info[0].var, TREE_TYPE (an_loop_info[0].var)); new_yes_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_TYPE (array_op0)); } else { new_yes_ind = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, TREE_OPERAND (array_op0, 1), TREE_TYPE (TREE_OPERAND (array_op0, 1))); new_yes_expr = build_modify_expr (location, array_ind_value, TREE_TYPE (array_ind_value), NOP_EXPR, location, func_parm, TREE_OPERAND (array_op0, 1)); } new_yes_list = alloc_stmt_list (); append_to_statement_list (new_yes_ind, &new_yes_list); append_to_statement_list (new_yes_expr, &new_yes_list); new_no_list = alloc_stmt_list (); append_to_statement_list (new_no_ind, &new_no_list); append_to_statement_list (new_no_expr, &new_no_list); new_expr = build_conditional_expr (location, build2 (GE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, func_parm), false, new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, identity_value, new_var_type); new_call_expr = build_call_expr (call_fn, 2, *new_var, func_parm); new_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, new_call_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING: new_expr = build_call_expr (call_fn, 2, identity_value, func_parm); break; default: gcc_unreachable (); break; } for (ii = 0; ii < rank; ii++) append_to_statement_list (an_loop_info[ii].ind_init, &loop_init); if (an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND || an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND) append_to_statement_list (new_exp_init, &loop_init); if (an_type != BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING) append_to_statement_list (new_var_init, &loop_init); append_to_statement_list_force (loop_init, &loop_with_init); body = new_expr; for (ii = 0; ii < rank; ii++) { tree new_loop = push_stmt_list (); c_finish_loop (location, an_loop_info[ii].cmp, an_loop_info[ii].incr, body, NULL_TREE, NULL_TREE, true); body = pop_stmt_list (new_loop); } append_to_statement_list_force (body, &loop_with_init); an_info.release (); an_loop_info.release (); return loop_with_init; }