feat(decompiler): Rec 31 Stage 5 — op.cc + varnode.cc RAII migration#96
Merged
Merged
Conversation
PCode-core paired migration. Both create() overloads in `PcodeOpBank` and both `VarnodeBank::create` / `::createDef` follow the same create-then-transfer-into-bank pattern: T *thing = new T(...); bank.insert(thing); // ownership transfer ... use thing as alias ... return thing; Migrate to: auto owned = make_unique<T>(...); T *thing = owned.get(); bank.insert(thing); owned.release(); // ownership transferred ... use thing as alias ... return thing; Exception-safety improvement in `VarnodeBank::create`: previously the function did vn->lociter = loc_tree.insert(vn).first; vn->defiter = def_tree.insert(vn).first; with no protection — if def_tree.insert threw, loc_tree held a dangling raw pointer to a leaked Varnode (because vn was leaked on stack unwind). The new code does `owned.release()` immediately after `loc_tree.insert` so the cleanup-on-unwind doesn't fire over a tree-held pointer; if def_tree.insert subsequently throws, the loc_tree still holds a valid (newly tree-owned) pointer — same state as before, but with the rare-throws no longer producing heap-corruption. `VarnodeBank::createDef` and `PcodeOpBank::create(...)` overloads follow the same pattern. `xref(owned.release())` is fine: xref either stores in the trees or `delete vn;` on duplicate detection (line 1326), so ownership transfers correctly either way. `op.cc` + `varnode.cc` join `cppRaiiAudit`'s `PROTECTED_FILES` (count: 58 → 60). `op.hh` + `varnode.hh` were already in from #94. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 27, 2026
CryptoJones
added a commit
that referenced
this pull request
May 28, 2026
Six raw-`new` sites migrated in the sleigh OpTpl / VarnodeTpl /
HandleTpl decode paths:
- Two member-assignment sites (OpTpl::decode line 719
`output = new VarnodeTpl()`, ConstructTpl::decode line 913
`result = new HandleTpl()`) use `make_unique<T>().release()` —
the member types stay raw-pointer because the destructors
manually delete (preserved bit-for-bit).
- Two `vec.push_back(new T())` loop sites (line 723 VarnodeTpl,
line 917 OpTpl) use the create-then-transfer-with-named-raw-ptr
pattern from varnode.cc PR #96: `auto owned = make_unique<T>();
T *p = owned.get(); vec.push_back(owned.release());
p->decode(decoder);`.
- One create-then-addInput pair in fillinBuild (lines 782–783)
uses `.release()`-immediate on both the OpTpl(BUILD) and the
synthesized VarnodeTpl constant.
`make_unique` reaches semantics.cc via semantics.hh → slaformat.hh
→ marshal.hh's `using std::make_unique;`. No header changes needed.
semantics.cc joins PROTECTED_FILES. Local `make decomp_test_dbg`
green in 11s.
Protected-set count: 202 → 203.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
PCode-core paired migration. Both
PcodeOpBank::createoverloads (op.cc:974, 991) and bothVarnodeBank::create/::createDef(varnode.cc:1278, 1439) follow the same create-then-transfer-into-bank pattern. Migrate tomake_unique+.release()at the point of ownership transfer.Exception-safety improvement in
VarnodeBank::createThe function previously did:
with no protection between the two inserts. If
def_tree.insertthrew,loc_treeheld a dangling raw pointer to a leaked Varnode (vn went out of scope without delete). The new code doesowned.release()immediately after the first insert — ifdef_tree.insertthen throws,loc_treestill holds a valid (newly tree-owned) pointer; same observable state as before, but with the rare-throws no longer producing heap-corruption.xref()ownership transferVarnodeBank::createDefpasses vn toxref()viaowned.release().xref()either stores vn in the trees (line 1334) ordelete vn;on duplicate detection (line 1326), so ownership transfers correctly either way.Audit gate
op.cc+varnode.ccjoincppRaiiAudit'sPROTECTED_FILES(count: 58 → 60).op.hh+varnode.hhwere already in from PR #94.Test plan
gradle cppRaiiAuditpasses;op.cc+varnode.ccnow appear in the protected set.Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/