https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85244
--- Comment #7 from rguenther at suse dot de <rguenther at suse dot de> --- On Fri, 6 Apr 2018, jakub at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85244 > > --- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- > On the other side, this is done only if known_size_p (maxsize), don't we want > to reset it even if maxsize isn't known? All true. So like the following, wasting a few cycles in the !known_size_p && seen_variable_array_ref case Index: gcc/tree-dfa.c =================================================================== --- gcc/tree-dfa.c (revision 259082) +++ gcc/tree-dfa.c (working copy) @@ -438,7 +438,7 @@ get_ref_base_and_extent (tree exp, poly_ referenced the last field of a struct or a union member then we have to adjust maxsize by the padding at the end of our field. */ - if (seen_variable_array_ref && known_size_p (maxsize)) + if (seen_variable_array_ref) { tree stype = TREE_TYPE (TREE_OPERAND (exp, 0)); tree next = DECL_CHAIN (field); @@ -454,7 +454,7 @@ get_ref_base_and_extent (tree exp, poly_ || ssize == NULL || !poly_int_tree_p (ssize)) maxsize = -1; - else + else if (known_size_p (maxsize)) { poly_offset_int tem = (wi::to_poly_offset (ssize) @@ -464,6 +464,11 @@ get_ref_base_and_extent (tree exp, poly_ maxsize += tem; } } + /* An component ref with an adjacent field up in the + structure hierarchy constrains the size of any variable + array ref lower in the access hierarchy. */ + else + seen_variable_array_ref = false; } } else