PR tree-optimization/85826 - ICE in gimple-ssa-warn-restruct on

PR tree-optimization/85826 - ICE in gimple-ssa-warn-restruct on
   a variable-length struct

gcc/ChangeLog:

	PR tree-optimization/85826
	* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Avoid
	assuming that a DECL necesarily has a constant size.

gcc/testsuite/ChangeLog:

	PR tree-optimization/85826
	* gcc.dg/Wrestrict-17.c: New test.

From-SVN: r260537
This commit is contained in:
Martin Sebor 2018-05-22 15:22:16 +00:00 committed by Martin Sebor
parent f141b40a18
commit 9f855c10d6
4 changed files with 35 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2018-05-22 Martin Sebor <msebor@redhat.com>
PR tree-optimization/85826
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Avoid
assuming that a DECL necesarily has a constant size.
2018-05-22 Richard Sandiford <richard.sandiford@linaro.org>
PR middle-end/85862

View file

@ -278,7 +278,10 @@ builtin_memref::builtin_memref (tree expr, tree size)
&& array_at_struct_end_p (ref))
; /* Use the maximum possible offset for last member arrays. */
else if (tree basesize = TYPE_SIZE_UNIT (basetype))
maxoff = wi::to_offset (basesize);
if (TREE_CODE (basesize) == INTEGER_CST)
/* Size could be non-constant for a variable-length type such
as a struct with a VLA member (a GCC extension). */
maxoff = wi::to_offset (basesize);
if (offrange[0] >= 0)
{

View file

@ -1,3 +1,8 @@
2018-05-22 Martin Sebor <msebor@redhat.com>
PR tree-optimization/85826
* gcc.dg/Wrestrict-17.c: New test.
2018-05-22 Richard Sandiford <richard.sandiford@linaro.org>
* gcc.dg/torture/pr85862.c: Rename to...

View file

@ -0,0 +1,20 @@
/* PR tree-optimization/85826 - ICE in gimple-ssa-warn-restruct on
a variable-length struct
{ dg-do compile }
{ dg-options "-O2 -Wall" } */
int f (int n)
{
typedef struct { int a[n]; } S;
S a;
__attribute__ ((noinline)) S g (void) { return a; }
a.a[0] = 1;
a.a[9] = 2;
S b;
b = g ();
return b.a[0] == 1 && b.a[9] == 2;
}