[libcxx-commits] [libcxx] Lower std::string's alignment requirement from 16 to 8. (PR #68749)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 10 16:08:53 PDT 2023


================
@@ -167,6 +167,11 @@
 // The implementation moved to the header, but we still export the symbols from
 // the dylib for backwards compatibility.
 #    define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
+// Same memory by providing the allocator more freedom to allocate the most
+// efficient size class by dropping the alignment requirements for std::string's
+// pointer from 16 to 8. This changes the output of std::string::max_size,
+// which makes it ABI breaking
----------------
ldionne wrote:

I think the main source of the ABI break here is that a `std::string`'s `data()` could suddenly be aligned at a 8-byte aligned address and passed to a function that was compiled assuming a 16-bytes alignment? Or am I mistaken?

If it's really *just* about the value of `max_size()`, honestly I think this is something we could probably do unconditionally. I think the likelihood of that actually breaking the ABI for anyone is quite small. Didn't we return an incorrect value from that function for the longest time and it never affected anyone?

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


More information about the libcxx-commits mailing list