Repository navigation
[AUTOMATED] Size an MSVC __cdecl import's by-value class at the call site (msvcbyval) - #1072
Merged
Merged
Conversation
mahaloz
added a commit
that referenced
this pull request
Oct 14, 2026
…eanup alone (#1072 review) The cleanup `add esp,k` over-counts when padding, a local, or an earlier call's deferred pop is folded into it, and a `pop` run was read as k=4. The class size is now taken from the stack and cross-checked against the cleanup: - Only a single `add esp,k` is a cleanup; a pop (run) is declined (a `pop ebp` epilogue cannot be told apart locally). - A class with a copy constructor or a by-value return is sized by the one reservation the builder captured (`push ecx` = 4, `sub esp,n` = n), accepted only when known params + reservation == k. A trivially copyable aggregate is sized k - known only when no byte of the argument area is an unwritten gap. - An 8-byte class after an odd number of 4-byte slots is declined (the cdecl model misaligns it); documented. New fixture msvcbyval_ce_i386.exe (the review's ce4.asm) and stage assertions cover pop-run, class-last padding, dead push-ecx locals, and the misaligned 8-byte class -- all declined -- plus the sized 6-byte-padded class. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
mahaloz
force-pushed
the
fix/fix990-byval
branch
from
October 14, 2026 01:48
34bd3fd to
16aad51
Compare
mahaloz
added a commit
that referenced
this pull request
Oct 14, 2026
…s, and a split cleanup (#1072 delta review) - Restore the guard the round-2 rewrite dropped: once the slot is placed, an address formed into a live byte of the argument area outside it is a local the same `add esp` releases, and the sizing is declined. A frameless `push ecx` local passed as `Fill(&r)` before `Take(*p, r)` printed `Take(v1._0_12_,a0)`; it now prints `Take(*a1,a1[1],v1)` as with the option off. - Decline a cleanup followed by another bare `add esp` before the next call, branch or return (`add esp,8; add esp,4`). - Document the two shapes the stack cannot tell apart: one reservation larger than the class, and a dead pushed local above a trivially copyable aggregate. Fixture msvcbyval_ce_i386 gains podfold, split and a plain-struct control, with stage assertions #19-#21. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
…site (msvcbyval) An MSVC name does not state the size of a class passed by value, so msvcsig left every parameter after it open, and the copy constructor that builds the class in its outgoing slot made the call-site recovery refuse the rest: `MakeStack(a1)` for `Arr MakeStack(Arr, Arr &, Arr &)`. The new `msvcbyval` option (default on) reads the class's slot off the caller's `add esp,k` right after the call, once a walk back over the block's raw p-code shows that cleanup is this call's alone (no deferred pop, no folded frame release), and gives the call the full declaration. A constructor whose `this` is the slot creates the slot's value in heritage, and the slot stays a mapped local, so Build prints `Arr::Arr((Arr *)&v1,a1); MakeStack(a0,v1,a1,a2);` with three parameters. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
… keep any address-taken slot mapped `MakeStack(GetArr(), x, y)` has GetArr return straight into the by-value slot through its hidden pointer; with only constructors recognised, the argument printed as the `ecx` value pushed to reserve the slot. The walk now traces the object pointer a builder receives (a constructor's `ecx`, or the first stack argument of an MSVC declaration returning a class by value) back to the stack pointer, and any by-value slot whose address the caller forms stays a mapped local. The constructor call must be __thiscall. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
[AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
…eanup alone (#1072 review) The cleanup `add esp,k` over-counts when padding, a local, or an earlier call's deferred pop is folded into it, and a `pop` run was read as k=4. The class size is now taken from the stack and cross-checked against the cleanup: - Only a single `add esp,k` is a cleanup; a pop (run) is declined (a `pop ebp` epilogue cannot be told apart locally). - A class with a copy constructor or a by-value return is sized by the one reservation the builder captured (`push ecx` = 4, `sub esp,n` = n), accepted only when known params + reservation == k. A trivially copyable aggregate is sized k - known only when no byte of the argument area is an unwritten gap. - An 8-byte class after an odd number of 4-byte slots is declined (the cdecl model misaligns it); documented. New fixture msvcbyval_ce_i386.exe (the review's ce4.asm) and stage assertions cover pop-run, class-last padding, dead push-ecx locals, and the misaligned 8-byte class -- all declined -- plus the sized 6-byte-padded class. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
…o origin/main Rebase onto b2ac4b5: re-derive the hard-coded settable counts (295), the live-value count (130), recapture the catalog fixture, regenerate options.md, and re-record the stages baseline (only the new MSVCBYVAL keys and the catalog row-count rename change versus main). [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
…s, and a split cleanup (#1072 delta review) - Restore the guard the round-2 rewrite dropped: once the slot is placed, an address formed into a live byte of the argument area outside it is a local the same `add esp` releases, and the sizing is declined. A frameless `push ecx` local passed as `Fill(&r)` before `Take(*p, r)` printed `Take(v1._0_12_,a0)`; it now prints `Take(*a1,a1[1],v1)` as with the option off. - Decline a cleanup followed by another bare `add esp` before the next call, branch or return (`add esp,8; add esp,4`). - Document the two shapes the stack cannot tell apart: one reservation larger than the class, and a dead pushed local above a trivially copyable aggregate. Fixture msvcbyval_ce_i386 gains podfold, split and a plain-struct control, with stage assertions #19-#21. [AUTOMATED] change made by Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz
mahaloz
force-pushed
the
fix/fix990-byval
branch
from
October 14, 2026 02:53
921d26e to
2d0b63d
Compare
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.
A call to an MSVC
__cdeclimport that takes a class by value keeps only the arguments before that class. Withprotos.exefrom #990 (in the tree asdecompiler/crates/kuna-analysis/tests/fixtures/msvcsig_protos_i386.exe),Arr Build(Arr &x, Arr &y) { return MakeStack(x, x, y); }calls?MakeStack@@YA?AVArr@@V1@AAV1@1@Z:After:
Fix
--option msvcbyval on|off(default on). The name gives no size for a class passed by value, somsvcsigleaves the rest of the list open. The caller pops a__cdeclcallee's arguments, so anadd esp,kright after the call gives the argument bytes: the class takeskless the other parameters' slots, and the call gets the full declaration.thisof an MSVC constructor or the hidden return pointer of an MSVC function returning a class by value, that call creates the slot's value, so thepush ecxthat only reserves the slot no longer makesecxa parameter.MakeStack(GetArr(), x, y)printsGetArr((Arr *)&v1); MakeStack(a0,v1,a1,a2);.Tests
tests/stages/kuna-msvcbyval.xmldecompiles the #990 fixture and two nasm fixtures (msvcbyval_i386.asmsizes an 8-byte class, aGetArr()argument, and declines a deferred pop and a folded local;msvcbyval_ce_i386.asmdeclines apop;popor split cleanup, padding above a class-last argument, dead reserving pushes, an addressed local the cleanup releases, and an 8-byte class after a 4-byte slot). With the option off the calls keep only the parameters before the class; on, the full calls, with every unsound case declined in both passes. No datatest assertion moves (675/675). The 175 32-bit MSVC PE images used formsvcsigare byte-identical (none imports a__cdeclfunction taking a class by value); the sizing runs only on that path, so it is inert on the ELF speed corpus.Known limits: one
sub esplarger than the class, or a never-read pushed local above a plain struct, still reads as a wider class; the stack holds nothing that tells them apart.Still open: a class passed by value to a callee-pops convention (
Arr::operator=(Arr),__thiscall/__stdcall) is still refused bymsvcsig, since its stack adjustment depends on the size the name does not give.Fixes #990
🤖 Generated with Claude Code
https://claude.ai/code/session_015sdZpNU5odw5dVyaxeSvvz