Skip to content

fix!(codegen): initialize function outputs and omitted arguments (1.0.x) - #1959

Open
Angus-Bethke-Bachmann wants to merge 1 commit into
release/1.0.xfrom
anbt/PRG-4940-1.0.x
Open

Angus-Bethke-Bachmann wants to merge 1 commit into
release/1.0.xfrom
anbt/PRG-4940-1.0.x

Conversation

@Angus-Bethke-Bachmann

Copy link
Copy Markdown
Contributor

Problem: When a call left out an argument, the compiler passed the contents of a stack slot that nothing had written, so the callee saw whatever the previous call had left there. A VAR_OUTPUT of a function or method also started every call with the caller's current value, so a path that did not assign the output leaked that value back.

Solution: An argument that is left out, or written empty, carries the declared default or zero. Outputs of functions and methods are initialized like local variables at the start of each call: codegen zero-fills them through the caller's address and the init lowering adds the constructor call and initializer assignment. Variable length array outputs keep the caller's bounds. Non-constant output initializers such as ADR(THIS^) are left to the lowered initializer.

Cherry-picked from the master PR for PRG-4940.

Problem: When a call left out an argument, the compiler passed the
contents of a stack slot that nothing had written, so the callee saw
whatever the previous call had left there. A VAR_OUTPUT of a function
or method also started every call with the caller's current value, so a
path that did not assign the output leaked that value back.

Solution: An argument that is left out, or written empty, carries the
declared default or zero. Outputs of functions and methods are
initialized like local variables at the start of each call: codegen
zero-fills them through the caller's address and the init lowering adds
the constructor call and initializer assignment. Variable length array
outputs keep the caller's bounds. Non-constant output initializers such
as ADR(THIS^) are left to the lowered initializer.

Cherry-picked from the master PR for PRG-4940.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Build Artifacts

🐧 Linux

Artifact Link Size
schema Download 0.0 MB
stdlib Download 33.5 MB
deb-x86_64 Download 38.7 MB
plc-x86_64 Download 43.5 MB
plc-aarch64 Download 43.3 MB
deb-aarch64 Download 30.9 MB

From workflow run

🪟 Windows

Artifact Link Size
plc.exe Download 38.4 MB
stdlib.dll Download 0.1 MB
stdlib.lib Download 4.0 MB

From workflow run

@ghaith

ghaith commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

is this really breaking? (fix!)

@Angus-Bethke-Bachmann

Angus-Bethke-Bachmann commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@ghaith

is this really breaking? (fix!)

I wasn't 100% sure so I asked claude to flag it, different results are returned on a recompile of the same code. I think this is technically breaking but the returned results were wrong before... so I dunno. I don't mind removing it (the !). It's one of the reasons I asked for you guys to take a close look at these PRs.

This branch has not been deployed

No deployments
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