public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix middle-end/81737
@ 2017-08-07  8:47 Marek Polacek
  2017-08-07  8:58 ` Jakub Jelinek
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2017-08-07  8:47 UTC (permalink / raw)
  To: GCC Patches

In my recent change I failed to check whether the type domain
of a type is non-NULL and this goof causes crashing on this
testcase.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-08-07  Marek Polacek  <polacek@redhat.com>

	PR middle-end/81737
	* fold-const.c (fold_indirect_ref_1): Check type_domain.

	* gcc.dg/pr81737.c: New test.

diff --git gcc/fold-const.c gcc/fold-const.c
index d563ba76766..8eaea6cce3a 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -14107,8 +14107,10 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 		   && type == TREE_TYPE (op00type))
 	    {
 	      tree type_domain = TYPE_DOMAIN (op00type);
-	      tree min = TYPE_MIN_VALUE (type_domain);
-	      if (min && TREE_CODE (min) == INTEGER_CST)
+	      tree min;
+	      if (type_domain != NULL_TREE
+		  && (min = TYPE_MIN_VALUE (type_domain))
+		  && TREE_CODE (min) == INTEGER_CST)
 		{
 		  offset_int off = wi::to_offset (op01);
 		  offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
diff --git gcc/testsuite/gcc.dg/pr81737.c gcc/testsuite/gcc.dg/pr81737.c
index e69de29bb2d..493358956ef 100644
--- gcc/testsuite/gcc.dg/pr81737.c
+++ gcc/testsuite/gcc.dg/pr81737.c
@@ -0,0 +1,6 @@
+/* PR middle-end/81737 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern int a[];
+void fn1() { (a + 0)[1]; }

	Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-07  8:47 [PATCH] Fix middle-end/81737 Marek Polacek
@ 2017-08-07  8:58 ` Jakub Jelinek
  2017-08-07  9:10   ` Marek Polacek
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2017-08-07  8:58 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
> In my recent change I failed to check whether the type domain
> of a type is non-NULL and this goof causes crashing on this
> testcase.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2017-08-07  Marek Polacek  <polacek@redhat.com>
> 
> 	PR middle-end/81737
> 	* fold-const.c (fold_indirect_ref_1): Check type_domain.
> 
> 	* gcc.dg/pr81737.c: New test.

The old code was assuming size_zero_node if type_domain is NULL
or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed might
be wrong perhaps for Fortran or Ada.

Hopefully nothing will assume this has to be folded in these cases (mainly
thinking about C++ constexpr).

So ok.

> diff --git gcc/fold-const.c gcc/fold-const.c
> index d563ba76766..8eaea6cce3a 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -14107,8 +14107,10 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
>  		   && type == TREE_TYPE (op00type))
>  	    {
>  	      tree type_domain = TYPE_DOMAIN (op00type);
> -	      tree min = TYPE_MIN_VALUE (type_domain);
> -	      if (min && TREE_CODE (min) == INTEGER_CST)
> +	      tree min;
> +	      if (type_domain != NULL_TREE
> +		  && (min = TYPE_MIN_VALUE (type_domain))
> +		  && TREE_CODE (min) == INTEGER_CST)
>  		{
>  		  offset_int off = wi::to_offset (op01);
>  		  offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> diff --git gcc/testsuite/gcc.dg/pr81737.c gcc/testsuite/gcc.dg/pr81737.c
> index e69de29bb2d..493358956ef 100644
> --- gcc/testsuite/gcc.dg/pr81737.c
> +++ gcc/testsuite/gcc.dg/pr81737.c
> @@ -0,0 +1,6 @@
> +/* PR middle-end/81737 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +extern int a[];
> +void fn1() { (a + 0)[1]; }
> 
> 	Marek

	Jakub

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-07  8:58 ` Jakub Jelinek
@ 2017-08-07  9:10   ` Marek Polacek
  2017-08-07 14:07     ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2017-08-07  9:10 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
> > In my recent change I failed to check whether the type domain
> > of a type is non-NULL and this goof causes crashing on this
> > testcase.
> > 
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > 
> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
> > 
> > 	PR middle-end/81737
> > 	* fold-const.c (fold_indirect_ref_1): Check type_domain.
> > 
> > 	* gcc.dg/pr81737.c: New test.
> 
> The old code was assuming size_zero_node if type_domain is NULL
> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed might
> be wrong perhaps for Fortran or Ada.

Yeah, I did what Richi suggested doing in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81695#c4

> Hopefully nothing will assume this has to be folded in these cases (mainly
> thinking about C++ constexpr).
 
We'll see soon I suspect ;).

> So ok.

Thanks,

	Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-07  9:10   ` Marek Polacek
