diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h @@ -29,35 +29,60 @@ DIERef(llvm::Optional dwo_num, Section section, dw_offset_t die_offset) - : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)), - m_section(section), m_die_offset(die_offset) { + : m_u(dwo_num, section), m_die_offset(die_offset) { assert(this->dwo_num() == dwo_num && "Dwo number out of range?"); } llvm::Optional dwo_num() const { - if (m_dwo_num_valid) - return m_dwo_num; + if (m_u.s.dwo_num_valid) + return m_u.s.dwo_num; return llvm::None; } - Section section() const { return static_cast
(m_section); } + Section section() const { return static_cast
(m_u.s.section); } dw_offset_t die_offset() const { return m_die_offset; } bool operator<(DIERef other) const { - if (m_dwo_num_valid != other.m_dwo_num_valid) - return m_dwo_num_valid < other.m_dwo_num_valid; - if (m_dwo_num_valid && (m_dwo_num != other.m_dwo_num)) - return m_dwo_num < other.m_dwo_num; - if (m_section != other.m_section) - return m_section < other.m_section; + if (m_u.s.dwo_num_valid != other.m_u.s.dwo_num_valid) + return m_u.s.dwo_num_valid < other.m_u.s.dwo_num_valid; + // Assuming if not m_u.s.dwo_num_valid then m_u.s.dwo_num is zero. + if (m_u.s.dwo_num != other.m_u.s.dwo_num) + return m_u.s.dwo_num < other.m_u.s.dwo_num; + if (m_u.s.section != other.m_u.s.section) + return m_u.s.section < other.m_u.s.section; return m_die_offset < other.m_die_offset; } + bool operator==(DIERef other) const { + if (m_u.s.dwo_num_valid != other.m_u.s.dwo_num_valid) + return m_u.s.dwo_num_valid == other.m_u.s.dwo_num_valid; + // Assuming if not m_u.s.dwo_num_valid then m_u.s.dwo_num is zero. + if (m_u.s.dwo_num != other.m_u.s.dwo_num) + return m_u.s.dwo_num == other.m_u.s.dwo_num; + if (m_u.s.section != other.m_u.s.section) + return m_u.s.section == other.m_u.s.section; + return m_die_offset == other.m_die_offset; + } + private: - uint32_t m_dwo_num : 30; - uint32_t m_dwo_num_valid : 1; - uint32_t m_section : 1; + uint32_t get_hash_value() const { + return llvm::detail::combineHashValue(m_u.hash_bits, m_die_offset); + } + + union U { + struct S { + uint32_t dwo_num : 30; + uint32_t dwo_num_valid : 1; + uint32_t section : 1; + S(llvm::Optional dwo_num_, Section section_) + : dwo_num(dwo_num_.getValueOr(0)), dwo_num_valid(bool(dwo_num_)), + section(section_) {} + } s; + uint32_t hash_bits; + U(llvm::Optional dwo_num, Section section) + : s(dwo_num, section) {} + } m_u; dw_offset_t m_die_offset; }; static_assert(sizeof(DIERef) == 8, "");