diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2017-10-19 15:58:05 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2017-10-19 15:58:05 +0000 |
commit | 9e878cf1bae7eba3a097dbb6b04d0bbca5bdb0e4 (patch) | |
tree | 220024bc6525d567df9a66f538a7903a174bcadc /gcc/builtins.c | |
parent | d969783705f55506c111e4f4d0342b09ef301ea2 (diff) | |
download | gcc-9e878cf1bae7eba3a097dbb6b04d0bbca5bdb0e4.zip gcc-9e878cf1bae7eba3a097dbb6b04d0bbca5bdb0e4.tar.gz gcc-9e878cf1bae7eba3a097dbb6b04d0bbca5bdb0e4.tar.bz2 |
asan.c (handle_builtin_alloca): Deal with all alloca variants.
* asan.c (handle_builtin_alloca): Deal with all alloca variants.
(get_mem_refs_of_builtin_call): Likewise.
* builtins.c (expand_builtin_apply): Adjust call to
allocate_dynamic_stack_space.
(expand_builtin_alloca): For __builtin_alloca_with_align_and_max, pass
the third argument to allocate_dynamic_stack_space, otherwise -1.
(expand_builtin): Deal with all alloca variants.
(is_inexpensive_builtin): Likewise.
* builtins.def (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX): New.
* calls.c (special_function_p): Deal with all alloca variants.
(initialize_argument_information): Adjust call to
allocate_dynamic_stack_space.
(expand_call): Likewise.
* cfgexpand.c (expand_call_stmt): Deal with all alloca variants.
* doc/extend.texi (Built-ins): Add __builtin_alloca_with_align_and_max
* explow.c (allocate_dynamic_stack_space): Add MAX_SIZE parameter and
use it for the stack usage computation.
* explow.h (allocate_dynamic_stack_space): Adjust prototype.
* function.c (gimplify_parameters): Turn BUILT_IN_ALLOCA_WITH_ALIGN
into BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX and pass maximum size.
* gimple-ssa-warn-alloca.c (alloca_call_type): Simplify control flow.
Take into account 3rd argument of __builtin_alloca_with_align_and_max.
(in_loop_p): Remove first argument and useless check.
(pass_walloca::execute): Remove useless test and adjust call to above.
* gimple.c (gimple_build_call_from_tree): Deal with all alloc variants
* gimplify.c (gimplify_vla_decl): Turn BUILT_IN_ALLOCA_WITH_ALIGN into
BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX and pass maximum size.
(gimplify_call_expr): Deal with all alloca variants.
* hsa-gen.c (gen_hsa_alloca): Likewise.
(gen_hsa_insns_for_call): Likewise.
* ipa-pure-const.c (special_builtin_state): Likewise.
* tree-chkp.c (chkp_build_returned_bound): Likewise.
* tree-object-size.c (alloc_object_size): Likewise.
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Likewise.
(call_may_clobber_ref_p_1): Likewise.
* tree-ssa-ccp.c (evaluate_stmt): Likewise.
(ccp_fold_stmt): Likewise.
(optimize_stack_restore): Likewise.
* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Likewise.
(mark_all_reaching_defs_necessary_1): Likewise.
(propagate_necessity): Likewise.
(eliminate_unnecessary_stmts): Likewise.
* tree.c (build_common_builtin_nodes): Build
BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX.
* tree.h (ALLOCA_FUNCTION_CODE_P): New macro.
(CASE_BUILT_IN_ALLOCA): Likewise.
* varasm.c (incorporeal_function_p): Deal with all alloca variants.
c-family/
* c-common.c (check_builtin_function_arguments): Also check arguments
of __builtin_alloca_with_align_and_max.
From-SVN: r253901
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 28fc76b..d3498bb 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1609,7 +1609,7 @@ expand_builtin_apply (rtx function, rtx arguments, rtx argsize) arguments to the outgoing arguments address. We can pass TRUE as the 4th argument because we just saved the stack pointer and will restore it right after the call. */ - allocate_dynamic_stack_space (argsize, 0, BIGGEST_ALIGNMENT, true); + allocate_dynamic_stack_space (argsize, 0, BIGGEST_ALIGNMENT, -1, true); /* Set DRAP flag to true, even though allocate_dynamic_stack_space may have already set current_function_calls_alloca to true. @@ -4858,19 +4858,22 @@ expand_builtin_alloca (tree exp) rtx result; unsigned int align; tree fndecl = get_callee_fndecl (exp); - bool alloca_with_align = (DECL_FUNCTION_CODE (fndecl) - == BUILT_IN_ALLOCA_WITH_ALIGN); + HOST_WIDE_INT max_size; + enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); bool alloca_for_var = CALL_ALLOCA_FOR_VAR_P (exp); bool valid_arglist - = (alloca_with_align - ? validate_arglist (exp, INTEGER_TYPE, INTEGER_TYPE, VOID_TYPE) - : validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)); + = (fcode == BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX + ? validate_arglist (exp, INTEGER_TYPE, INTEGER_TYPE, INTEGER_TYPE, + VOID_TYPE) + : fcode == BUILT_IN_ALLOCA_WITH_ALIGN + ? validate_arglist (exp, INTEGER_TYPE, INTEGER_TYPE, VOID_TYPE) + : validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)); if (!valid_arglist) return NULL_RTX; - if ((alloca_with_align && !warn_vla_limit) - || (!alloca_with_align && !warn_alloca_limit)) + if ((alloca_for_var && !warn_vla_limit) + || (!alloca_for_var && !warn_alloca_limit)) { /* -Walloca-larger-than and -Wvla-larger-than settings override the more general -Walloc-size-larger-than so unless either of @@ -4885,13 +4888,19 @@ expand_builtin_alloca (tree exp) op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); /* Compute the alignment. */ - align = (alloca_with_align - ? TREE_INT_CST_LOW (CALL_EXPR_ARG (exp, 1)) - : BIGGEST_ALIGNMENT); + align = (fcode == BUILT_IN_ALLOCA + ? BIGGEST_ALIGNMENT + : TREE_INT_CST_LOW (CALL_EXPR_ARG (exp, 1))); + + /* Compute the maximum size. */ + max_size = (fcode == BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX + ? TREE_INT_CST_LOW (CALL_EXPR_ARG (exp, 2)) + : -1); /* Allocate the desired space. If the allocation stems from the declaration of a variable-sized object, it cannot accumulate. */ - result = allocate_dynamic_stack_space (op0, 0, align, alloca_for_var); + result + = allocate_dynamic_stack_space (op0, 0, align, max_size, alloca_for_var); result = convert_memory_address (ptr_mode, result); return result; @@ -6482,8 +6491,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, && fcode != BUILT_IN_EXECLE && fcode != BUILT_IN_EXECVP && fcode != BUILT_IN_EXECVE - && fcode != BUILT_IN_ALLOCA - && fcode != BUILT_IN_ALLOCA_WITH_ALIGN + && !ALLOCA_FUNCTION_CODE_P (fcode) && fcode != BUILT_IN_FREE && fcode != BUILT_IN_CHKP_SET_PTR_BOUNDS && fcode != BUILT_IN_CHKP_INIT_PTR_BOUNDS @@ -6712,8 +6720,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, else return XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); - case BUILT_IN_ALLOCA: - case BUILT_IN_ALLOCA_WITH_ALIGN: + CASE_BUILT_IN_ALLOCA: target = expand_builtin_alloca (exp); if (target) return target; @@ -10425,8 +10432,7 @@ is_inexpensive_builtin (tree decl) switch (DECL_FUNCTION_CODE (decl)) { case BUILT_IN_ABS: - case BUILT_IN_ALLOCA: - case BUILT_IN_ALLOCA_WITH_ALIGN: + CASE_BUILT_IN_ALLOCA: case BUILT_IN_BSWAP16: case BUILT_IN_BSWAP32: case BUILT_IN_BSWAP64: |