@ 2017-08-07 14:07     ` Richard Biener
  2017-08-08 17:23       ` Marek Polacek
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2017-08-07 14:07 UTC (permalink / raw)
  To: gcc-patches, Marek Polacek, Jakub Jelinek; +Cc: GCC Patches

On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
>On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
>> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
>> > In my recent change I failed to check whether the type domain
>> > of a type is non-NULL and this goof causes crashing on this
>> > testcase.
>> > 
>> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>> > 
>> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
>> > 
>> > 	PR middle-end/81737
>> > 	* fold-const.c (fold_indirect_ref_1): Check type_domain.
>> > 
>> > 	* gcc.dg/pr81737.c: New test.
>> 
>> The old code was assuming size_zero_node if type_domain is NULL
>> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed
>might
>> be wrong perhaps for Fortran or Ada.

It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review).  IIRC there are at least one other 'copy' of the folding somewhere.

Richard. 

>Yeah, I did what Richi suggested doing in
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81695#c4
>
>> Hopefully nothing will assume this has to be folded in these cases
>(mainly
>> thinking about C++ constexpr).
> 
>We'll see soon I suspect ;).
>
>> So ok.
>
>Thanks,
>
>	Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-07 14:07     ` Richard Biener
@ 2017-08-08 17:23       ` Marek Polacek
  2017-08-14  8:32         ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2017-08-08 17:23 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, Jakub Jelinek

On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote:
> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
> >> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
> >> > In my recent change I failed to check whether the type domain
> >> > of a type is non-NULL and this goof causes crashing on this
> >> > testcase.
> >> > 
> >> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >> > 
> >> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
> >> > 
> >> > 	PR middle-end/81737
> >> > 	* fold-const.c (fold_indirect_ref_1): Check type_domain.
> >> > 
> >> > 	* gcc.dg/pr81737.c: New test.
> >> 
> >> The old code was assuming size_zero_node if type_domain is NULL
> >> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed
> >might
> >> be wrong perhaps for Fortran or Ada.
> 
> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review).  IIRC there are at least one other 'copy' of the folding somewhere.

Sure, this patch should do it:

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-08-08  Marek Polacek  <polacek@redhat.com>

	PR middle/81695
	* fold-const.c (fold_indirect_ref_1): Restore original behavior
	regarding size_zero_node.

