https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128697
Bug ID: 128697
Summary: var-tracking does not terminate with -g -Os (dataflow
oscillates in endless loop block)
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: frank.mehnert at googlemail dot com
Target Milestone: ---
The compiler hangs in the var-tracking pass (100% CPU, never finishes) when
compiling the following test case with -g and -Os. Without -g, it compiles
instantly.
Test case (t.c):
struct cpu { unsigned v; };
static void raw_exit(struct cpu c) { (void)c; }
static void (*exit_question)(struct cpu) = raw_exit;
void cov_print(void) __attribute__((weak));
void set_exit(void (*eq)(struct cpu)) { exit_question = eq; }
void
terminate_from(struct cpu cpu)
{
if (exit_question && !cov_print)
exit_question(cpu);
if (cov_print)
cov_print();
for (;;)
__asm__ volatile ("nop");
}
Command:
aarch64-linux-gnu-gcc -c -g -Os t.c
Results with aarch64-linux-gnu-gcc:
11.5.0 -g -Os ok
13.5.0 -g -Os hangs
14.4.0 -g -Os hangs
15.3.0 -g -Os hangs
16.2.0 -g -Os hangs
16.2.0 -g -O2, -g -O3 hang
16.2.0 -g -O1, -g -Og ok
16.2.0 -Os ok
16.2.0 -g -Os -fno-var-tracking ok
16.2.0 -g -Os -fno-var-tracking-assignments ok
The same test case (with "wait" or "nop" in the asm) also hangs on MIPS
(-mabi=32 -march=mips32r6 -mno-abicalls -fno-pic -g -Os, also mips32r2 and
mips64r6) with GCC 13.4.0 and 14.2.0. GCC 12 was not tested. It does not hang
on arm-linux-gnueabihf-gcc 16.2.0 or on x86-64 GCC 16.2.0.
All of the following are needed to trigger the hang:
- the struct passed by value (an int parameter compiles fine),
- the test "!cov_print" of the weak symbol in the first condition,
- the call cov_print(),
- the endless loop at the end.
The original code comes from an OS kernel (terminate function that ends in an
endless "wait" loop) and was reduced manually.
Workaround: -fno-var-tracking-assignments, or restructuring the code so that
cov_print is tested only once (if (cov_print) ... else ...).