------- Comment #9 from rguenth at gcc dot gnu dot org 2009-08-27 15:43 ------- In fact the code generated by the C++ frontend (or the library) looks bogus.
other.1157_15 = (const struct hash_eq_fn *) D.107435_2; this.1158_16 = (struct hash_eq_fn *) D.107436_4; other.1161_17 = (struct equal_to *) other.1157_15; this.1162_18 = (struct equal_to *) this.1158_16; __tmp = *this.1162_18; *this.1162_18 = *other.1161_17; *other.1161_17 = __tmp; this swaps the first byte(!) of the struct which contains the vtable pointer. In fact gp_hash_table::swap(gp_hash_table&) seems to cause this. Forcing to not inline that function fixes the issue as well. (so the dead store really is not dead - but only because of that bogus swap). Thus, things like void _M_swap(_Hash_code_base& __x) { std::swap(_M_extract, __x._M_extract); std::swap(_M_eq, __x._M_eq); std::swap(_M_h1, __x._M_h1); std::swap(_M_h2, __x._M_h2); } protected: _ExtractKey _M_extract; _Equal _M_eq; _H1 _M_h1; _H2 _M_h2; }; seem to corrupt the vtable pointer as the empty function classes are tail-packed into that field. OTOH std::swap should do nothing for empty classes, but instead it does ;; Function void std::swap(_Tp&, _Tp&) [with _Tp = std::equal_to<__gnu_pbds::test::basic_type>] (null) ;; enabled by -tree-original { struct equal_to __tmp; struct equal_to __tmp; <<cleanup_point <<< Unknown tree: expr_stmt (void) (__tmp = TARGET_EXPR <D.100064, *(const struct equal_to &) (const struct equal_to *) __a>) >>> >>; <<cleanup_point <<< Unknown tree: expr_stmt (void) (*(struct equal_to *) __a = *(const struct equal_to &) (const struct equal_to *) __b) >>> >>; <<cleanup_point <<< Unknown tree: expr_stmt (void) (*(struct equal_to *) __b = *(const struct equal_to &) (const struct equal_to *) &__tmp) >>> >>; } bah. Paolo, who is at fault here? The library or the frontend? The issue must be latent on trunk. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paolo dot carlini at oracle | |dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41058