macOS / aarch64: Procedure's parameter gets overwritten with zero
Summary
As previosuly mentioned in #41180 (closed), with FPC trunk [macOS / aarch64], in some cases procedure's parameter gets overwritten with zeros, when certain value type params are passed together.
Observations:
- Floating point params are affected (
Int64
param keeps its value,Double
/Single
/Extended
don't). - The size of the value parameter matters, <64 bytes works ok, 64+ breaks.
-
cdecl
calling convention is unaffected.
System Information
- Operating system: macOS Sequoia 15.3.1
- Processor architecture: AARCH64 (Apple M2)
- Compiler version: Free Pascal Compiler version 3.3.1-17624-g1f6ac0609e [2025/03/09] for aarch64
- Device: MacBook Air
Steps to reproduce
program FFloats3;
type
TArr63 = array[1..63] of Byte;
TArr64 = array[1..64] of Byte;
procedure Test63(Value: Double; Param: TArr63);
begin
{ Output: '63, 3.14' }
WriteLn(SizeOf(Param), ', ', Value:5:2);
end;
procedure Test64_1(Value: Double; Param: TArr64);
begin
{ Output: '64, 0.00' }
WriteLn(SizeOf(Param), ', ', Value:5:2);
end;
procedure Test64_2(Value: Double; Param: TArr64); cdecl;
begin
{ Output: '64, 3.14' }
WriteLn(SizeOf(Param), ', ', Value:5:2);
end;
var
Param63: TArr63;
Param64: TArr64;
begin
Test63(3.1416, Param63);
Test64_1(3.1416, Param64);
Test64_2(3.1416, Param64);
end.
What is the current bug behavior?
3.14
0.00
3.14
What is the expected (correct) behavior?
3.14
3.14
3.14
Possible fixes
Likely has something to do with how the value params are copied to procedure's stack before invocation. https://gitlab.com/freepascal.org/fpc/source/-/blob/2ff7f45a362c7fd592206c17ba5a789c5353cb22/rtl/inc/cgeneric.inc#L31