Skip to content

Fix various intrinsic signatures around dynamic and open arrays #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

cirras
Copy link
Collaborator

@cirras cirras commented Dec 5, 2024

This PR fixes several intrinsic signatures to handle array size types properly.
It's a symmetrical change with #312.

Due to the current asymmetry, it's very trivial to get PlatformDependentTruncation false-positives with cases like:

procedure Test(Foo: TArray<Byte>; Bar: TArray<Byte>);
begin
  // Length returns NativeInt, and SetLength incorrectly expects Integer.
  SetLength(Foo, Length(Bar));
end;

@cirras cirras requested a review from fourls December 5, 2024 01:43
Copy link
Collaborator

@fourls fourls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good. Just to confirm my understanding, passing an Int64 to these intrinsics should now cause a PlatformDependentTruncation issue? Assuming the Delphi documentation is correct (...), this is the right behaviour.

@cirras
Copy link
Collaborator Author

cirras commented Dec 5, 2024

Change looks good. Just to confirm my understanding, passing an Int64 to these intrinsics should now cause a PlatformDependentTruncation issue? Assuming the Delphi documentation is correct (...), this is the right behaviour.

No - and it's kind of an irritating problem.
For accuracy reasons, we return Integer for array sizes on 32-bit. We'd need custom handling in the PlatformDependent* rules to consistently detect this on 32-bit toolchains. On 64-bit toolchains, it will work as expected.

In summary - false negatives on 32-bit.

@cirras cirras merged commit 66b6c55 into master Dec 5, 2024
5 checks passed
@cirras cirras deleted the array_intrinsics branch December 5, 2024 03:01
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.

2 participants