Skip to content

x64: pass by-value dynamic arrays as pointer value on FPC 3+#315

Open
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:fix/fpc-dynarray-byval
Open

x64: pass by-value dynamic arrays as pointer value on FPC 3+#315
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:fix/fpc-dynarray-byval

Conversation

@TetzkatLipHoka

Copy link
Copy Markdown

The classic x64 path passed by-value dynamic array parameters as the
ADDRESS of the variable slot on FPC ({$IFDEF FPC} FVar.Dta instead of
FVar.Dta^), a leftover from an FPC 2.4-era fix. On FPC 3.x x86_64-linux the
callee then reads garbage instead of the array (Length() returns random
values, element access crashes with an access violation).

A dynamic array IS a pointer on every current target: pass its value, like
the Delphi branch always did. The 2.4 behavior is kept behind
{$IF FPC_VERSION < 3}.

Repro (fails on master with the FPC-compilation fixes applied, passes with
this change; fpc 3.2.2 x86_64-linux):
host: function DynTake(const A: TArr): Integer; // TArr = array of string
script: SetLength(a, 2); a[0] := 'x'; a[1] := 'y'; n := DynTake(a);
Delphi Win64 classic path unchanged and re-verified.

Related: #198 (the FPC access violation with dynamic arrays crossing the import boundary).

🤖 Generated with Claude Code

The classic x64 path passed by-value dynamic array parameters as the
ADDRESS of the variable slot on FPC ({$IFDEF FPC} FVar.Dta instead of
FVar.Dta^), a leftover from an FPC 2.4-era fix. On FPC 3.x x86_64-linux the
callee then reads garbage instead of the array (Length() returns random
values, element access crashes with an access violation).

A dynamic array IS a pointer on every current target: pass its value, like
the Delphi branch always did. The 2.4 behavior is kept behind
{$IF FPC_VERSION < 3}.

Repro (fails on master with the FPC-compilation fixes applied, passes with
this change; fpc 3.2.2 x86_64-linux):
  host:   function DynTake(const A: TArr): Integer;  // TArr = array of string
  script: SetLength(a, 2); a[0] := 'x'; a[1] := 'y'; n := DynTake(a);
Delphi Win64 classic path unchanged and re-verified.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant