From 7775d2806fe082626103f5abffd95fe9e1fccc27 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 11 Dec 2014 21:46:36 +0100 Subject: [PATCH] Added IdString::destruct_guard hack --- kernel/rtlil.cc | 1 + kernel/rtlil.h | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index f5dbafe16..5c010dabf 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -27,6 +27,7 @@ YOSYS_NAMESPACE_BEGIN +RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard; std::vector RTLIL::IdString::global_refcount_storage_; std::vector RTLIL::IdString::global_id_storage_; std::map RTLIL::IdString::global_id_index_; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 0157f3b7c..29fa90692 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -85,6 +85,12 @@ namespace RTLIL } }; + static struct destruct_guard_t { + bool ok = false; + destruct_guard_t() { ok = true; } + ~destruct_guard_t() { ok = false; } + } destruct_guard; + static std::vector global_refcount_storage_; static std::vector global_id_storage_; static std::map global_id_index_; @@ -98,6 +104,8 @@ namespace RTLIL static inline int get_reference(const char *p) { + log_assert(destruct_guard.ok); + if (p[0]) { log_assert(p[1] != 0); log_assert(p[0] == '$' || p[0] == '\\'); @@ -126,6 +134,11 @@ namespace RTLIL static inline void put_reference(int idx) { + // put_reference() may be called from destructors after the destructor of + // global_refcount_storage_ has been run. in this case we simply do nothing. + if (!destruct_guard.ok) + return; + log_assert(global_refcount_storage_.at(idx) > 0); if (--global_refcount_storage_.at(idx) != 0) -- 2.30.2