Under some apparently rare conditions a DECL can have a non-
constant size that the fix for bug 85753 committed last week
into trunk was not prepared for.  The attached change removes
the assumption to avoid the ICE that otherwise results.

Martin

PS The test case that triggers the ICE makes use of variable-
length structs and local functions, both of which are fairly
obscure GCC extensions that I tend to forget to consider when
writing GCC code.  I tried to construct a less convoluted (and
strictly conforming) test case but in all of those I've come
up with a variable-length object is represented by a pointer
(pointing to memory returned by __builtin_alloca_with_align()).
Is there a straightforward way to create a variable-size DECL
that doesn't rely on GCC extensions?
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.


Index: gcc/gimple-ssa-warn-restrict.c
===================================================================
--- gcc/gimple-ssa-warn-restrict.c	(revision 260371)
+++ gcc/gimple-ssa-warn-restrict.c	(working copy)
@@ -278,7 +278,10 @@ builtin_memref::builtin_memref (tree expr, tree si
       && 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)
     {
Index: gcc/testsuite/gcc.dg/Wrestrict-17.c
===================================================================
--- gcc/testsuite/gcc.dg/Wrestrict-17.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/Wrestrict-17.c	(working copy)
@@ -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;
+}

Reply via email to