Inlined ‘Self’-changing type helpers over values accessed by dereference either do not work or cause internal errors.
While trying to fix #39841 (closed) (by changing something randomly and seeing if it works) I tried to compile tests/webtbs/tw38122.pas
and got an ICE on the line 72:
px^.sub(100); //and this works as well.
Then I remembered I had -OoAUTOINLINE
, but quickly found an offending function whose manual inlining also fails perfectly, and built a simpler example:
{$mode objfpc} {$typedaddress on} {$modeswitch typehelpers}
type
XType = double;
XTypeHelper = type helper for XType
procedure Add(x: XType); inline;
end;
procedure XTypeHelper.Add(x: XType);
begin
self += x;
end;
var
x: XType;
begin
x := 0;
(@x)^.Add(1);
if x <> 1 then begin writeln('x = ', x, ', expected 1'); halt(1); end;
writeln('ok');
end.
Compiling this for x86_64-win64
with floating-point XType
gives Internal error 200109227
.
Compiling this for i386-win32
with floating-point XType
gives Internal error 200306031
.
Compiling this with integral (or even record
, with corresponding modifications) XType
proceeds, but running fails:
x = 0, expected 1
Probably related and can be fixed (one day) together with #39841 (closed), as my #38122 (closed)-reintroducing patch fixes this as well.
Edited by Rika