@@ -1190,7 +1190,15 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) {
11901190}
11911191
11921192bool ConverterRefCount::VisitStringLiteral (clang::StringLiteral *expr) {
1193- if (!curr_init_type_.empty () && curr_init_type_.back ()->isArrayType ()) {
1193+ if (IsCodeUnitStringLiteral (expr)) {
1194+ auto arr = GetCodeUnitArrayLiteral (expr);
1195+ StrCat (IsArrayInitContext () ? std::format (" Box::from({})" , arr)
1196+ : ' &' + arr);
1197+ computed_expr_type_ = ComputedExprType::FreshValue;
1198+ return false ;
1199+ }
1200+
1201+ if (IsArrayInitContext ()) {
11941202 uint64_t pad = 1 ;
11951203 if (auto *arr_ty = ctx_.getAsConstantArrayType (curr_init_type_.back ())) {
11961204 uint64_t arr_size = arr_ty->getSize ().getZExtValue ();
@@ -1283,7 +1291,11 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
12831291 return false ;
12841292 }
12851293 if (IsStringLiteralExpr (sub_expr)) {
1286- StrCat (std::format (" Ptr::from_string_literal({})" ,
1294+ auto code_unit = ToStringBase (
1295+ ctx_.getAsArrayType (
1296+ sub_expr->IgnoreParens ()->IgnoreImplicit ()->getType ())
1297+ ->getElementType ());
1298+ StrCat (std::format (" Ptr::<{}>::from_string_literal({})" , code_unit,
12871299 ToString (sub_expr->IgnoreParens ())));
12881300 computed_expr_type_ = ComputedExprType::FreshPointer;
12891301 return false ;
@@ -2169,7 +2181,12 @@ std::string ConverterRefCount::ConvertVarInitValue(clang::QualType qual_type,
21692181 }
21702182 if (qual_type.getNonReferenceType ()->isArrayType ()) {
21712183 if (IsStringLiteralExpr (expr)) {
2172- return std::format (" Ptr::from_string_literal_array({})" ,
2184+ auto code_unit = ToStringBase (
2185+ ctx_.getAsArrayType (
2186+ expr->IgnoreParens ()->IgnoreImplicit ()->getType ())
2187+ ->getElementType ());
2188+ return std::format (" Ptr::<Box<[{}]>>::from_string_literal_array({})" ,
2189+ code_unit,
21732190 ToString (expr->IgnoreParens ()->IgnoreImplicit ()));
21742191 }
21752192 return std::format (" ({} as {})" , ConvertFreshPointer (expr),
@@ -2461,7 +2478,12 @@ void ConverterRefCount::ConvertArraySubscript(clang::Expr *base,
24612478 {
24622479 PushParen paren (*this , is_inner_boxed);
24632480 if (IsStringLiteralExpr (base)) {
2464- StrCat (std::format (" Ptr::from_string_literal({}).offset({})" ,
2481+ auto code_unit = ToStringBase (
2482+ ctx_.getAsArrayType (
2483+ base->IgnoreParens ()->IgnoreImplicit ()->getType ())
2484+ ->getElementType ());
2485+ StrCat (std::format (" Ptr::<{}>::from_string_literal({}).offset({})" ,
2486+ code_unit,
24652487 ToString (base->IgnoreParens ()->IgnoreImplicit ()),
24662488 ConvertSubscriptIndex (idx)));
24672489 } else {
0 commit comments