This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR68087
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Mon, 26 Oct 2015 15:39:18 +0100
- Subject: Re: [PATCH] Fix PR68087
- Authentication-results: sourceware.org; auth=none
- References: <20151026113222 dot GA418 at x4> <CAFiYyc2NRb94x+hpQhODtoD4BMM5r00oSmLnsxq+JyiKHV7c-A at mail dot gmail dot com>
On 2015.10.26 at 13:26 +0100, Richard Biener wrote:
> On Mon, Oct 26, 2015 at 12:32 PM, Markus Trippelsdorf <markus@trippelsdorf.de> wrote:
> > diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
> > index ebca411b3eb4..0828a90b0e75 100644
> > --- a/gcc/cp/constexpr.c
> > +++ b/gcc/cp/constexpr.c
> > @@ -1782,8 +1782,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
> > gcc_unreachable ();
> > }
> >
> > - i = tree_to_shwi (index);
> > - if (i < 0)
> > + if (!tree_fits_shwi_p (index) || tree_to_shwi (index) < 0)
> > {
>
> Err, but that also catches very large positive constants. Why not use
> wi::lt (index, 0)?
> Or is index to be interpreted as signed? Then use wi::lts (index, 0).
I think the compiler will reject the array as too large before that can
happen. But anyway, thanks for your suggestion. Here is an updated
patch, that still passes bootstrap and regtesting on ppc64le.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ebca411..11e4ef6 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1782,8 +1782,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
gcc_unreachable ();
}
- i = tree_to_shwi (index);
- if (i < 0)
+ if (wi::lts_p (index, 0))
{
if (!ctx->quiet)
error ("negative array subscript");
@@ -1792,6 +1791,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
}
bool found;
+ i = tree_to_shwi (index);
if (TREE_CODE (ary) == CONSTRUCTOR)
{
HOST_WIDE_INT ix = find_array_ctor_elt (ary, index);
--
Markus