[clang] [clang] Fix handling of asm string literals (PR #169803)

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 7 18:00:44 PST 2026


================
@@ -260,6 +276,26 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
     Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string);
   }
 
+  // The evaluated string is in the literal encoding (-fexec-charset).
+  // Convert it back to UTF-8
+  if (llvm::TextEncodingConverter *FromLiteral =
+          PP.getTextEncoding().getFromLiteralEncodingConverter()) {
+    std::string Raw = V.getCharArrayAsString();
+    SmallString<16> Converted;
+    if (std::error_code EC = FromLiteral->convert(Raw, Converted)) {
+      Diag(Expr->getBeginLoc(), diag::err_exec_charset_conversion_failed)
+          << EC.message() << /*from literal encoding to UTF-8*/ 2;
----------------
hubert-reinterpretcast wrote:

Please add a test for this diagnostic (e.g., by using numeric escapes to encode an invalid sequence). Note that, for portability, the test would probably need an ICU-enabled build for use with an ICU-recognized encoding name.

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


More information about the cfe-commits mailing list