https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61773
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Proper testcase (string init was missing): char *stpcpy (char*, const char *); char *foo (void) { char *p = __builtin_calloc (64, 1); char *q = __builtin_calloc (64, 1); __builtin_strcat (q, "abcde"); __builtin_strcat (p, "ab"); p[1] = 'a'; __builtin_strcat (p, q); return q; } this isn't optimized either, only when p[0] = 'a'; is there the last strcat will be optimized with known strlen of p. Hmm, a p[1] = '\0' isn't optimized either. Unfortunately strlen isn't very verbose in its -details dump.