From a90f9406155aafb4becc43fb21c75ab3aff9bdd7 Mon Sep 17 00:00:00 2001 From: Aki Van Ness Date: Wed, 1 Feb 2023 10:15:20 -0500 Subject: [PATCH] backends/firrtl: Ensure `modInstance` is valid This should fix #3648 where when calling `emit_elaborated_extmodules` it checks to see if a module is a black-box, however there was no validation that the cell type was actually known, and it just always assumed that we would get a valid instance, causing a segfault. --- backends/firrtl/firrtl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backends/firrtl/firrtl.cc b/backends/firrtl/firrtl.cc index d68c52563..eb30ab4b9 100644 --- a/backends/firrtl/firrtl.cc +++ b/backends/firrtl/firrtl.cc @@ -346,6 +346,12 @@ void emit_elaborated_extmodules(RTLIL::Design *design, std::ostream &f) { // Find the module corresponding to this instance. auto modInstance = design->module(cell->type); + // Ensure that we actually have a module instance + if (modInstance == nullptr) { + log_error("Unknown cell type %s\n", cell->type.c_str()); + return; + } + bool modIsBlackbox = modInstance->get_blackbox_attribute(); if (modIsBlackbox)