PR tree-optimization/85826 - ICE in gimple-ssa-warn-restruct on
authorMartin Sebor <msebor@redhat.com>
Tue, 22 May 2018 15:22:16 +0000 (15:22 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 22 May 2018 15:22:16 +0000 (09:22 -0600)
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

gcc/ChangeLog
gcc/gimple-ssa-warn-restrict.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wrestrict-17.c [new file with mode: 0644]

index 5e09013ad6465c37b59ad2b7a5db721fa356515e..ca5faf0b8c708625734eafbbc28d9c57d584d5ca 100644 (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
index 9f23f57c426d1b0943d6235ae15dd25fb6cf2067..637ed3cc29094e16ca33d7cfa7c077add967ef77 100644 (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)
     {
index 912a1f26886741e68a055804bb42bf5ea4229367..434a118fd754c0462789cf27108fd3dedbe74b7f 100644 (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...
diff --git a/gcc/testsuite/gcc.dg/Wrestrict-17.c b/gcc/testsuite/gcc.dg/Wrestrict-17.c
new file mode 100644 (file)
index 0000000..8061fda
--- /dev/null
@@ -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;
+}