Repository navigation
bugc: fix -O2/-O3 codegen for call arguments and continuations - #388
Merged
Merged
Conversation
Contributor
|
gnidan
added a commit
that referenced
this pull request
Oct 15, 2026
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.
examples/advanced/token-registry.bugcompiled at -O0 and -O1 but failed at -O2 ("Cannot load value t107 - not in stack or memory") and, after that was fixed, at -O3 ("Jump target call_cont_14 not found"). Two optimizer steps forgot aboutcallterminators:msg.senderpassed straight to a call was removed, and the call kept using the removed temp. The step now rewrites call arguments, too.returnblock and redirected jumps and branches to the kept one, but left a call's continuation pointing at the deleted block. Redirecting the continuation would not be right either: evmgen enters a continuation only from its call, with the callee's return value on the stack. Continuation blocks now stay out of return merging, both as the block removed and as the block kept. This is also why the blog's arcade contract has failed at -O3 since bugc: string and bytes calldata parameters #383 (call play() -> call_cont_6, followed by a barereturn;).Each fix has a small regression test next to the step's other tests. The CSE test runs a program at -O2/-O3. The return-merging test runs at -O3 with the continuation before and after the other
return;, and with a callee that returns a value or nothing. It checks that every call's continuation still exists and that no jump or branch enters it, and it runs both paths. All four cases fail on main. Of all the examples, only token-registry's bytecode changes (it now compiles at -O2 and -O3; the activation-pairing snapshot is updated for that). Its storage after a sequence of 18 calls is the same at every level.The example keeps
@wip: its dispatch never matches a selector, becausebytes == bytescompares the two memory pointers, not the contents (let s: bytes = msg.data[0:4]vs.keccak256("pause()")[0:4]giveseq %t13, %t30on the allocations). That is a separate irgen issue.Closes #389