https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92226
Bug ID: 92226 Summary: [10 Regression] live nul char store to array eliminated Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- One of the recent strlen changes (bisection points to r277076) leads to a miscompilation of the following test case. The problem is that the nul-over-nul optimization is being applied when it shouldn't be. It looks to me like the change above might have exposed a latent bug here, or the change is incomplete. Before the change, compare_nonzero_chars returned -1 in this case which doesn't really correspond to the documentation of the function -- that SI might not start with OFF nonzero characters, where SI length is in [0, 7] and OFF is 0 -- but now it returns 0. That also doesn't reflect exactly what's going on. $ cat a.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout a.c struct A { char a[8], c; }; void f (void*); void g (const char *s) { if (__builtin_strlen (s) > 7) return; struct A a; __builtin_strcpy (a.a, s); a.a[0] = 0; // incorrectly eliminated f (&a); } ;; Function g (g, funcdef_no=0, decl_uid=1935, cgraph_uid=1, symbol_order=0) g (const char * s) { struct A a; long unsigned int _1; long unsigned int _10; <bb 2> [local count: 1073741824]: _1 = __builtin_strlen (s_4(D)); if (_1 > 7) goto <bb 3>; [51.12%] else goto <bb 4>; [48.88%] <bb 3> [local count: 548896821]: a ={v} {CLOBBER}; goto <bb 5>; [100.00%] <bb 4> [local count: 524845004]: _10 = _1 + 1; __builtin_memcpy (&a.a, s_4(D), _10); f (&a); a ={v} {CLOBBER}; <bb 5> [local count: 1073741824]: return; }