Hi, this patch makes array_at_struct_end_p to not give up at MEM_REF as discussed on IRC few weeks back. This happens a lot for Fortran testcases. I am bootstrapping/regtesteing x86_64-linux and intend to commit it as obvoius.
We sill miss a lot of upper bound for fortran code because we can not look up the origin of the array. For example: type <array_type 0x7ffff6df3690 type <array_type 0x7ffff6df30a8 type <integer_type 0x7ffff6c34540 character(kind=1)> string-flag QI size <integer_cst 0x7ffff6c30cc0 constant 8> unit size <integer_cst 0x7ffff6c30cd8 constant 1> align 8 symtab 0 alias set 7 canonical type 0x7ffff6df30a8 domain <integer_type 0x7ffff6df3000> pointer_to_this <pointer_type 0x7ffff6df7c78>> BLK align 8 symtab 0 alias set -1 canonical type 0x7ffff6df3690 domain <integer_type 0x7ffff6c515e8 type <integer_type 0x7ffff6c34930 integer(kind=8)> DI size <integer_cst 0x7ffff6c30bd0 constant 64> unit size <integer_cst 0x7ffff6c30be8 constant 8> align 64 symtab 0 alias set -1 canonical type 0x7ffff6c515e8 precision 64 min <integer_cst 0x7ffff6c4b258 0>> pointer_to_this <pointer_type 0x7ffff6df3738>> arg 0 <ssa_name 0x7ffff6a9fbd0 type <pointer_type 0x7ffff6c492a0 type <void_type 0x7ffff6c49150 void> public unsigned DI size <integer_cst 0x7ffff6c30bd0 64> unit size <integer_cst 0x7ffff6c30be8 8> align 64 symtab 0 alias set 3 canonical type 0x7ffff6c492a0 pointer_to_this <pointer_type 0x7ffff6c513f0>> visiteddef_stmt _92 = __builtin_malloc (5); version 92 ptr-info 0x7ffff6a91df8> arg 1 <integer_cst 0x7ffff6decca8 type <pointer_type 0x7ffff6df37e0> constant 0>> .... <mem_ref 0x7ffff6a935a0 type <array_type 0x7ffff6df30a8 type <integer_type 0x7ffff6c34540 character(kind=1) public unsigned string-flag QI size <integer_cst 0x7ffff6c30cc0 constant 8> unit size <integer_cst 0x7ffff6c30cd8 constant 1> align 8 symtab 0 alias set 7 canonical type 0x7ffff6c34540 precision 8 min <integer_cst 0x7ffff6c30cf0 0> max <integer_cst 0x7ffff6c30c90 255> pointer_to_this <pointer_type 0x7ffff6c511f8>> string-flag QI size <integer_cst 0x7ffff6c30cc0 8> unit size <integer_cst 0x7ffff6c30cd8 1> align 8 symtab 0 alias set 7 canonical type 0x7ffff6df30a8 domain <integer_type 0x7ffff6df3000 type <integer_type 0x7ffff6c347e0 integer(kind=4)> SI size <integer_cst 0x7ffff6c30e10 constant 32> unit size <integer_cst 0x7ffff6c30e28 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff6df3000 precision 32 min <integer_cst 0x7ffff6c30f78 1> max <integer_cst 0x7ffff6c30f78 1>> pointer_to_this <pointer_type 0x7ffff6df7c78>> arg 0 <ssa_name 0x7ffff6a82798 type <pointer_type 0x7ffff6df7c78 type <array_type 0x7ffff6df30a8> public unsigned DI size <integer_cst 0x7ffff6c30bd0 constant 64> unit size <integer_cst 0x7ffff6c30be8 constant 8> align 64 symtab 0 alias set 6 canonical type 0x7ffff6df7c78 pointer_to_this <pointer_type 0x7ffff6df7f18>> visiteddef_stmt _16 = A.1[S.2_456]; version 16 ptr-info 0x7ffff6ac70a8> arg 1 <integer_cst 0x7ffff6e21b10 type <pointer_type 0x7ffff6df7c78> constant 0>> Moreover the trailin array code is probably all unnecesary for Fortran. Richard, I wonder if we don't want to add a flag to ARRAY_REF (or some other place) specifyin that given access is not going to go past the size of the array type? * tree.c (array_at_struct_end_p): Look through MEM_REFs. Index: tree.c =================================================================== --- tree.c (revision 236507) +++ tree.c (working copy) @@ -13076,6 +13076,13 @@ array_at_struct_end_p (tree ref) ref = TREE_OPERAND (ref, 0); } + if (TREE_CODE (ref) == MEM_REF + && TREE_CODE (TREE_OPERAND (ref, 0)) == ADDR_EXPR) + { + ref = TREE_OPERAND (TREE_OPERAND (ref, 0), 0); + gcc_assert (!handled_component_p (ref)); + } + /* If the reference is based on a declared entity, the size of the array is constrained by its given domain. (Do not trust commons PR/69368). */ if (DECL_P (ref)