Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
      • Shallow Copy in Nested Payload
      • Queue of Handle Cells Still Aliases
      • Analysis Port Lifetime Reuse
      • Null Handle During Partial Deep Copy
      • Handle Equality vs Content Equality
      • Clone Without Overridden do_copy
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Handle and Copy Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Handle and Copy Puzzles
  5. Clone Without Overridden do_copy

VLSI DV Interview Puzzles · All levels

Clone Without Overridden do_copy

A class has nested handle members but only uses field macros for scalars. Why can `clone()` still leak aliasing?

On this page

    Puzzle

    Difficulty: Hard · Puzzle 6 of 6 · Topic: Handle and Copy Puzzles

    A class has nested handle members but only uses field macros for scalars. Why can `clone()` still leak aliasing?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    class hdr extends uvm_object;
      `uvm_object_utils(hdr)
      int opcode;
      function new(string name="hdr"); super.new(name); endfunction
    endclass
    
    class tr extends uvm_sequence_item;
      `uvm_object_utils_begin(tr)
        `uvm_field_int(addr, UVM_DEFAULT)
      `uvm_object_utils_end
      int addr;
      hdr h;
      function new(string name="tr");
        super.new(name);
        h = hdr::type_id::create("h");
      endfunction
      // no do_copy override
    endclass

    Hint

    Which members are actually registered to automation macros?

    Step-by-step solution

    Diagram
    1) `clone()` relies on `copy()` and field automation unless overridden.
    2) Only `addr` is registered; nested handle `h` is not covered, so automation does not deep-copy it.
    3) Depending on implementation defaults, `h` may remain shared or stale, causing aliasing bugs.
    4) Register `h` with `uvm_field_object` or write explicit `do_copy/do_compare` for deterministic ownership.

    Answer

    Answer: Because nested handle `h` is not part of copy automation and no custom `do_copy` exists, clone semantics are incomplete and can leave shared/stale nested state.

    Why candidates get it wrong

    Many candidates trust `clone()` blindly without auditing which fields are actually copied.

    Interviewer follow-up

    Would you prefer field macros or hand-written copy for high-performance scoreboards, and why?

    Related topics

    • Back to Handle and Copy Puzzles

    • OOP & Testbench Puzzles section

    Previous

    35 / 210

    Next: Virtual Method Puzzles

    Up next

    Up nextVirtual Method Puzzles

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Shallow Copy in Nested Payload
    • Queue of Handle Cells Still Aliases
    • Analysis Port Lifetime Reuse