This is an archive of the discontinued LLVM Phabricator instance.

Fix undefined behavior in __hash_table
ClosedPublic

Authored by EricWF on May 30 2016, 12:19 AM.

Details

Summary

This patch attempts to fix the undefined behavior in __hash_table by changing the node pointer types used throughout. The pointer types are changed for raw pointers in the current ABI and for fancy pointers in ABI V2 (since the fancy pointer types may not be ABI compatible).

The UB in __hash_table arises because tree downcasts the embedded end node and then deferences that pointer. Currently there are 2 node types in __hash_table:

  • __hash_node_base which contains the __next_ pointer.
  • __hash_node which contains __hash_ and __value_.

Currently the bucket list, iterators, and __next_ pointers store pointers to __hash_node even though they all need to store __hash_node_base pointers.
This patch makes that change by introducing a __next_pointer typedef which is a pointer to __hash_node in the current ABI and __hash_node_base afterwards.

One notable change is to the type of __bucket_list which used to be defined as unique_ptr<__node_pointer[], ...> and is now unique_ptr<__next_pointer[], ...> meaning that we now allocate and deallocate different types using a different allocator. I'm going to give this part of the change more thought since it may introduce compatibility issues.

This change is similar to D20786.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 58936.May 30 2016, 12:19 AM
EricWF retitled this revision from to Fix undefined behavior in __hash_table.
EricWF updated this object.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.
EricWF planned changes to this revision.Jun 2 2016, 2:19 AM

There's an unintentional functionality change somewhere is this patch.

EricWF updated this revision to Diff 65253.Jul 23 2016, 1:43 PM
  • Merge with upstream.
  • Cleanup logic in iterator
  • Remove UBSAN blacklist. It's no longer needed. We have no more UB.
EricWF accepted this revision.Jul 23 2016, 1:43 PM
EricWF added a reviewer: EricWF.
This revision is now accepted and ready to land.Jul 23 2016, 1:43 PM
EricWF closed this revision.Jul 23 2016, 1:44 PM
test/libcxx/test/config.py