https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121586
Bug ID: 121586 Summary: aliased built-in function generated code calling itself Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bpar at skl dot vc Target Milestone: --- For an embedded project I wrote a simple version of clib's "memset". When I compiled with -O2, gcc produced weird code including a recursive call. This bug appears to have stated with v10 and continues up to v15 (I didn't try 16). I only tried arm 32 bit architectures but I think it happens in aarch64 as well. It looks like gcc "recognizes" that the code is doing a memset and then tried to call glib's memset. But the function is called memset, so this is recursive. -O1 doesn't have the problem. and adding -fnobuiltin also causes the problem to go away. #include <stdint.h> #include <stddef.h> void *memset(void *s, int c, size_t n) { uint8_t *p = (uint8_t *)s; while (n > 0) { *p++ = c; n--; } return s; } kinda dumb, yes. but I think it should recognize that it's trying to optimize by calling the function it's optimizing.