https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102711
Bug ID: 102711
Summary: Infinite loop with extern calls removed with -O2 or
higher
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: andy.koppe at analog dot com
Target Milestone: ---
Created attachment 51591
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51591&action=edit
Minimized example
Compiling the minimised example below (and attached) with -O2 or higher, if
FAIL is defined, the second infinite loop is removed. Code is produced for it
when FAIL is not defined.
Reproduced with gcc 10.3.1 for aarch64-none-elf, gcc 11.2.0 for
x86_64-pc-cygwin, and gcc 9.3.0 for x86_64-linux-gnu.
$ cat test.c
int bar(void);
void foo(void)
{
if (!bar())
for (;;);
for (;;) {
static int flag = 0;
int ret = 0;
bar();
if (flag) {
ret = bar();
if (!ret)
ret = bar();
}
flag = !bar();
#ifdef FAIL
if (!ret)
#endif
bar();
}
}
$ aarch64-none-elf-gcc -O2 -S test.c -DFAIL
$ cat test.s
.arch armv8-a
.file "test.c"
.text
.align 2
.p2align 4,,11
.global foo
.type foo, %function
foo:
stp x29, x30, [sp, -16]!
mov x29, sp
bl bar
.L2:
b .L2
.size foo, .-foo
.ident "GCC: (GNU Toolchain for the A-profile Architecture
10.3-2021.07 (arm-10.29)) 10.3.1 20210621"