This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++] Omit overflow check for new char[n]
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Florian Weimer <fweimer at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 31 Oct 2012 10:05:24 +0100
- Subject: Re: [C++] Omit overflow check for new char[n]
- References: <5072F64A.6030509@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Oct 08, 2012 at 05:50:34PM +0200, Florian Weimer wrote:
> gcc/:
>
> 2012-10-08 Florian Weimer <fweimer@redhat.com>
>
> * init.c (build_new_1): Do not check for arithmetic overflow if
> inner array size is 1.
>
> gcc/testsuite/:
>
> 2012-10-08 Florian Weimer <fweimer@redhat.com>
>
> * g++.dg/init/new40.C: New.
> @@ -2450,7 +2450,13 @@
> if (array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type))
> size = size_binop (PLUS_EXPR, size, cookie_size);
> else
> - cookie_size = NULL_TREE;
> + {
> + cookie_size = NULL_TREE;
> + /* No size arithmetic necessary, so the size check is
> + not needed. */
> + if (outer_nelts_check != NULL && inner_size == double_int_one)
> + outer_nelts_check = NULL_TREE;
> + }
I don't see any == double_int_one (or zero) comparisons in grep,
so I'd say inner_size.is_one () should be used instead (which is used
pretty frequently). Ditto in the second spot.
Otherwise the patch looks good to me, but I'd like Jason to chime in too.
> /* Perform the overflow check. */
> if (outer_nelts_check != NULL_TREE)
> size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
> @@ -2486,7 +2492,13 @@
> /* Use a global operator new. */
> /* See if a cookie might be required. */
> if (!(array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type)))
> - cookie_size = NULL_TREE;
> + {
> + cookie_size = NULL_TREE;
> + /* No size arithmetic necessary, so the size check is
> + not needed. */
> + if (outer_nelts_check != NULL && inner_size == double_int_one)
> + outer_nelts_check = NULL_TREE;
> + }
>
> alloc_call = build_operator_new_call (fnname, placement,
> &size, &cookie_size,
Jakub