On 2/4/20 7:35 AM, Richard Biener wrote:
...
Jakub/Richi, comments on this hunk?+ tree ref = TREE_OPERAND (TREE_OPERAND (arg, 0), 0); + tree off = TREE_OPERAND (arg, 1); + if ((TREE_CODE (ref) == PARM_DECL || VAR_P (ref)) + && (!DECL_EXTERNAL (ref) + || !array_at_struct_end_p (arg))) + { I think you'd want decl_binds_to_current_def_p (ref) instead of !DECL_EXTERNAL.
I've made the change.
Since 'arg' is originally a pointer array_at_struct_end_p is meaningless here since that's about the structure of a reference while the pointer is just a value.
array_at_struct_end_p handles MEM_REF by looking at the argument (i.e., at the DECL when it is one), so its use here avoids DECLs with flexible arrays but allows others. In other words, I don't want to exclude MEM_REFs to a in: extern char a[4]; just because a is extern.
So if you're concerned the objects size might not be as it looks like then you have to rely on decl_binds_to_current_def_p only.
I'm only concerned about sizes of extern objects of struct types with flexible array members. I believe others are handled fine.
You also shouldn't use 'off' natively in the code below but use mem_ref_offset to access the embedded offset which is to be interpreted as signed integer (it's a pointer as you use it). You compare it against an unsigned size...
I've changed it in the latest revision of the patch. Martin
