@@ -2510,6 +2510,18 @@ bool Converter::VisitSourceLocExpr(clang::SourceLocExpr *expr) {
25102510 }
25112511}
25122512
2513+ std::string Converter::GetCharArrayLiteral (const clang::StringLiteral *expr) {
2514+ std::string out = " (&[" ;
2515+ for (char c : expr->getString ()) {
2516+ auto value = CharRustTypeIsSigned ()
2517+ ? std::to_string (static_cast <signed char >(c))
2518+ : std::to_string (static_cast <unsigned char >(c));
2519+ out += getTypedLiteral (value.c_str (), CharRustType ()) + " , " ;
2520+ }
2521+ out += getTypedLiteral (" 0" , CharRustType ()) + " ])" ;
2522+ return out;
2523+ }
2524+
25132525bool Converter::VisitStringLiteral (clang::StringLiteral *expr) {
25142526 if (IsCodeUnitStringLiteral (expr)) {
25152527 EmitFresh (GetCodeUnitArrayLiteral (expr));
@@ -2539,15 +2551,7 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) {
25392551 return false ;
25402552 }
25412553 if (expr->getString ().contains (' \0 ' )) {
2542- std::string out = " (&[" ;
2543- for (char c : expr->getString ()) {
2544- auto value = CharRustTypeIsSigned ()
2545- ? std::to_string (static_cast <signed char >(c))
2546- : std::to_string (static_cast <unsigned char >(c));
2547- out += getTypedLiteral (value.c_str (), CharRustType ()) + " , " ;
2548- }
2549- out += getTypedLiteral (" 0" , CharRustType ()) + " ])" ;
2550- EmitFresh (out);
2554+ EmitFresh (GetCharArrayLiteral (expr));
25512555 return false ;
25522556 }
25532557 EmitFresh (std::format (" c{}" , GetEscapedStringLiteral (expr, 0 )));
@@ -5409,6 +5413,14 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
54095413 return std::move (buf).str ();
54105414 }
54115415
5416+ if (auto *literal = clang::dyn_cast<clang::StringLiteral>(
5417+ arg->IgnoreParens ()->IgnoreImplicit ());
5418+ literal && arg->getType ()->isArrayType () &&
5419+ !IsCodeUnitStringLiteral (literal)) {
5420+ MarkFresh ();
5421+ return GetCharArrayLiteral (literal);
5422+ }
5423+
54125424 if (ph_ctx.needs_materialization ()) {
54135425 auto materialized = ph_ctx.materialize_ctx ->GetOrMaterialize (
54145426 static_cast <unsigned >(ph_ctx.materialize_idx ),
0 commit comments