FPC optimization bug (FORLOOP or DFA)
FPC Trunk
Windows 11 x64 FPC x64
program i20241020_01;
{$mode objfpc}
//{$OPTIMIZATION NODFA}
//{$OPTIMIZATION NOFORLOOP}
type
TObj = object
arr: array [0..512] of byte;
constructor init;
destructor done; virtual;
end;
const
cnt=44;
var
arr: array[0..cnt] of TObj;
i: int32;
constructor TObj.init;
begin
end;
destructor TObj.done;
begin
end;
begin
for i:=0 to cnt do arr[i].init;
for i:=0 to cnt do arr[i].done; // AV here in run-time
end.
Compile:
C:\fpclaztrunk\fpc\bin\x86_64-win64\fpc.exe -n -O3 -FuC:\fpclaztrunk\fpc\units\x86_64-win64\rtl i20241020_01.pas
Run:
>i20241020_01.exe
Runtime error 216 at $000000010000165D
$000000010000165D
With NODFA
or NOFORLOOP
or -O1
, -O2
- OK