x64: pass by-value dynamic arrays as pointer value on FPC 3+#315
Open
TetzkatLipHoka wants to merge 1 commit into
Open
x64: pass by-value dynamic arrays as pointer value on FPC 3+#315TetzkatLipHoka wants to merge 1 commit into
TetzkatLipHoka wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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