[clang] [llvm] Enable fexec-charset option (PR #138895)
Sergei Barannikov via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 07:51:13 PDT 2026
================
@@ -2332,12 +2422,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) {
+
const llvm::UTF8 *ErrorPtrTmp;
- if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp))
+ if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp)) {
+ if (Converter) {
+ assert(isOrdinary() && "Only ordinary literals are supported");
+ SmallString<64> CpConv;
+ char *Cp = ResultPtr - Fragment.size();
+ auto EC = Converter->convert(Fragment, CpConv);
+ if (!EC) {
+ memcpy(Cp, CpConv.data(), CpConv.size());
+ ResultPtr = Cp + CpConv.size();
+ } else { // there was a conversion error
+ if (Diags)
+ Diags->Report(Tok.getLocation(),
+ diag::err_exec_charset_conversion_failed)
+ << EC.message();
+ }
+ }
----------------
s-barannikov wrote:
Although ConvertUTF8toWide can handle CharByteWidth==1 (by copying the input to the ouptut), the name suggests it should actually *convert* a string. We should either do this conversion inside that function (and hopefully give it a more precise name), or move this logic above the call (duplicating isLegalUTF8String check).
https://github.com/llvm/llvm-project/pull/138895
More information about the cfe-commits
mailing list