fix(validation): reject FB-level VAR_TEMP referenced from a METHOD#1746
Open
ghaith wants to merge 1 commit into
Open
fix(validation): reject FB-level VAR_TEMP referenced from a METHOD#1746ghaith wants to merge 1 commit into
ghaith wants to merge 1 commit into
Conversation
A method has its own stack frame, so a VAR_TEMP declared on the enclosing FUNCTION_BLOCK is not accessible. Previously the resolver let the reference through and codegen emitted a fresh, uninitialized stack slot — the load was undef and any boolean expression depending on it folded to nonsense at optimization levels above none. Now the resolver filters VAR_TEMP when crossing from a METHOD into its enclosing POU, and the validator emits a focused E137 diagnostic pointing at the offending read site and the TEMP declaration. ACTIONs continue to see the TEMP since they share the FB's frame. Refs #1745 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Build Artifacts🐧 Linux
From workflow run 🪟 Windows
From workflow run |
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.
Fixes #1745.
Summary
VAR_TEMPdeclared on aFUNCTION_BLOCKwas silently miscompiledwhen read from one of that FB's
METHODs: the method allocated itsown uninitialized stack slot for the temp, the load was
undef,and any boolean expression depending on it folded to nonsense at
optimization levels above
none.aligns behavior: the resolver no longer leaks a method's enclosing
VAR_TEMPinto the method body, and the validator emits a focuseddiagnostic (E137) instead of the generic "unresolved reference".
ACTIONs continue to see the FB'sVAR_TEMPbecause they share theFB body's stack frame.
Changes
src/index.rs—find_local_member_recursivefiltersis_temp()when crossing from a METHOD into its enclosing POU.
src/validation/statement.rs—fb_temp_referenced_from_methodhelper emits E137 with a secondary location at the TEMP declaration,
shadowing the generic unresolved-reference diagnostic for this case.
compiler/plc_diagnostics/src/diagnostics/{diagnostics_registry.rs,error_codes/E137.md}— register and document E137 with both fix options (promote to
instance member, or move the TEMP into the method).
Test plan
cargo test --workspace— all green, no regressions.cargo fmt --allandcargo clippy --workspace -- -Dwarnings— clean.
plc --iron the reproducer from FB-level VAR_TEMP referenced from a METHOD lowers to an uninitialized method-local #1745 now aborts withE137 and emits no IR (previously it produced an
undefload).