diff --git gcc/fold-const.c gcc/fold-const.c
index 5a118ca50a1..2c47d1d16a4 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 		   && type == TREE_TYPE (op00type))
 	    {
 	      tree type_domain = TYPE_DOMAIN (op00type);
-	      tree min;
+	      tree min = size_zero_node;
 	      if (type_domain != NULL_TREE
-		  && (min = TYPE_MIN_VALUE (type_domain))
+		  && TYPE_MIN_VALUE (type_domain)
 		  && TREE_CODE (min) == INTEGER_CST)
+		min = TYPE_MIN_VALUE (type_domain);
+	      offset_int off = wi::to_offset (op01);
+	      offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
+	      offset_int remainder;
+	      off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
+	      if (remainder == 0)
 		{
-		  offset_int off = wi::to_offset (op01);
-		  offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
-		  offset_int remainder;
-		  off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
-		  if (remainder == 0)
-		    {
-		      off = off + wi::to_offset (min);
-		      op01 = wide_int_to_tree (sizetype, off);
-		      return build4_loc (loc, ARRAY_REF, type, op00, op01,
-					 NULL_TREE, NULL_TREE);
-		    }
+		  off = off + wi::to_offset (min);
+		  op01 = wide_int_to_tree (sizetype, off);
+		  return build4_loc (loc, ARRAY_REF, type, op00, op01,
+				     NULL_TREE, NULL_TREE);
 		}
 	    }
 	}

	Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-08 17:23       ` Marek Polacek
@ 2017-08-14  8:32         ` Richard Biener
  2017-08-16 10:51           ` Marek Polacek
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2017-08-14  8:32 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches, Jakub Jelinek

On Tue, Aug 8, 2017 at 7:23 PM, Marek Polacek <polacek@redhat.com> wrote:
> On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote:
>> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
>> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
>> >> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
>> >> > In my recent change I failed to check whether the type domain
>> >> > of a type is non-NULL and this goof causes crashing on this
>> >> > testcase.
>> >> >
>> >> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>> >> >
>> >> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
>> >> >
>> >> >  PR middle-end/81737
>> >> >  * fold-const.c (fold_indirect_ref_1): Check type_domain.
>> >> >
>> >> >  * gcc.dg/pr81737.c: New test.
>> >>
>> >> The old code was assuming size_zero_node if type_domain is NULL
>> >> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed
>> >might
>> >> be wrong perhaps for Fortran or Ada.
>>
>> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review).  IIRC there are at least one other 'copy' of the folding somewhere.
>
> Sure, this patch should do it:
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-08-08  Marek Polacek  <polacek@redhat.com>
>
>         PR middle/81695
>         * fold-const.c (fold_indirect_ref_1): Restore original behavior
>         regarding size_zero_node.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index 5a118ca50a1..2c47d1d16a4 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
>                    && type == TREE_TYPE (op00type))
>             {
>               tree type_domain = TYPE_DOMAIN (op00type);
> -             tree min;
> +             tree min = size_zero_node;
>               if (type_domain != NULL_TREE
> -                 && (min = TYPE_MIN_VALUE (type_domain))
> +                 && TYPE_MIN_VALUE (type_domain)
>                   && TREE_CODE (min) == INTEGER_CST)
> +               min = TYPE_MIN_VALUE (type_domain);

I think this is wrong for non-INTEGER_CST TYPE_MIN_VALUE.

Richard.

> +             offset_int off = wi::to_offset (op01);
> +             offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> +             offset_int remainder;
> +             off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
> +             if (remainder == 0)
>                 {
> -                 offset_int off = wi::to_offset (op01);
> -                 offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> -                 offset_int remainder;
> -                 off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
> -                 if (remainder == 0)
> -                   {
> -                     off = off + wi::to_offset (min);
> -                     op01 = wide_int_to_tree (sizetype, off);
> -                     return build4_loc (loc, ARRAY_REF, type, op00, op01,
> -                                        NULL_TREE, NULL_TREE);
> -                   }
> +                 off = off + wi::to_offset (min);
> +                 op01 = wide_int_to_tree (sizetype, off);
> +                 return build4_loc (loc, ARRAY_REF, type, op00, op01,
> +                                    NULL_TREE, NULL_TREE);
>                 }
>             }
>         }
>
>         Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-14  8:32         ` Richard Biener
@ 2017-08-16 10:51           ` Marek Polacek
  2017-08-16 13:38             ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2017-08-16 10:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Jakub Jelinek

On Mon, Aug 14, 2017 at 10:22:09AM +0200, Richard Biener wrote:
> On Tue, Aug 8, 2017 at 7:23 PM, Marek Polacek <polacek@redhat.com> wrote:
> > On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote:
> >> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
> >> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
> >> >> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
> >> >> > In my recent change I failed to check whether the type domain
> >> >> > of a type is non-NULL and this goof causes crashing on this
> >> >> > testcase.
> >> >> >
> >> >> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >> >> >
> >> >> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
> >> >> >
> >> >> >  PR middle-end/81737
> >> >> >  * fold-const.c (fold_indirect_ref_1): Check type_domain.
> >> >> >
> >> >> >  * gcc.dg/pr81737.c: New test.
> >> >>
> >> >> The old code was assuming size_zero_node if type_domain is NULL
> >> >> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed
> >> >might
> >> >> be wrong perhaps for Fortran or Ada.
> >>
> >> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review).  IIRC there are at least one other 'copy' of the folding somewhere.
> >
> > Sure, this patch should do it:
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2017-08-08  Marek Polacek  <polacek@redhat.com>
> >
> >         PR middle/81695
> >         * fold-const.c (fold_indirect_ref_1): Restore original behavior
> >         regarding size_zero_node.
> >
> > diff --git gcc/fold-const.c gcc/fold-const.c
> > index 5a118ca50a1..2c47d1d16a4 100644
> > --- gcc/fold-const.c
> > +++ gcc/fold-const.c
> > @@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
> >                    && type == TREE_TYPE (op00type))
> >             {
> >               tree type_domain = TYPE_DOMAIN (op00type);
> > -             tree min;
> > +             tree min = size_zero_node;
> >               if (type_domain != NULL_TREE
> > -                 && (min = TYPE_MIN_VALUE (type_domain))
> > +                 && TYPE_MIN_VALUE (type_domain)
> >                   && TREE_CODE (min) == INTEGER_CST)
> > +               min = TYPE_MIN_VALUE (type_domain);
> 
> I think this is wrong for non-INTEGER_CST TYPE_MIN_VALUE.

Ah, right, another try:

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-08-16  Marek Polacek  <polacek@redhat.com>

	PR middle/81695
	* fold-const.c (fold_indirect_ref_1): Restore original behavior
	regarding size_zero_node.

diff --git gcc/fold-const.c gcc/fold-const.c
index 5a118ca50a1..0a05da0b49f 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -14109,22 +14109,19 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 		   && type == TREE_TYPE (op00type))
 	    {
 	      tree type_domain = TYPE_DOMAIN (op00type);
-	      tree min;
-	      if (type_domain != NULL_TREE
-		  && (min = TYPE_MIN_VALUE (type_domain))
-		  && TREE_CODE (min) == INTEGER_CST)
+	      tree min = size_zero_node;
+	      if (type_domain && TYPE_MIN_VALUE (type_domain))
+		min = TYPE_MIN_VALUE (type_domain);
+	      offset_int off = wi::to_offset (op01);
+	      offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
+	      offset_int remainder;
+	      off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
+	      if (remainder == 0)
 		{
-		  offset_int off = wi::to_offset (op01);
-		  offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
-		  offset_int remainder;
-		  off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
-		  if (remainder == 0)
-		    {
-		      off = off + wi::to_offset (min);
-		      op01 = wide_int_to_tree (sizetype, off);
-		      return build4_loc (loc, ARRAY_REF, type, op00, op01,
-					 NULL_TREE, NULL_TREE);
-		    }
+		  off = off + wi::to_offset (min);
+		  op01 = wide_int_to_tree (sizetype, off);
+		  return build4_loc (loc, ARRAY_REF, type, op00, op01,
+				     NULL_TREE, NULL_TREE);
 		}
 	    }
 	}

	Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix middle-end/81737
  2017-08-16 10:51           ` Marek Polacek
