Description
Bug #179 fix (commit 05010af) resolved a critical frame allocation conflict that was causing struct tm corruption when code was linked across translation units. However, this fix introduced a regression: the register keyword optimization no longer works.
Problem
The fix forces all locals to FRAME allocation to prevent overlaps with temporaries. This prevents register variables from being allocated to Zero Page (ZP), which was a performance optimization.
Before fix: register int x; → allocated to ZP (fast)
After fix: register int x; → allocated to FRAME (correct but slower)
Root Cause
The frame allocation reordering in IRCodeGen.cpp (lines 1015-1043) now allocates all locals to FRAME first, then temporaries. While this prevents corruption, it also prevents register variables from using the register keyword behavior.
Solution Needed
Refine the fix to allow register variables to be allocated to ZP while still protecting non-register locals from frame allocation conflicts. This requires:
- Distinguish between
register and non-register locals in IRCodeGen
- Apply the FRAME-only restriction only to non-register locals
- Allow
register locals to use ZP allocation when available
- Ensure no overlap occurs between any locals and temporaries
Testing
The failing test register int allocated in ZP in src/test-resources/test_register.c validates register keyword optimization.
References
Labels
enhancement, optimization, register-allocation
🤖 Generated with Claude Code
Description
Bug #179 fix (commit 05010af) resolved a critical frame allocation conflict that was causing struct tm corruption when code was linked across translation units. However, this fix introduced a regression: the
registerkeyword optimization no longer works.Problem
The fix forces all locals to FRAME allocation to prevent overlaps with temporaries. This prevents
registervariables from being allocated to Zero Page (ZP), which was a performance optimization.Before fix:
register int x;→ allocated to ZP (fast)After fix:
register int x;→ allocated to FRAME (correct but slower)Root Cause
The frame allocation reordering in IRCodeGen.cpp (lines 1015-1043) now allocates all locals to FRAME first, then temporaries. While this prevents corruption, it also prevents register variables from using the
registerkeyword behavior.Solution Needed
Refine the fix to allow
registervariables to be allocated to ZP while still protecting non-register locals from frame allocation conflicts. This requires:registerand non-register locals in IRCodeGenregisterlocals to use ZP allocation when availableTesting
The failing test
register int allocated in ZPinsrc/test-resources/test_register.cvalidates register keyword optimization.References
make test-registershows 1 failure out of 8 testsLabels
enhancement, optimization, register-allocation
🤖 Generated with Claude Code