Skip to content

parser: allow readonly storage and results for untyped constref - #49

Open
Moonbot-Tech wants to merge 2 commits into
unleashedpascal:mainfrom
Moonbot-Tech:fix-41766
Open

parser: allow readonly storage and results for untyped constref#49
Moonbot-Tech wants to merge 2 commits into
unleashedpascal:mainfrom
Moonbot-Tech:fix-41766

Conversation

@Moonbot-Tech

@Moonbot-Tech Moonbot-Tech commented Sep 6, 2026

Copy link
Copy Markdown

Problem. FPC #41766: forwarding an element of readonly storage to an untyped constref parameter was rejected as an assignment to a const variable.

Fix. Permit readonly storage in the frontend and materialize accepted non-reference actuals, such as function results, for the call. Existing references retain their addresses. The earlier title overstated the change: valid_const is not permission to pass arbitrary scalar literals or arithmetic expressions.

Tests. The original buffer test is now endian-independent. tw41766a varies storage origin (local, field, dynamic array, typed constant, integer/FP/managed function result), direct/forwarded/typed consumers, evaluation counts and two simultaneous temporaries. tw41766b/c keep scalar-literal and readonly-to-var/out rejection controls.

Validation. The new runtime matrix passes on this Unleashed branch at -O3 on Win64. The corresponding FPC branch passes -O-/-O2/-O3 on Win64 and -O3 on i386-win32. Removing only constref materialization from the FPC patch makes the new matrix fail with IE 200304235, independently covering that part of the fix.

Upstream MR: https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/1554. This PR waits for the FPC decision.

…stream#41766)

A formal constref parameter, like an ordinary const, may bind to a
constant expression, but the assignment check rejected it with "Can't
assign values to const variable", and codegen materialized a
non-reference actual only for const formals.

Add valid_const to the check and materialize the actual for constref
formals the same way as for const ones: both promise the callee an
address.

FPC issue: https://gitlab.com/freepascal.org/fpc/source/-/issues/41766

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fibodevy fibodevy added the waiting-upstream Stock FPC fix, waits for the upstream MR to be merged or rejected label Sep 6, 2026
@Moonbot-Tech

Copy link
Copy Markdown
Author

Make the original forwarding oracle endian-independent. Cover storage identity, register and managed results, forwarding and simultaneous temporaries; keep readonly-to-writable and scalar-literal rejection controls. Clarify valid_const scope without changing compiler behavior.
@Moonbot-Tech Moonbot-Tech changed the title parser: accept constant expressions for constref parameters (fixes upstream#41766) parser: allow readonly storage and results for untyped constref Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-upstream Stock FPC fix, waits for the upstream MR to be merged or rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants