[libcxx-commits] [libcxx] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)

James Y Knight via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 18 06:19:25 PDT 2023


================
@@ -1969,7 +1955,8 @@ private:
                     allocator_type __a = __str.__alloc();
                     auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
                     __begin_lifetime(__allocation.ptr, __allocation.count);
-                    __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
+                    if (__is_long())
+                        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
----------------
jyknight wrote:

Looks like this is a pre-existing bug. I changed this because it failed the test-suite without this change, as it was trying to call get_long_pointer on a short string during constant evaluation. I didn't look closely enough before to see that it's actually reachable in normal code too, if you have an allocator with `propagate_on_container_copy_assignment`, and which has unequal instances, and you are assigning from a long string to a short string that previously contained more than 15 characters (such that the long-pointer didn't happen to be zero).

Demo of crash: https://godbolt.org/z/TqEf15K3K

https://github.com/llvm/llvm-project/pull/66576


More information about the libcxx-commits mailing list