[clang] [llvm] Enable fexec-charset option (PR #138895)

Abhina Sree via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 2 06:37:30 PDT 2026


================
@@ -2343,9 +2432,29 @@ static const char *resyncUTF8(const char *Err, const char *End) {
 /// This function copies from Fragment, which is a sequence of bytes
 /// within Tok's contents (which begin at TokBegin) into ResultPtr.
 /// Performs widening for multi-byte characters.
-bool StringLiteralParser::CopyStringFragment(const Token &Tok,
-                                             const char *TokBegin,
-                                             StringRef Fragment) {
+bool StringLiteralParser::CopyStringFragment(
+    const Token &Tok, const char *TokBegin, StringRef Fragment,
+    llvm::TextEncodingConverter *Converter) {
+
+  if (CharByteWidth == 1 && Converter) {
+    const llvm::UTF8 *FragmentBegin =
+        reinterpret_cast<const llvm::UTF8 *>(Fragment.begin());
+    assert(llvm::isLegalUTF8String(
+        &FragmentBegin, reinterpret_cast<const llvm::UTF8 *>(Fragment.end())));
+    SmallString<64> CpConv;
+    auto EC = Converter->convert(Fragment, CpConv);
+    if (!EC) {
+      memcpy(ResultPtr, CpConv.data(), CpConv.size());
+      ResultPtr += CpConv.size();
+    } else { // there was a conversion error
+      if (Diags)
+        Diags->Report(Tok.getLocation(),
+                      diag::err_exec_charset_conversion_failed)
+            << EC.message();
+    }
+    return false;
----------------
abhina-sree wrote:

Sure, I restored it back to the previous version and added another RUN line to the testcase

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


More information about the cfe-commits mailing list