-O3 memory corruption with record assignments to function result
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Compile the program in "Steps To Reproduce".
With -O2 it works as expected.
Winth -O3 the MyObj variable gets corrupted in the Test method call (the second Writeln writes a different pointer value).
Steps to reproduce:
program Project1;
{$mode delphi}
type
TSinglePoint = record
X, Y: Single;
public
constructor Create(const aX, aY: Single);
end;
{ TSinglePoint }
constructor TSinglePoint.Create(const aX, aY: Single);
begin
X := aX;
Y := aY;
end;
type
TMyObj = class
public
function Test: TSinglePoint;
end;
{ TMyObj }
function TMyObj.Test: TSinglePoint;
begin
Result := TSinglePoint.Create(0, 0);
end;
var
MyObj: TMyObj;
begin
MyObj := TMyObj.Create;
Writeln(NativeUInt(MyObj));
MyObj.Test;
Writeln(NativeUInt(MyObj));
Readln;
end.
Mantis conversion info:
- Mantis ID: 36212
- OS: Windows 10
- Build: r43309
- Platform: win 32bit
- Version: 3.3.1
- Fixed in version: 3.3.1