[PATCH] D12299: [libcxx] Fix for ALL undefined behavior in <list>.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 11 17:38:33 PST 2015


EricWF retitled this revision from "[libcxx] ABI-Breaking Fix for ALL undefined behavior in <list>." to "[libcxx] Fix for ALL undefined behavior in <list>.".
EricWF updated the summary for this revision.
EricWF updated this revision to Diff 42557.
EricWF added a comment.

Ping.

Originally I considered this change to be ABI breaking because we changed the type of the link pointers from `__list_node_pointer` to `__list_node_base_pointer`.  However I now believe this change is ABI compatible in 99% of cases. I assert that this change is safe whenever `__list_node_pointer` and `__list_node_base_pointer` are builtin pointer types.

Unfortunately std::list supports fancy "class-like" pointers and we cannot guarantee that these fancy pointers will be ABI compatible in the same why builtin pointers are. Fancy pointers are free to have entirely different representations depending on the pointee type. For this reason I don't think we can fix std::list with fancy pointers until the next ABI version.

This patch fixes std::list for builtin pointer types in the current ABI version and fixes std::list for all fancy pointer types in the next ABI version. The patch was designed to minimize the amount of code needed to support both ABI configurations. Currently only ~5 lines of code differ.

The patch works by introducing a `__link_pointer` typedef that defines the type of pointers used to make the link list. `__link_pointer` is either `__list_node_pointer` or `__list_node_base_pointer' depending on the ABI version. Instead of working with `__node_pointer` or `__node_base_pointer` types in std::list  we now only work with `__link_pointer` types except when we absolutely need to access the underlying node. When we need to convert between `__node_pointer`,  `__node_base_pointer` or `__link_pointer` we use the conversion methods supplied defined in `__list_node_base`.

One problem with  `__link_pointer` is that its easy to accidentally depend on it being defined as `__node_pointer` or `__node_base_pointer`. For example it would be incorrect to access `__list_node::__value_` through a pointer declared as `__link_pointer` even though it will work when `__link_pointer` is an alias for `__node_pointer`. This code will compile


http://reviews.llvm.org/D12299

Files:
  include/list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12299.42557.patch
Type: text/x-patch
Size: 23809 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151212/21c98d89/attachment-0001.bin>


More information about the cfe-commits mailing list