diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-11-27 22:27:22 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-11-27 22:27:22 +0000 |
commit | ea44ee202f6a73bfd832d89bd882b34cda9ca65e (patch) | |
tree | adb715061579324d4a04659a1f55d6241682dff2 /libcxx/include/bitset | |
parent | 8eaa8ec8fc9591bc71675605a3cee24a17d16d3f (diff) | |
download | llvm-ea44ee202f6a73bfd832d89bd882b34cda9ca65e.zip llvm-ea44ee202f6a73bfd832d89bd882b34cda9ca65e.tar.gz llvm-ea44ee202f6a73bfd832d89bd882b34cda9ca65e.tar.bz2 |
Fix problems with r'890 when building on machines where sizeof(size_t) != sizeof(unsigned long long) and C++03
llvm-svn: 319106
Diffstat (limited to 'libcxx/include/bitset')
-rw-r--r-- | libcxx/include/bitset | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libcxx/include/bitset b/libcxx/include/bitset index e26e674..cd6c289 100644 --- a/libcxx/include/bitset +++ b/libcxx/include/bitset @@ -235,8 +235,13 @@ void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; - for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) - __t[__i] = static_cast<__storage_type>(__v); + size_t __sz = _Size; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) + if ( __sz < __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; + else + __t[__i] = static_cast<__storage_type>(__v); + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); @@ -248,6 +253,9 @@ void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { __first_[0] = __v; + if (_Size < __bits_per_word) + __first_[0] &= ( 1ULL << _Size ) - 1; + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); } @@ -261,7 +269,9 @@ __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT #if __SIZEOF_SIZE_T__ == 8 : __first_{__v} #elif __SIZEOF_SIZE_T__ == 4 - : __first_{static_cast<__storage_type>(__v), static_cast<__storage_type>(__v >> __bits_per_word)} + : __first_{static_cast<__storage_type>(__v), + _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) + : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} #else #error This constructor has not been ported to this platform #endif |