[libc-commits] [libc] [libc] Add UTF-16 support in CharacterConverter [1/6] (PR #230434)

via libc-commits libc-commits at lists.llvm.org
Tue Oct 13 17:55:43 PDT 2026


================
@@ -112,13 +161,31 @@ LIBC_INLINE int CharacterConverter::push(char8_t utf8_byte) {
     state->bytes_stored++;
     return 0;
   }
+  // Pushing when partially popping is a misuse in the library
+  if (isPartiallyPopping()) {
+    clear();
+    return -1;
+  }
----------------
yangbowen wrote:

I agree about it causing performance issues. But the reason these checks exist is for tests to work. `utf_32_to_8_test.cpp` has the test [CantPushMidConversion](https://github.com/llvm/llvm-project/blob/233a17723ac5de7e6cab5c75a0055f73373291dd/libc/test/src/__support/wchar/utf32_to_8_test.cpp#L193). So I replicated it into `utf16_to_8_test.cpp`. But for that test to work I have to check `isPartiallyPopping` in `push(char16_t)`, so the check at 230-234. And to remain consistent I also added the check at 164-168.

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


More information about the libc-commits mailing list