https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92041
Bug ID: 92041 Summary: m68k optimizations (-O2, -O3 or -Ofast) generates wrong code Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: djipi.mari at gmail dot com Target Milestone: --- Host: x86 Target: m68k-elf This code: void *calloc(size_t num_elements, size_t size) { void *ptr = malloc(num_elements*size); if (ptr) { memset(ptr, 0, (num_elements*size)); } return ptr; } Generates this assembly when using -O2, -O3 or -Ofast: calloc: move.l 8(%sp),%d0 moveq #1,%d1 move.l %d1,8(%sp) move.l %d0,-(%sp) move.l 8(%sp),-(%sp) jsr __mulsi3 addq.l #8,%sp move.l %d0,4(%sp) jra calloc The issue appears since the 9.1.0, previous versions do not have such issues.