https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90923

            Bug ID: 90923
           Summary: hash_map destroys elements without constructing them
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following snippet compiles without warnings but aborts at runtime during
the destruction of the hash_map with the stack trace below.  The problem is
caused by the hash_map insertion function never invoking the element ctor but
the hash_map dtor invoking the element dtor.

See also bug 90904 for another gotcha in these basic building blocks.

struct Value
{
  Value (): ptr (&ptr) { fputs (__PRETTY_FUNCTION__, stderr); }
  Value (const Value &): ptr (&ptr) { fputs (__PRETTY_FUNCTION__, stderr); }
  Value& operator= (const Value &) { fputs (__PRETTY_FUNCTION__, stderr);
return *this; }
  ~Value () { fputs (__PRETTY_FUNCTION__, stderr); gcc_assert (ptr == &ptr); }
  void *ptr;
};

void f (void)
{
  {
    hash_map <void *, Value> m;
    void *p = &p;
    m.get_or_insert (p);
  }

Value::~Value()during GIMPLE pass: isolate-paths
...
internal compiler error: in ~Value, at gimple-ssa-isolate-paths.c:891
...
0x1e91f09 Value::~Value()
        gcc/gimple-ssa-isolate-paths.c:891
0x1e936df void simple_hashmap_traits<default_hash_traits<void*>,
Value>::remove<hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value>
>::hash_entry>(hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value> >::hash_entry&)
        gcc/hash-map-traits.h:66
0x1e92dc3 hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value>
>::hash_entry::remove(hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value> >::hash_entry&)
        gcc/hash-map.h:47
0x1e923f9 hash_table<hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value> >::hash_entry, false,
xcallocator>::~hash_table()
        gcc/hash-table.h:674
0x1e91f25 hash_map<void*, Value,
simple_hashmap_traits<default_hash_traits<void*>, Value> >::~hash_map()
        gcc/hash-map.h:26
...

Reply via email to