fpc/tests/webtbs/tw39918.pp
J. Gareth "Curious Kit" Moreton fa76baa3d4 * New test to evaluate i39918
2022-10-22 13:07:16 +00:00

47 lines
923 B
ObjectPascal

{ %OPT=-O3 }
{ Test triggers incorrect AddMov2Mov optimisation
(second register not checked for modification) }
program tw39918;
type
ObjectA = object
Index: Cardinal;
end;
ObjectB = object
ObjectAArray: array of ObjectA;
TestString: String; //Needed for crash
end;
ObjectC = object
TestValue: Uint32;
end;
var
ObjectBArray: array of ObjectB;
ObjectCArray: array of ObjectC;
BIndex: Integer = 0;
begin
//Init variables
setlength(ObjectBArray, 1);
setlength(ObjectBArray[0].ObjectAArray, 1);
SetLength(ObjectCArray, 1);
ObjectCArray[0].TestValue := 0;
ObjectBArray[0].ObjectAArray[0].Index := 0;
ObjectBArray[0].TestString := 'Needed';
//Works
writeln(ObjectCArray[ObjectBArray[BIndex].ObjectAArray[0].Index].TestValue);
//Crash
with ObjectBArray[BIndex], ObjectCArray[ObjectAArray[0].Index] do
begin
writeln(TestValue);
end;
WriteLn('ok');
end.