Add test coverage for the new behaviors, especially to verify that the returned string uses the correct allocator. Fixes https://github.com/llvm/llvm-project/issues/64644 Migrated from https://reviews.llvm.org/D157776 — @philnik777 @pfusik @ldionne @mordante please take another look!