From 850a6f56d3703c39ed9057e4ca4f914f4996f1ed Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 25 Feb 2025 23:22:06 +0100 Subject: [PATCH] [consider merging] avoid a crash during certain queries This query used to crash: "instances of cell .*.* where inst.trans.rot == 2" on a layout with 1 hierarchy level and some cells with rot 180 degree --- src/db/db/dbLayoutQuery.cc | 14 +++++++++----- src/db/unit_tests/dbLayoutQueryTests.cc | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/db/db/dbLayoutQuery.cc b/src/db/db/dbLayoutQuery.cc index d2753b617..c5989b5bb 100644 --- a/src/db/db/dbLayoutQuery.cc +++ b/src/db/db/dbLayoutQuery.cc @@ -1006,15 +1006,19 @@ public: db::Instance inst; if (m_reading) { - inst = mp_parent->sorted_inst_ptr (std::distance (mp_parent->begin_sorted_insts (), m_inst)); + if (mp_parent) { + inst = mp_parent->sorted_inst_ptr (std::distance (mp_parent->begin_sorted_insts (), m_inst)); + } } else { inst = m_i; } - if (m_instance_mode == ArrayInstances) { - v.push (tl::Variant (db::InstElement (inst))); - } else { - v.push (tl::Variant (db::InstElement (inst, m_array_iter))); + if (! inst.is_null ()) { + if (m_instance_mode == ArrayInstances) { + v.push (tl::Variant (db::InstElement (inst))); + } else { + v.push (tl::Variant (db::InstElement (inst, m_array_iter))); + } } return true; diff --git a/src/db/unit_tests/dbLayoutQueryTests.cc b/src/db/unit_tests/dbLayoutQueryTests.cc index e93171e89..77f091cd2 100644 --- a/src/db/unit_tests/dbLayoutQueryTests.cc +++ b/src/db/unit_tests/dbLayoutQueryTests.cc @@ -1578,3 +1578,20 @@ TEST(64) EXPECT_EQ (s, "(0.01,-0.02),(-0.01,0.02),(-0.01,0.02),(-0.01,0.02),(0.01,-0.02),(-0.01,0.02)"); } } + +TEST(65) +{ + db::Layout g; + init_layout (g); + + { + db::LayoutQuery q ("instances of cell .*.* where inst.trans.rot == 0"); + db::LayoutQueryIterator iq (q, &g); + std::string s = q2s_var (iq, "data"); + EXPECT_EQ (s, "nil,nil"); + s = q2s_var (iq, "cell_name"); + EXPECT_EQ (s, "c1,c5x"); + s = q2s_var (iq, "inst_elements"); + EXPECT_EQ (s, "(cell_index=0 r0 *1 10,-20),(cell_index=4 r0 *1 10,-20)"); + } +}