https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116556
Bug ID: 116556 Summary: __builtin_object_size does not handle `ptr + (PHI<4,8>)`, only `PHI<ptr+4,ptr+8>` Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` void __attribute__ ((noinline)) test9 (unsigned cond) { char *buf2 = __builtin_malloc (10); char *p; __SIZE_TYPE__ t; if (cond) t = 8; else t = 4; p = &buf2[t]; if (__builtin_object_size (&p[0], 0) != 6) __builtin_abort (); } void __attribute__ ((noinline)) test9a (unsigned cond) { char *buf2 = __builtin_malloc (10); char *p; __SIZE_TYPE__ t; if (cond) p = &buf2[8]; else p = &buf2[4]; if (__builtin_object_size (&p[0], 0) != 6) __builtin_abort (); } ``` The __builtin_object_size does not handle the pointer in test9 but does handle the one in test9a. This is reduced from gcc.dg/builtin-object-size-1.c when improving phiopt's factor_out_conditional_operation to handle more than just unary operators.