diff options
author | Martin Sebor <msebor@redhat.com> | 2016-12-08 23:50:40 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2016-12-08 16:50:40 -0700 |
commit | 8bd9f164e29e8d6303ea421076e52be162158f7f (patch) | |
tree | 1265e2a8ec25f7020ef6c9eb300baef80c2e2afa /gcc/builtins.c | |
parent | 410aa8982fcea63dc2e823aa48e554a33f1fc1d3 (diff) | |
download | gcc-8bd9f164e29e8d6303ea421076e52be162158f7f.zip gcc-8bd9f164e29e8d6303ea421076e52be162158f7f.tar.gz gcc-8bd9f164e29e8d6303ea421076e52be162158f7f.tar.bz2 |
PR c/77531 - __attribute__((alloc_size(1,2))) could also warn on multiplication overflow
PR c/77531 - __attribute__((alloc_size(1,2))) could also warn on multiplication overflow
PR c/78284 - warn on malloc with very large arguments
gcc/c-family/ChangeLog:
PR c/78284
* c.opt (-Walloc-zero, -Walloc-size-larger-than): New options.
gcc/ChangeLog:
PR c/78284
* builtin-attrs.def (ATTR_ALLOC_SIZE, ATTR_RETURNS_NONNULL): New
identifier tree nodes.
(ATTR_ALLOCA_SIZE_1_NOTHROW_LEAF_LIST): New attribute list.
(ATTR_MALLOC_SIZE_1_NOTHROW_LIST): Same.
(ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST): Same.
(ATTR_MALLOC_SIZE_1_2_NOTHROW_LEAF_LIST): Same.
(ATTR_ALLOC_SIZE_2_NOTHROW_LEAF_LIST): Same.
* builtins.c (expand_builtin_alloca): Call
maybe_warn_alloc_args_overflow.
* builtins.def (aligned_alloc, calloc, malloc, realloc):
Add attribute alloc_size.
(alloca): Add attribute alloc_size and returns_nonnull.
* calls.h (maybe_warn_alloc_args_overflow): Declare.
* calls.c (alloc_max_size, operand_signed_p): New functions.
(maybe_warn_alloc_args_overflow): Define.
(initialize_argument_information): Diagnose overflow in functions
declared with attaribute alloc_size.
* doc/invoke.texi (Warning Options): Document -Walloc-zero and
-Walloc-size-larger-than.
gcc/testsuite/ChangeLog:
PR c/78284
* gcc.dg/attr-alloc_size-3.c: New test.
* gcc.dg/attr-alloc_size-4.c: New test.
* gcc.dg/attr-alloc_size-5.c: New test.
* gcc.dg/attr-alloc_size-6.c: New test.
* gcc.dg/attr-alloc_size-7.c: New test.
* gcc.dg/attr-alloc_size-8.c: New test.
* gcc.dg/attr-alloc_size-9.c: New test.
* gcc/testsuite/gcc.dg/errno-1.c: Adjust.
From-SVN: r243470
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index b58056c..20515e7 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4797,12 +4797,12 @@ expand_builtin_alloca (tree exp, bool cannot_accumulate) { rtx op0; rtx result; - bool valid_arglist; unsigned int align; - bool alloca_with_align = (DECL_FUNCTION_CODE (get_callee_fndecl (exp)) + tree fndecl = get_callee_fndecl (exp); + bool alloca_with_align = (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN); - valid_arglist + bool valid_arglist = (alloca_with_align ? validate_arglist (exp, INTEGER_TYPE, INTEGER_TYPE, VOID_TYPE) : validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)); @@ -4810,6 +4810,18 @@ expand_builtin_alloca (tree exp, bool cannot_accumulate) if (!valid_arglist) return NULL_RTX; + if ((alloca_with_align && !warn_vla_limit) + || (!alloca_with_align && !warn_alloca_limit)) + { + /* -Walloca-larger-than and -Wvla-larger-than settings override + the more general -Walloc-size-larger-than so unless either of + the former options is specified check the alloca arguments for + overflow. */ + tree args[] = { CALL_EXPR_ARG (exp, 0), NULL_TREE }; + int idx[] = { 0, -1 }; + maybe_warn_alloc_args_overflow (fndecl, exp, args, idx); + } + /* Compute the argument. */ op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |