https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80769
Bug ID: 80769 Summary: Invalid delayed string length computation in tree-ssa-strlen.c Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rsandifo at gcc dot gnu.org Target Milestone: --- This testcase below (which uses strlenopt.h in gcc/testsuite/gcc.dg) fails at -O2 but passes with -O0. tree-ssa-strlen.c isn't invalidating delayed string lengths when "x" is added to the end. #define USE_GNU #include "strlenopt.h" __attribute__((noinline, noclone)) int bar (char *p1, const char *q) { strcpy (p1, "abcde"); char *p2 = strchr (p1, '\0'); strcpy (p2, q); char *p3 = strchr (p2, '\0'); memcpy (p3, "x", 2); return strlen (p1); } int main (void) { char buffer[10]; int res = bar (buffer, "foo"); if (strcmp (buffer, "abcdefoox") != 0 || res != 9) abort (); return 0; }