GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

Fixes ICE with -Winfinite-recursion by using iteration instead of recursion.

Avoids stack overflows when using -Winfinite-recursion on very large functions by switching to an iterative approach.

The implementation of -Winfinite-recursion used a recursive algorithm to detect infinite recursion, which could lead to stack overflows when processing very large functions. This commit replaces the recursive calls with an iterative approach, avoiding stack exhaustion. The underlying logic for detecting infinite recursion remains unchanged.

In Details

The -Winfinite-recursion flag triggers warnings when the compiler detects potentially infinite recursion in a function. The fix modifies pass_warn_recursion::find_function_exit() in gimple-warn-recursion.cc, replacing recursive calls with iteration. This avoids stack overflows during analysis of very large functions, a common issue when dealing with compiler-generated code or heavily templated code.

For Context

When compiling code, GCC can detect functions that might call themselves infinitely, leading to a stack overflow at runtime. The -Winfinite-recursion flag enables this warning. However, the warning mechanism itself could run out of memory (specifically, stack space) when analyzing extremely large functions. This commit changes the internal implementation of the warning to use a loop instead of recursion, preventing the compiler from crashing in these cases.

Filed Under: gccwarningrecursionstack overflowbugfix