@ 2017-08-16 13:38             ` Richard Biener
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Biener @ 2017-08-16 13:38 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches, Jakub Jelinek

On Wed, Aug 16, 2017 at 12:33 PM, Marek Polacek <polacek@redhat.com> wrote:
> On Mon, Aug 14, 2017 at 10:22:09AM +0200, Richard Biener wrote:
>> On Tue, Aug 8, 2017 at 7:23 PM, Marek Polacek <polacek@redhat.com> wrote:
>> > On Mon, Aug 07, 2017 at 04:07:49PM +0200, Richard Biener wrote:
>> >> On August 7, 2017 11:09:59 AM GMT+02:00, Marek Polacek <polacek@redhat.com> wrote:
>> >> >On Mon, Aug 07, 2017 at 10:58:09AM +0200, Jakub Jelinek wrote:
>> >> >> On Mon, Aug 07, 2017 at 10:47:51AM +0200, Marek Polacek wrote:
>> >> >> > In my recent change I failed to check whether the type domain
>> >> >> > of a type is non-NULL and this goof causes crashing on this
>> >> >> > testcase.
>> >> >> >
>> >> >> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>> >> >> >
>> >> >> > 2017-08-07  Marek Polacek  <polacek@redhat.com>
>> >> >> >
>> >> >> >  PR middle-end/81737
>> >> >> >  * fold-const.c (fold_indirect_ref_1): Check type_domain.
>> >> >> >
>> >> >> >  * gcc.dg/pr81737.c: New test.
>> >> >>
>> >> >> The old code was assuming size_zero_node if type_domain is NULL
>> >> >> or TYPE_MIN_VALUE is NULL, which is reasonable for C/C++, but indeed
>> >> >might
>> >> >> be wrong perhaps for Fortran or Ada.
>> >>
>> >> It's how the middle-end defines it, so please restore this behavior (sorry for missing this in the review).  IIRC there are at least one other 'copy' of the folding somewhere.
>> >
>> > Sure, this patch should do it:
>> >
>> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>> >
>> > 2017-08-08  Marek Polacek  <polacek@redhat.com>
>> >
>> >         PR middle/81695
>> >         * fold-const.c (fold_indirect_ref_1): Restore original behavior
>> >         regarding size_zero_node.
>> >
>> > diff --git gcc/fold-const.c gcc/fold-const.c
>> > index 5a118ca50a1..2c47d1d16a4 100644
>> > --- gcc/fold-const.c
>> > +++ gcc/fold-const.c
>> > @@ -14109,22 +14109,21 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
>> >                    && type == TREE_TYPE (op00type))
>> >             {
>> >               tree type_domain = TYPE_DOMAIN (op00type);
>> > -             tree min;
>> > +             tree min = size_zero_node;
>> >               if (type_domain != NULL_TREE
>> > -                 && (min = TYPE_MIN_VALUE (type_domain))
>> > +                 && TYPE_MIN_VALUE (type_domain)
>> >                   && TREE_CODE (min) == INTEGER_CST)
>> > +               min = TYPE_MIN_VALUE (type_domain);
>>
>> I think this is wrong for non-INTEGER_CST TYPE_MIN_VALUE.
>
> Ah, right, another try:
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-08-16  Marek Polacek  <polacek@redhat.com>
>
>         PR middle/81695
>         * fold-const.c (fold_indirect_ref_1): Restore original behavior
>         regarding size_zero_node.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index 5a118ca50a1..0a05da0b49f 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -14109,22 +14109,19 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
>                    && type == TREE_TYPE (op00type))
>             {
>               tree type_domain = TYPE_DOMAIN (op00type);
> -             tree min;
> -             if (type_domain != NULL_TREE
> -                 && (min = TYPE_MIN_VALUE (type_domain))
> -                 && TREE_CODE (min) == INTEGER_CST)
> +             tree min = size_zero_node;
> +             if (type_domain && TYPE_MIN_VALUE (type_domain))
> +               min = TYPE_MIN_VALUE (type_domain);
> +             offset_int off = wi::to_offset (op01);
> +             offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> +             offset_int remainder;
> +             off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
> +             if (remainder == 0)

Ok with && TREE_CODE (min) == INTEGER_CST here.

Richard.

>                 {
> -                 offset_int off = wi::to_offset (op01);
> -                 offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
> -                 offset_int remainder;
> -                 off = wi::divmod_trunc (off, el_sz, SIGNED, &remainder);
> -                 if (remainder == 0)
> -                   {
> -                     off = off + wi::to_offset (min);
> -                     op01 = wide_int_to_tree (sizetype, off);
> -                     return build4_loc (loc, ARRAY_REF, type, op00, op01,
> -                                        NULL_TREE, NULL_TREE);
> -                   }
> +                 off = off + wi::to_offset (min);
> +                 op01 = wide_int_to_tree (sizetype, off);
> +                 return build4_loc (loc, ARRAY_REF, type, op00, op01,
> +                                    NULL_TREE, NULL_TREE);
>                 }
>             }
>         }
>
>         Marek

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-08-16 10:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07  8:47 [PATCH] Fix middle-end/81737 Marek Polacek
2017-08-07  8:58 ` Jakub Jelinek
2017-08-07  9:10   ` Marek Polacek
2017-08-07 14:07     ` Richard Biener
2017-08-08 17:23       ` Marek Polacek
2017-08-14  8:32         ` Richard Biener
2017-08-16 10:51           ` Marek Polacek
2017-08-16 13:38             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).