From: Martin Sebor Date: Tue, 22 May 2018 15:22:16 +0000 (+0000) Subject: PR tree-optimization/85826 - ICE in gimple-ssa-warn-restruct on X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f855c10d6be14e4ac73fc55625d4799ca939cf8;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5e09013ad64..ca5faf0b8c7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-05-22 Martin Sebor + + 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 PR middle-end/85862 diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index 9f23f57c426..637ed3cc290 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 912a1f26886..434a118fd75 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-05-22 Martin Sebor + + PR tree-optimization/85826 + * gcc.dg/Wrestrict-17.c: New test. + 2018-05-22 Richard Sandiford * 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 00000000000..8061fda5985 --- /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; +}