dft: ScanStitch::Stitch dereferences std::deque::end() on chains of 3+ cells

Open Beginner friendly
#11,985 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mmporong is already working on this.

Since Oct 26, 2026.

  • #11995 by @mmporong — open
  • #12011 by @shivarammysore — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
testing-qa

Research direction

Start in src/dft/src/stitch/ScanStitch.cpp at ScanStitch::Stitch and trace how the deque is formed and how the first and last cells are connected. The issue gives src/dft/test/scan_architect_no_mix_sky130.tcl as a reproducer; run it with a hardened standard library or ASan to expose the invalid access. Done when chains of three or more cells connect in order without dereferencing past the deque, while preserving the stated connection order.

Written by the indexing model from the issue text.

Description

dft

ScanStitch::Stitch(block, scan_chain, ordinal) in src/dft/src/stitch/ScanStitch.cpp dereferences std::deque::end() when a chain has 3 or more cells, which is undefined behaviour.

The chain's cells are copied into a std::deque, the first and last are popped off, and the middle cells are walked with:

for (auto it = scan_cells.begin(); it != scan_cells.end(); ++it) {
  const std::unique_ptr<ScanCell>& current = *it;
  const std::unique_ptr<ScanCell>& next = *(it + 1);
  next->connectScanIn(current->getScanOut());
}

On the last middle cell, it + 1 == scan_cells.end(), so next is read from past the end.

Why the regressions pass anyway: with libc++, the slot just past the end still holds the element that pop_back() removed, which is the last cell of the chain. So the read returns the last cell, and the last cell's scan-in ends up connected to the last middle cell's scan-out. Nothing else connects the last cell when there are 3+ cells; the explicit "connect the last cell" branch only runs when the middle is empty. The correct result therefore depends on the stale slot.

Reproducer: any execute_dft_plan that builds a chain of 3 or more cells, e.g. src/dft/test/scan_architect_no_mix_sky130.tcl. A hardened standard library (libc++ hardened mode, _GLIBCXX_ASSERTIONS) or ASan should flag the dereference. A different standard library, or a deque layout where that slot is no longer the popped element, could connect the wrong cell or crash.

Suggested fix: connect the cells pairwise in chain order instead of popping both ends, e.g. after connecting the first cell's scan-in, for i in 1..n: cells[i]->connectScanIn(cells[i-1]->getScanOut()), then the last cell's scan-out as today. The connections, and the order they are made in, stay what the current binary produces.

Seen at 27288f5c90 and still present on master (3c92de5213).

Dominant language
Verilog
Stars
3.2k
Forks
1.1k
Avg merge
2d 9h
Merged PRs (30d)
270

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from The-OpenROAD-Project/OpenROAD

All issues in The-OpenROAD-Project/OpenROAD

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.