Skip to content

Fix UB in dcalc tests: remove fake Pin* pointers from LoadPinIndexMap#346

Open
gonsolo wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
gonsolo:fix/gcc15-fake-pin-ub
Open

Fix UB in dcalc tests: remove fake Pin* pointers from LoadPinIndexMap#346
gonsolo wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
gonsolo:fix/gcc15-fake-pin-ub

Conversation

@gonsolo
Copy link
Copy Markdown

@gonsolo gonsolo commented Apr 13, 2026

LoadPinIndexMap uses PinIdLess as its comparator, which calls network_->id(pin) and dereferences the Pin pointer. Three tests created fake Pin* via reinterpret_cast<const Pin*>(&int_var) and inserted them into LoadPinIndexMap, causing undefined behavior.

With GCC 15.2.0's hardened std::vector::operator[] bounds checking, this UB manifests as an assertion failure:
vector::operator[]: Assertion '__n < this->size()' failed

Fix by using empty LoadPinIndexMap for gateDelay/gateDelays/ inputPortDelay calls (the comparator is never invoked on an empty map) and testing wire delay/load slew accessors via ArcDcalcResult::setLoadCount() directly.

LoadPinIndexMap uses PinIdLess as its comparator, which calls
network_->id(pin) and dereferences the Pin pointer. Three tests
created fake Pin* via reinterpret_cast<const Pin*>(&int_var) and
inserted them into LoadPinIndexMap, causing undefined behavior.

With GCC 15.2.0's hardened std::vector::operator[] bounds checking,
this UB manifests as an assertion failure:
  vector::operator[]: Assertion '__n < this->size()' failed

Fix by using empty LoadPinIndexMap for gateDelay/gateDelays/
inputPortDelay calls (the comparator is never invoked on an empty
map) and testing wire delay/load slew accessors via
ArcDcalcResult::setLoadCount() directly.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 13, 2026

CLA assistant check
All committers have signed the CLA.

@dsengupta0628 dsengupta0628 requested a review from jhkim-pii April 15, 2026 20:51
// Note: LoadPinIndexMap uses PinIdLess which calls network_->id(pin),
// so we cannot use fake Pin* pointers. Test with an empty map
// (load sizing is already covered by ArcDcalcResultTest).
TEST_F(StaDcalcTest, UnitDelayCalcGateDelayWithLoads) {
Copy link
Copy Markdown
Contributor

@jhkim-pii jhkim-pii Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a non-empty load_pin_index_map does not look trivial.
I think removing this TEST_F (and the others below) is better because there is a similar UnitDelayCalcGateDelay test w/ empty load_pin_index_map.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as my package still works, I'm happy:
NixOS/nixpkgs@63a954c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants