This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR68087


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]