https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109609
--- Comment #7 from Gabriel Burca <gburca-gnu at ebixio dot com> --- Here's the code that still fails with -O3 -fno-optimize-sibling-calls: ``` #include <string.h> #include <stdint.h> #define N 23 #define MAX_LEN 13 char dst[N + 1]; void stringify(uint64_t id) { char buf[MAX_LEN]; char *ptr = buf + sizeof(buf); // start from the end of buf *(--ptr) = '\0'; // terminate string while (id && ptr > buf) { *(--ptr) = static_cast<char>(id % 10) + '0'; id /= 10; } __builtin_strncpy(dst, ptr, N); // copy ptr/buf to dst } int main() { stringify(12345); if (strcmp(dst, "12345")) __builtin_abort(); } ``` Notably this only fails with -O3, not with -O2