From 80ac68404011962860e32f899fbf0859d49cbdda Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 23 Aug 2024 17:59:04 +0200 Subject: [PATCH] hashlib: replace check with proper assert --- kernel/rtlil.cc | 12 ++++++------ kernel/rtlil.h | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 01c3de99940..37d1935511d 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -250,7 +250,7 @@ RTLIL::Const::Const(const RTLIL::Const &other) { else if (is_bits()) new ((void*)&bits_) bitvectype(other.get_bits()); else - check(false); + log_assert(false && "malformed Const union"); } RTLIL::Const::Const(RTLIL::Const &&other) { @@ -261,7 +261,7 @@ RTLIL::Const::Const(RTLIL::Const &&other) { else if (is_bits()) new ((void*)&bits_) bitvectype(std::move(other.get_bits())); else - check(false); + log_assert(false && "malformed Const union"); } RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { @@ -269,7 +269,7 @@ RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { if (other.is_str()) { if (!is_str()) { // sketchy zone - check(is_bits()); + log_assert(is_bits() && "malformed Const union"); bits_.~bitvectype(); (void)new ((void*)&str_) std::string(); } @@ -278,14 +278,14 @@ RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { } else if (other.is_bits()) { if (!is_bits()) { // sketchy zone - check(is_str()); + log_assert(is_str() && "malformed Const union"); str_.~string(); (void)new ((void*)&bits_) bitvectype(); } tag = other.tag; get_bits() = other.get_bits(); } else { - check(false); + log_assert(false && "malformed Const union"); } return *this; } @@ -296,7 +296,7 @@ RTLIL::Const::~Const() { else if (is_str()) str_.~string(); else - check(false); + log_assert(false && "malformed Const union"); } bool RTLIL::Const::operator<(const RTLIL::Const &other) const diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 53732a2dda5..71524d3f2fd 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -683,13 +683,14 @@ struct RTLIL::Const bitvectype* get_if_bits() const { return is_bits() ? &bits_ : NULL; } std::string* get_if_str() const { return is_str() ? &str_ : NULL; } - void check(bool condition) const { - // TODO debug assert or throw - // log_assert(condition && "malformed Const union"); + bitvectype& get_bits() const { + log_assert(is_bits() && "malformed Const union"); + return *get_if_bits(); + } + std::string& get_str() const { + log_assert(is_str() && "malformed Const union"); + return *get_if_str(); } - - bitvectype& get_bits() const { check(is_bits()); return *get_if_bits(); } - std::string& get_str() const { check(is_str()); return *get_if_str(); } public: Const() : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::vector()) {} Const(const std::string &str); @@ -716,19 +717,19 @@ struct RTLIL::Const std::string decode_string() const; inline size_t size() const { - if (tag == backing_tag::string) + if (is_str()) return 8 * str_.size(); else { - check(tag == backing_tag::bits); + log_assert(is_bits() && "malformed Const union"); return bits_.size(); } } inline bool empty() const { - if (tag == backing_tag::string) + if (is_str()) return str_.empty(); else { - check(tag == backing_tag::bits); + log_assert(is_bits() && "malformed Const union"); return bits_.empty(); } } @@ -737,7 +738,7 @@ struct RTLIL::Const if (tag == backing_tag::bits) return; - check(tag == backing_tag::string); + log_assert(is_str() && "malformed Const union"); bitvectype new_bits;