This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++] Fix pr58525
- From: Jason Merrill <jason at redhat dot com>
- To: Alexander Ivchenko <aivchenk at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 23 Nov 2013 11:27:53 -0500
- Subject: Re: [c++] Fix pr58525
- Authentication-results: sourceware.org; auth=none
- References: <CACysShhcKizF7j_5SG97p-VPLppxcBH5sMu0pqomiFM5my=RaA at mail dot gmail dot com>
On 10/07/2013 09:38 AM, Alexander Ivchenko wrote:
__cxa_throw_bad_array_new_length and __cxa_throw_bad_array_new_length
are generated with -fno-exceptions right now. The attached patch fixes
that problem. Bootstrapped and regtested on x86_64-unknown-linux-gnu:
Thanks. The underlying code has changed a bit since you sent this, so
here's the version I'm applying:
commit 3cf869f3399cc126ee91ecc37a19a331d277291a
Author: Alexander Ivchenko <aivchenk@gmail.com>
Date: Mon Oct 7 17:38:48 2013 +0400
PR c++/58525
* call.c (build_operator_new_call): Add flag_exceptions check.
* decl.c (compute_array_index_type): Ditto.
* init.c (build_new_1): Ditto.
(build_vec_init): Ditto.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 935e011..6a4386e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3956,7 +3956,7 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
if (size_check != NULL_TREE)
{
tree errval = TYPE_MAX_VALUE (sizetype);
- if (cxx_dialect >= cxx11)
+ if (cxx_dialect >= cxx11 && flag_exceptions)
errval = throw_bad_array_new_length ();
*size = fold_build3 (COND_EXPR, sizetype, size_check,
original_size, errval);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 40a9a8c..889c203 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8393,7 +8393,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
stabilize_vla_size (itype);
- if (cxx_dialect >= cxx1y)
+ if (cxx_dialect >= cxx1y && flag_exceptions)
{
/* If the VLA bound is larger than half the address space,
or less than zero, throw std::bad_array_length. */
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 0263050..1e6e691 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2529,7 +2529,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
}
/* Perform the overflow check. */
tree errval = TYPE_MAX_VALUE (sizetype);
- if (cxx_dialect >= cxx11)
+ if (cxx_dialect >= cxx11 && flag_exceptions)
errval = throw_bad_array_new_length ();
if (outer_nelts_check != NULL_TREE)
size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
@@ -3399,7 +3399,8 @@ build_vec_init (tree base, tree maxindex, tree init,
is big enough for all the initializers. */
if (init && TREE_CODE (init) == CONSTRUCTOR
&& CONSTRUCTOR_NELTS (init) > 0
- && !TREE_CONSTANT (maxindex))
+ && !TREE_CONSTANT (maxindex)
+ && flag_exceptions)
length_check = fold_build2 (LT_EXPR, boolean_type_node, maxindex,
size_int (CONSTRUCTOR_NELTS (init) - 1));