https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106349
Bug ID: 106349
Summary: strlen reimplementation produces infinite loop with
-Os
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent.riviere at freesbee dot fr
Target Milestone: ---
Target: m68k-elf
Compiling a function named strlen with strlen-like body generates an infinite
loop.
$ cat bug.c
#include <stddef.h>
size_t strlen(const char *str)
{
size_t n;
for (n = 0; *str++; n++);
return n;
}
$ m68k-elf-gcc -S bug.c -o - -Os
#NO_APP
.file "bug.c"
.text
.align 2
.globl strlen
.type strlen, @function
strlen:
jra strlen
.size strlen, .-strlen
.ident "GCC: (GNU) 12.1.0"
The only generated code is the infinite loop. That's a nonsense.
This issue doesn't occur with -O2.