diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2018-02-07 21:30:17 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2018-02-07 21:30:17 +0000 |
| commit | fc940277cba00b3a023c8c0f15360df73319c2a4 (patch) | |
| tree | 2ade6d9b28e9eb75e3f008d825a7e628102a2544 | |
| parent | ce26819f9e673c844d82f5394b660fd3572d8a7d (diff) | |
| download | bcm5719-llvm-fc940277cba00b3a023c8c0f15360df73319c2a4.tar.gz bcm5719-llvm-fc940277cba00b3a023c8c0f15360df73319c2a4.zip | |
Fix PR#31454 - 'basic_string<T>::push_back() crashes if sizeof(T)>sizeof(long long)'. We were mishandling the small-string optimization calculations for very large 'characters'. This may be an ABI change (change the size of) strings of very large 'characters', but since they never worked, I'm not too concerned.
llvm-svn: 324531
| -rw-r--r-- | libcxx/include/string | 10 | ||||
| -rw-r--r-- | libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/libcxx/include/string b/libcxx/include/string index b213cd411d1..f89ef5741e5 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1363,9 +1363,13 @@ private: enum {__alignment = 16}; static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s) _NOEXCEPT - {return (__s < __min_cap ? static_cast<size_type>(__min_cap) : - __align_it<sizeof(value_type) < __alignment ? - __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} + { + if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1; + size_type __guess = __align_it<sizeof(value_type) < __alignment ? + __alignment/sizeof(value_type) : 1 > (__s+1) - 1; + if (__guess == __min_cap) ++__guess; + return __guess; + } inline void __init(const value_type* __s, size_type __sz, size_type __reserve); diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp index 5ca5aaf8629..128446534e8 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp @@ -48,7 +48,7 @@ int main() test(S("12345678901234567890"), 'a', S("12345678901234567890a")); } #endif -#if 0 + { // https://bugs.llvm.org/show_bug.cgi?id=31454 std::basic_string<veryLarge> s; @@ -57,5 +57,4 @@ int main() s.push_back(vl); s.push_back(vl); } -#endif } |

