https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90435
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Your implementation of calloc will be calling itself due to the optimization of malloc followed by memset into calloc. You need to use -fno-tree-loop-distribute-patterns for that case since your implementation of malloc calls calloc in some cases. One other thing is you are most likely also violating C aliasing rules; try -fno-strict-aliasing and see if that helps.