Skip to content

Fix ASM frame crash when range operator RHS is a constant sub#297

Merged
fglock merged 1 commit intomasterfrom
fix/range-operator-asm-crash
Mar 10, 2026
Merged

Fix ASM frame crash when range operator RHS is a constant sub#297
fglock merged 1 commit intomasterfrom
fix/range-operator-asm-crash

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Mar 10, 2026

Summary

Fixes ASM frame computation crash when using array slices with constants as range endpoints.

Reproducer:

use constant END => 2;
sub test { my @a = (1,2,3,4); return @a[0..END]; }

Root cause: The range operator (..) was not spilling its left operand before evaluating the right side. When the RHS was a constant sub call, the non-local control flow handling could leave the JVM operand stack in an inconsistent state.

Fix: Apply the same spill pattern used by other binary operators (substr, concat, push, etc.).

Test plan

  • Unit tests pass (162/162)
  • ExifTool Writer.t passes without ASM errors
  • Time::Piece module loads without crashes

Generated with Devin

The range operator (..) was not spilling its left operand before
evaluating the right side. When the RHS was a constant sub call
(e.g., @A[0..CONST]), the non-local control flow handling could
leave the JVM operand stack in an inconsistent state, causing
"Incompatible stack heights" errors during ASM frame computation.

Fix: Apply the same spill pattern used by other binary operators
(substr, concat, push, etc.) - store LHS in a local variable before
evaluating RHS, then restore it.

Reproducer:
  use constant END => 2;
  sub test { my @A = (1,2,3,4); return @A[0..END]; }

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 94c19f8 into master Mar 10, 2026
2 checks passed
@fglock fglock deleted the fix/range-operator-asm-crash branch March 10, 2026 14:53
fglock added a commit that referenced this pull request Mar 10, 2026
Follow-up to PR #297: Apply the same spill pattern to additional
operators that were missing it:

- atan2 function - e.g., atan2(0, CONST)
- exists/delete with compound dereference - e.g., exists $h{key}[CONST]

These operators were not spilling their left operand before evaluating
the right side, causing "Incompatible stack heights" errors when the
RHS was a constant sub call.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
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.

1 participant