[Compiler] Recursive inline causes Infinite loop in compiler
Summary
If an inline routine calls itself (or two inline routiness reference each other etc.), it's possible to trigger an infinite loop in the compiler that only stops when some kind of memory error occurs.
System Information
- Processor architecture: Cross-platform
- Compiler version: Trunk
Steps to reproduce
Have an inline routine that calls itself recursively (see example project for how this can work).
Example Project
Best to compile under -O2.
program InlineTest;
{$MODE OBJFPC}
function TestFunc(X: Integer): Integer; inline;
begin
TestFunc := TestFunc(X + 1);
end;
begin
WriteLn(TestFunc(5));
end.
What is the current bug behavior?
The compiler does not build the project, instead getting stuck in an infinite loop and eventually (after several minutes) crashing.
What is the expected (correct) behavior?
The program should successfully compile (even if it itself contains an infinite loop).
Possible fixes
The cause is commit 4e3e2136 - by clearing the tnf_pass1_done flag, the compiler attempts to expand nested inline routines ad infinitum.