aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-05-22 15:22:16 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-05-22 09:22:16 -0600
commit9f855c10d6be14e4ac73fc55625d4799ca939cf8 (patch)
tree26f442f9bb35bd3f8a13db2039ee7a8396748413 /gcc
parentf141b40a181eea1546d0b6930c4eb386cd28241f (diff)
downloadgcc-9f855c10d6be14e4ac73fc55625d4799ca939cf8.zip
gcc-9f855c10d6be14e4ac73fc55625d4799ca939cf8.tar.gz
gcc-9f855c10d6be14e4ac73fc55625d4799ca939cf8.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/gimple-ssa-warn-restrict.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Wrestrict-17.c20
4 files changed, 35 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5e09013..ca5faf0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 9f23f57..637ed3c 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -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)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 912a1f2..434a118 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..8061fda
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wrestrict-17.c
@@ -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;
+}