@@ -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));
@@ -2538,19 +2550,18 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) {
25382550 GetEscapedStringLiteral (expr, 1 )));
25392551 return false ;
25402552 }
2553+ std::string literal;
25412554 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);
2551- return false ;
2555+ literal = GetCharArrayLiteral (expr);
2556+ } else {
2557+ literal = std::format (" c{}" , GetEscapedStringLiteral (expr, 0 ));
2558+ }
2559+ // A pointer to the array.
2560+ if (isAddrOf ()) {
2561+ literal = std::format (" {}.as_ptr().cast::<{}>()" , literal,
2562+ ToString (expr->getType ()));
25522563 }
2553- EmitFresh (std::format ( " c{} " , GetEscapedStringLiteral (expr, 0 )) );
2564+ EmitFresh (literal );
25542565 return false ;
25552566}
25562567
@@ -3136,6 +3147,11 @@ bool Converter::ConvertIncAndDec(clang::UnaryOperator *expr) {
31363147 MarkFresh ();
31373148 return true ;
31383149 }
3150+ bool deref_prefix = expr->isPrefix () && !isVoid ();
3151+ PushParen paren (*this , deref_prefix);
3152+ if (deref_prefix) {
3153+ StrCat (token::kStar );
3154+ }
31393155 {
31403156 PushExprKind push (*this , ExprKind::LValue);
31413157 Convert (expr->getSubExpr ());
@@ -5404,6 +5420,14 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
54045420 return std::move (buf).str ();
54055421 }
54065422
5423+ if (auto *literal = clang::dyn_cast<clang::StringLiteral>(
5424+ arg->IgnoreParens ()->IgnoreImplicit ());
5425+ literal && arg->getType ()->isArrayType () &&
5426+ !IsCodeUnitStringLiteral (literal)) {
5427+ MarkFresh ();
5428+ return GetCharArrayLiteral (literal);
5429+ }
5430+
54075431 if (ph_ctx.needs_materialization ()) {
54085432 auto materialized = ph_ctx.materialize_ctx ->GetOrMaterialize (
54095433 static_cast <unsigned >(ph_ctx.materialize_idx ),
@@ -5688,7 +5712,9 @@ std::string Converter::ConvertIRFragment(
56885712 assert (arg_idx < all_args.size ());
56895713 auto *arg = all_args[arg_idx];
56905714 bool is_receiver = HasReceiver (expr) && arg_idx == 0 ;
5691- bool is_cpp_ptr = arg->getType ()->isPointerType ();
5715+ bool cpp_ptr = arg->getType ()->isPointerType ();
5716+ bool is_cpp_ptr =
5717+ cpp_ptr && RuleRegistry::ParamTakesPointerValue (expr, arg_idx);
56925718
56935719 PlaceholderCtx ph_ctx{
56945720 .arg_idx = arg_idx,
@@ -5701,9 +5727,8 @@ std::string Converter::ConvertIRFragment(
57015727 .is_cpp_ptr = is_cpp_ptr,
57025728 // Whatever its spelling, a pointer in C++ is converted as one.
57035729 .maps_to_rust_ptr =
5704- !is_cpp_ptr &&
5705- RuleRegistry::MapsToPointer (
5706- ctx_, arg->IgnoreParenNoopCasts (ctx_)->getType ()),
5730+ !cpp_ptr && RuleRegistry::MapsToPointer (
5731+ ctx_, arg->IgnoreParenNoopCasts (ctx_)->getType ()),
57075732 .declared_in_rule_as_rust_ptr =
57085733 RuleRegistry::ParamIsPointer (ctx_, expr, arg_idx),
57095734 .is_index_base = ph->is_index_base ,
0 commit comments