Small records are passed incompatible to Delphi
Original Reporter info from Mantis: Jasper
-
Reporter name: Jasper Neumann
Original Reporter info from Mantis: Jasper
- Reporter name: Jasper Neumann
Description:
According to the Delphi-6 manual (Parameter passing):
"Sets, records, and static arrays of 1, 2, or 4 bytes are passed as 8-bit, 16-bit, and 32-bit values. ..."
In this case FPC pushes the values instead of using registers.
This incompatability becomes a problem when porting assembly routines from Delphi to FPC (and I have a many of them).
Have I missed a compiler switch?
Steps to reproduce:
program test;
type
tr_rgba=packed record
r,g,b,a: byte;
end;
function f(const a,b:tr_rgba):tr_rgba; register;
begin
result.r:=a.r+b.r;
end;
var
a,b,c: tr_rgba;
begin
a.r:=17;
b.r:=19;
c:=f(a,b);
writeln(c.r);
end.
The line with the call is translated by FPC as this:
pushl 0x40b000 // a
pushl 0x40b004 // b
lea 0xfffffffc(%ebp),%eax
call 0x401410 // F
mov 0xfffffffc(%ebp),%eax // c
...and Delphi produces this:
mov edx,[b]
mov eax,[a]
call f
mov [c],eax
Mantis conversion info:
- Mantis ID: 16697
- OS: win32
- OS Build: xp
- Platform: win32
- Version: 2.4.0