optimization loopunroll conflicts with inline modifier
Original Reporter info from Mantis: Nitorami
-
Reporter name:
Original Reporter info from Mantis: Nitorami
- Reporter name:
Description:
The compiler crashes on trying to compile the attached code.
{$mode objfpc}
{$OPTIMIZATION LOOPUNROLL}
type TList = array [0..3] of integer;
var worklist, tmplist : TList;
function flip (const list1: TList; var list2: TList): integer; inline;
var i: integer;
begin
for i := 0 to 3 do list2[i] := list1[i];
end;
begin
flip (worklist, tmplist);
end.
Steps to reproduce:
fpc loopunroll.pas
Same problem with 32bit and 64bit version.
Additional information:
The original program used an array of size 16, and system.move to copy the arrays. When inlining the flip function, it produced a wrong result. I changed the move to a for loop and still got the wrong result.
With range check on, the debugger then threw a range check error in the line containing the loop, although the code is correct.
The original program was multithreaded so I thought this might be a threading issue, but then managed to reduce the code while maintaining the problem.
With an array size of 16 and range check ON, you'll see a range check error at runtime.
With range check OFF, the code may run but generate unexpected results within a larger program.
With an array size of 3 or less the compiler will crash.
Mantis conversion info:
- Mantis ID: 35224
- OS: Windows 10
- Platform: PC
- Version: 3.0.4