================
@@ -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;
----------------
cor3ntin wrote:

I think we are missing a `return false` in the else branch (L2454 or so)

https://github.com/llvm/llvm-project/pull/138895
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to