Repository navigation
Conversation
- The extrapop solver equated every input of a stack-pointer merge, so a path lowering SP by a runtime amount took the other path's constant and was rewritten away. - Mark SP values moved by a non-constant amount, and merges they reach, as dynamic: no equation touches them and they are never rewritten. - Regression: Open Watcom DOS alloca behind stackavail() at -od and -ox.
- Dynamic marks follow COPY, CAST, INDIRECT, INT_SUB and PTRADD/PTRSUB value inputs, not only merges. - Only equations joining a dynamic value to a fixed one are dropped; relations among dynamic values stay, unanchored. - PTRADD's element size is not an amount; INT_SUB(sp, c) gets the equation add sp,-c, so a constant reservation on one arm is solved instead of equated.
- A non-constant adjustment is often a constant not yet propagated (add sp,si with si == 2 after a push): a trial upstream solve implies a nonzero move there, so it stays solved as before. - Only an adjustment whose solved move is zero (the merge equated it away) or that stays unsolved is treated as runtime. FreeDOS sweep: ARJ/GZIP return to main's output; FORMAT and JWASMR keep the Watcom alloca amount.
- mov ax,8; sub sp,ax is a fixed reservation: literal_value sees through the copy, so it is not marked runtime.
- is_const/const_off read literal_value, so mov ax,8; sub sp,ax is solved as an 8-byte adjustment instead of being equated through a merge. - Document that confirm_dynamic is evidence, not proof: a runtime arm merged with a nonzero constant keeps upstream's answer. - The regression test now requires the reservation arm's pointer to use the (n + 1) & ~1 amount.
thotypous
force-pushed
the
fix/stackptr-dynamic-sp-merge
branch
from
November 15, 2026 17:51
a2fcf2c to
1108ad5
Compare
This branch has not been deployed
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.
Problem
Open Watcom's DOS
allocareserves stack space only on the branch wherestackavail()says there is room, and returns NULL on the other branch:The x86-16 default model has unknown extrapop, so
ActionStackPtrFlow::analyzeExtraPop(theStackSolver) runs. Its MULTIEQUAL rule equates every input of a stack-pointer merge. That handssp - axthe other path's constant, and the solver then rewrites theINT_SUB(sp, ax)producer asINT_ADD(sp_in, -12). The runtime reservation disappears, and the allocated pointer prints as a fixed frame local. Before:Fix
p6_variables/coreaction_stackptr.rs:kuna_bejoin::literal_value) is marked dynamic. A PTRADD element size does not count as an amount.add sp,siwithsi == 2on that path, which pops a pushed argument (FreeDOS ARJ, GZIP). A seed stays dynamic only if the trial solve gives it a zero move (the merge erased it) or leaves it unsolved.INT_SUB(sp, c)and adjustments whose amount evaluates to a constant (mov ax,8; sub sp,ax) now get their exact equation instead of being left to merge equalities.After:
Tests
New CLI test
dynamic_sp_mergeon two Open Watcom 2 DOS executables built fromwatcom_dos_alloca.c(wcl -bt=dos -ms -s -ecc,-odand-ox). It requires the reservation arm's pointer to use the(n + 1) & ~1amount, and it fails on main. The 13 existingcoreaction_stackptrunit tests pass.Validation
allocasites (FORMAT, JWASMR, FDTUI): the reservation now survives.Known limitation
The trial solve is evidence, not proof. Suppose a runtime reservation sits on one arm of a merge, and the sibling arm moves SP by a nonzero constant (for example
alloca(c ? n : 8)). The trial then reads the sibling's constant and keeps upstream's rewrite, so the output there is the same as main's.