llvm-project/libcxx/include
Eric Fiselier 40492ba417 Fix undefined behavior in __hash_table
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.



Reviewers: mclow.lists, EricWF

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D20787

llvm-svn: 276533
2016-07-23 20:36:55 +00:00
..
experimental Implement P0392r0. Integrate filesystem::path and string_view. 2016-07-23 03:10:56 +00:00
ext Cleanup: move visibility/linkage attributes to the first declaration. 2016-04-22 01:04:55 +00:00
support Implement LWG issue 1169. num_get not fully compatible with strto* 2016-06-19 06:58:22 +00:00
CMakeLists.txt Fix PR27751. Add proper dependancies for install-libcxx-headers rule 2016-05-27 23:33:10 +00:00
__bit_reference Get tests running with warnings. Fix warnings in headers and tests 2015-02-05 20:28:37 +00:00
__bsd_locale_defaults.h Reorganize _LIBCPP_LOCALE__L_EXTENSIONS 2016-03-09 15:39:39 +00:00
__bsd_locale_fallbacks.h Reorganize _LIBCPP_LOCALE__L_EXTENSIONS 2016-03-09 15:39:39 +00:00
__config Fix undefined behavior in __hash_table 2016-07-23 20:36:55 +00:00
__config_site.in [libcxx] Allow explicit pthread opt-in 2016-05-25 17:40:09 +00:00
__debug Fix undefined behavior in __hash_table 2016-07-23 20:36:55 +00:00
__functional_03 [libcxx] Fix PR23589: std::function doesn't recognize null pointer to varargs function. 2015-08-18 19:41:51 +00:00
__functional_base Fix most GCC attribute ignored warnings 2016-04-21 22:54:21 +00:00
__functional_base_03 [libcxx] Rewrite C++03 __invoke. 2015-08-26 20:15:02 +00:00
__hash_table Fix undefined behavior in __hash_table 2016-07-23 20:36:55 +00:00
__locale Use libcxx's default rune table with the Musl C library. 2015-11-24 10:24:54 +00:00
__mutex_base Don't use pthread initializers in constexpr constructors. Patch by elram. Reviewed at https://reviews.llvm.org/D21637. 2016-07-18 17:23:06 +00:00
__nullptr Factor definition of std::nullptr_t out of <cstddef> into a header that can also be used by <stddef.h>. 2015-10-08 20:34:11 +00:00
__refstring Fix some -Wundef issues. 2015-02-05 02:34:59 +00:00
__split_buffer Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
__sso_allocator Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
__std_stream Enable and fix warnings during the build. 2015-07-18 20:40:46 +00:00
__string Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459 2016-07-21 05:31:24 +00:00
__threading_support [libcxx] Allow explicit pthread opt-in 2016-05-25 17:40:09 +00:00
__tree Fix undefined behavior in __tree 2016-07-19 17:56:20 +00:00
__tuple Cleanup SFINAE in tuple, and add tests for reference assignment 2016-07-02 01:25:46 +00:00
__undef___deallocate Add option to disable __deallocate #warning 2016-07-12 14:39:13 +00:00
__undef_min_max Add option to disable __deallocate #warning 2016-07-12 14:39:13 +00:00
algorithm Add heterogeneous comparator support for __debug_less. Fixes PR17147. 2016-07-19 23:27:18 +00:00
array Add is_swappable/is_nothrow_swappable traits 2016-04-21 23:38:59 +00:00
atomic Revert r276506 - Diagnose invalid memory order arguments in <atomic>. 2016-07-23 01:43:53 +00:00
bitset Fix most GCC attribute ignored warnings 2016-04-21 22:54:21 +00:00
cassert
ccomplex
cctype Put back the undefs that Richard removed. Boost won't build w/o these; specifically the file 'bytes_methods.h' in Apple's python framework defines these. 2016-04-04 22:49:20 +00:00
cerrno Split <errno.h> out of <cerrno>. 2015-10-08 20:37:11 +00:00
cfenv Fix incorrect file header. This is <cfenv> not <cctype>. 2015-10-08 21:17:21 +00:00
cfloat Split <float.h> out of <cfloat>. 2015-10-08 20:37:44 +00:00
chrono Last bit of P0006; mark it as complete 2015-11-30 05:39:30 +00:00
cinttypes Split <inttypes.h> out of <cinttypes>. 2015-10-08 20:38:53 +00:00
ciso646
climits
clocale Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
cmath Implement P0030R1: Introduce a 3-Argument Overload to std::hypot 2016-05-17 14:52:19 +00:00
codecvt Update synopsis in <locale> to match LWG Issue 2229. No code change 2013-08-27 14:22:13 +00:00
complex Add SFINAE on additional overloads of std::complex functions. Fixes PR19921. 2016-07-20 00:14:10 +00:00
complex.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
condition_variable Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
csetjmp Split <setjmp.h> out of <csetjmp>. 2015-10-08 20:41:26 +00:00
csignal
cstdarg
cstdbool
cstddef PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
cstdint
cstdio Split <stdio.h> out of <cstdio>. 2015-10-09 01:29:09 +00:00
cstdlib Split <stdlib.h> out of <cstdlib>. 2015-10-09 01:41:45 +00:00
cstring Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
ctgmath
ctime Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
ctype.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
cwchar Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
cwctype Split <wctype.h> out of <cwctype>. 2015-10-09 19:57:37 +00:00
deque Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
errno.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
exception Fix typo it _LIBCPP_NO_EXCEPTIONS macro 2016-05-07 02:30:21 +00:00
float.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
forward_list Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
fstream Don't call memmove when there's nothing to move. Fixes PR#27978. 2016-06-04 16:16:59 +00:00
functional Move std::function constructor SFINAE into template parameter list. Fixes PR20002. 2016-07-20 05:21:00 +00:00
future Cleanup non-standard tests as reported by STL@microsoft.com. NFC. 2016-06-01 21:05:53 +00:00
initializer_list Apply constexpr to initializer_list for c++1y. 2013-08-26 20:11:32 +00:00
inttypes.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
iomanip Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459 2016-07-21 05:31:24 +00:00
ios Make ios_base::failure visibility specified consistent 2016-04-21 23:00:33 +00:00
iosfwd Make __wrap_iter work with GCC again 2016-02-20 00:19:45 +00:00
iostream Make the presence of stdin and stdout optional. 2015-03-26 14:35:46 +00:00
istream Constuct a sentry object in istream::readsome, and handle failures appropriately. Fixes PR#28217. 2016-07-13 16:58:48 +00:00
iterator Change a couple ifdefs from '#if __cplusplus >= 2011xxx' to '#ifndef _LIBCPP_CXX03_LANG'. No functionality change. 2016-07-18 13:19:00 +00:00
limits [WebAssembly] Set std::numeric_limits's traps field for WebAssembly. 2016-01-13 16:32:00 +00:00
list Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
locale Fix PR28079 - std::wstring_convert move constructor broken. 2016-06-26 22:56:26 +00:00
map Change a couple ifdefs from '#if __cplusplus >= 2011xxx' to '#ifndef _LIBCPP_CXX03_LANG'. No functionality change. 2016-07-18 13:19:00 +00:00
math.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
memory Always use the allocator to construct/destruct elements of a deque/vector. Fixes PR#28412. Thanks to Jonathan Wakely for the report. 2016-07-11 21:38:08 +00:00
module.modulemap Remove __config module to avoid #include cycle when libc headers include libc++'s <foo.h> headers. 2015-10-13 22:13:33 +00:00
mutex Fix const default initialization of lock_guard<> 2016-06-15 17:04:40 +00:00
new [libcxx] Rework sized delete. 2015-05-19 02:03:22 +00:00
numeric [libcxx] Fix use of operator comma where the types can be user defined 2014-10-27 19:28:20 +00:00
ostream Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459 2016-07-21 05:31:24 +00:00
queue Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
random Cleanup: move visibility/linkage attributes to the first declaration. 2015-11-07 01:22:13 +00:00
ratio Missing file from last commit 2015-11-30 05:04:48 +00:00
regex [libcxx] Fix definition of regex_traits::__regex_word on big-endian glibc systems 2016-02-17 13:16:31 +00:00
scoped_allocator Fix LWG#2476: scoped_allocator_adaptor is not assignable 2015-10-25 19:52:47 +00:00
set Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. vector/unordered/list/string already do this. Add tests for all the containers to verify this. 2015-11-26 01:24:04 +00:00
setjmp.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
shared_mutex Qualify calls to addressof to avoid getting ADL. Fixes PR#27254. 2016-04-13 17:02:23 +00:00
sstream Revert "Remove visibility attributes from out-of-class method definitions in iostreams." 2016-01-08 19:21:02 +00:00
stack Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
stdbool.h Add stdbool.h wrapper for libc++ 2016-02-20 00:16:41 +00:00
stddef.h PR25118: move system_header pragma before uses of include_next to avoid extension warnings for people finding libc++ headers via -I paths. 2015-10-09 00:26:50 +00:00
stdexcept Fix most GCC attribute ignored warnings 2016-04-21 22:54:21 +00:00
stdio.h Split <stdio.h> out of <cstdio>. 2015-10-09 01:29:09 +00:00
stdlib.h Cleanup foo.h headers and __config to work in C 2015-11-06 06:30:12 +00:00
streambuf [streambuf] Added call to traits_type::copy to common case in xsgetn() 2016-06-10 16:00:29 +00:00
string Implement std::string_view as described in http://wg21.link/P0254R1. Reviewed as https://reviews.llvm.org/D21459 2016-07-21 05:31:24 +00:00
string.h Instead of asking glibc to provide correct C++ signatures for <string.h> 2016-02-11 23:51:02 +00:00
string_view Fix some string_view tests that were failing when exceptions were disabled. Also comment out a _LIBCPP_ASSERT that gcc4.9 was complaining about. Will revisit that later. 2016-07-21 06:24:04 +00:00
strstream
system_error Fix most GCC warnings during build. Only -Wattribute left. 2015-08-28 07:02:42 +00:00
tgmath.h
thread Cleanup error handling when TLS creation fails 2016-05-30 23:15:19 +00:00
tuple Add tests for reference binding assertions in std::tuple. 2016-07-20 02:57:39 +00:00
type_traits Reimplement is_constructible fallback implementation. Fixes PR21574. 2016-07-20 05:01:24 +00:00
typeindex Nico Rieck: this patch series fixes visibility issues on Windows as explained in <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-August/031214.html>. 2013-08-12 18:38:34 +00:00
typeinfo RTTI Uniqueness: remove __name_for_load function. 2014-04-03 09:12:38 +00:00
unordered_map Change a couple ifdefs from '#if __cplusplus >= 2011xxx' to '#ifndef _LIBCPP_CXX03_LANG'. No functionality change. 2016-07-18 13:19:00 +00:00
unordered_set Cleanup: move visibility/linkage attributes to the first declaration. 2016-04-22 01:04:55 +00:00
utility Rename and rework `_LIBCPP_TRIVIAL_PAIR_COPY_CTOR`. Move FreeBSD configuration in-tree. 2016-07-18 01:58:37 +00:00
valarray Mark declarations of externally instantiated functions as inline so GCC doesn't complain. 2015-12-15 01:41:41 +00:00
vector Implement P0084r2. Changing emplace return types. 2016-07-21 03:20:17 +00:00
wchar.h Fix overload sets of strchr, strpbrk, strrchr, memchr and strstr from 2016-02-10 00:59:02 +00:00
wctype.h Split <wctype.h> out of <cwctype>. 2015-10-09 19:57:37 +00:00