SystemVerilog OOP Mastery · All levels
Handle Aliasing Bugs: Exercises
Exercises for Handle Aliasing Bugs.
Practice exercises
Exercise 1
A scoreboard does exp_q.push_back(txn) in write(); later monitor updates txn.status for logging. Why do compares flap, and what fix pattern removes the flakiness?
Solution
diagram
exp_q stores the same handle, so later status updates mutate expected entries. Fix by cloning/deep-copying before push and treating queued objects as immutable snapshots.Exercise 2
You printed top-level handle %p and they differ, yet data still co-mutates. What should you inspect next?
Solution
diagram
Inspect nested handle identities (%p for members like payload, cfg, arrays of objects). Aliasing often lives one level below the top object.