Skip to content

Commit 3cb321b

Browse files
Merge pull request #3287 from verilog-to-routing/fredt_check_model_existence
Add check that model exists during read_blif to avoid seg fault
2 parents 7b55b70 + a79ef80 commit 3cb321b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

vpr/src/base/read_blif.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,14 @@ struct BlifAllocCallback : public blifparse::Callback {
244244
VTR_ASSERT(ports.size() == nets.size());
245245

246246
LogicalModelId blk_model_id = models_.get_model_by_name(subckt_model);
247+
if(!blk_model_id.is_valid()) {
248+
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_,
249+
"Subckt instantiates model '%s', but no such model exists in the architecture file.",
250+
subckt_model.c_str());
251+
}
247252
const t_model& blk_model = models_.get_model(blk_model_id);
248253

249-
//We name the subckt based on the net it's first output pin drives
254+
//We name the subckt based on the net its first output pin drives
250255
std::string subckt_name;
251256
for (size_t i = 0; i < ports.size(); ++i) {
252257
const t_model_ports* model_port = find_model_port(blk_model, ports[i]);
@@ -269,8 +274,7 @@ struct BlifAllocCallback : public blifparse::Callback {
269274
}
270275

271276
//The name for every block should be unique, check that there is no name conflict
272-
AtomBlockId blk_id = curr_model().find_block(subckt_name);
273-
if (blk_id) {
277+
if (AtomBlockId blk_id = curr_model().find_block(subckt_name)) {
274278
LogicalModelId conflicting_model = curr_model().block_model(blk_id);
275279
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_,
276280
"Duplicate blocks named '%s' found in netlist."
@@ -279,7 +283,7 @@ struct BlifAllocCallback : public blifparse::Callback {
279283
}
280284

281285
//Create the block
282-
blk_id = curr_model().create_block(subckt_name, blk_model_id);
286+
AtomBlockId blk_id = curr_model().create_block(subckt_name, blk_model_id);
283287
set_curr_block(blk_id);
284288

285289
for (size_t i = 0; i < ports.size(); ++i) {

0 commit comments

Comments
 (0)