From: Martin Jambor Date: Wed, 19 Feb 2020 10:13:52 +0000 (+0100) Subject: sra: Do not create zero sized accesses (PR 93776) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=51faf07cef9293af544bfacc7d0b320ab90d7d60;p=gcc.git sra: Do not create zero sized accesses (PR 93776) SRA can get a bit confused with zero-sized accesses like the one in the testcase. Since there is nothing in the access, nothing is scalarized, but we can get order of the structures wrong, which the verifier is not happy about. Fixed by simply ignoring such accesses. 2020-02-19 Martin Jambor PR tree-optimization/93776 * tree-sra.c (create_access): Do not create zero size accesses. (get_access_for_expr): Do not search for zero sized accesses. testsuite/ * gcc.dg/tree-ssa/pr93776.c: New test. --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b53f9a2f07..7ebeaed89e0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-02-19 Martin Jambor + + PR tree-optimization/93776 + * tree-sra.c (create_access): Do not create zero size accesses. + (get_access_for_expr): Do not search for zero sized accesses. + 2020-02-19 Martin Jambor PR tree-optimization/93667 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8033fa0a3bb..df79951b6cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-19 Martin Jambor + + PR tree-optimization/93776 + * gcc.dg/tree-ssa/pr93776.c: New test. + 2020-02-19 Martin Jambor PR tree-optimization/93667 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c new file mode 100644 index 00000000000..c407a627718 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O1" } */ + +struct empty {}; +struct s { int i; }; +struct z +{ + int j; + struct empty e; + struct s s; + int k; +}; + +void bar (struct z); +void baz (int); + +void foo (void) +{ + struct z z, z2; + + z.k = 8; + z2.s.i = 1; + z = z2; + bar (z); + z.e = (struct empty) {}; + baz (z.k); +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 4c7d651e6b9..49f9001f7fb 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -926,6 +926,8 @@ create_access (tree expr, gimple *stmt, bool write) size = max_size; unscalarizable_region = true; } + if (size == 0) + return NULL; if (size < 0) { disqualify_candidate (base, "Encountered an unconstrained access."); @@ -3643,7 +3645,8 @@ get_access_for_expr (tree expr) return NULL; } - if (!bitmap_bit_p (candidate_bitmap, DECL_UID (base))) + if (max_size == 0 + || !bitmap_bit_p (candidate_bitmap, DECL_UID (base))) return NULL; return get_var_base_offset_size_access (base, offset, max_size);