https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117912
--- Comment #17 from Siddhesh Poyarekar <siddhesh at gcc dot gnu.org> --- (In reply to Siddhesh Poyarekar from comment #16) > (In reply to Andrew Pinski from comment #15) > > (In reply to Jakub Jelinek from comment #14) > > > struct S { int a; int b[24]; int c[24]; int d; }; > > > void bar (int *); > > > > > > __SIZE_TYPE__ > > > foo (struct S *p) > > > { > > > bar (&p->b[24]); > > > bar (&p->c[0]); > > > return __builtin_object_size (&p->c[0], 1); > > > } > > Couldn't VN/CSE, when eliminating an expression involving pointers to > component_refs, pick the one that points to the beginning of a component > rather than the end? That should solve both these problems. Sorry, hit submit before finishing my thought. There's a chance that it could miss actual sub-object overwrites to, e.g. &p->b[24] but hopefully early_objsz will catch that and pass it on to objsz.