Skip to content

Commit be00acf

Browse files
authored
Apply static mut array decay fix
1 parent 0e8a426 commit be00acf

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,15 +1986,22 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
19861986
StrCat(keyword::kAs, dest_pointee_const ? "*const u8" : "*mut u8");
19871987
break;
19881988
}
1989-
Convert(sub_expr);
1990-
if (clang::isa<clang::StringLiteral>(sub_expr) ||
1991-
clang::isa<clang::PredefinedExpr>(sub_expr)) {
1992-
StrCat(".as_ptr()");
1993-
if (!dest_pointee_const) {
1994-
StrCat(".cast_mut()");
1995-
}
1989+
if (IsGlobalVar(sub_expr)) {
1990+
StrCat("(&raw", dest_pointee_const ? keyword::kConst : keyword_mut_);
1991+
Convert(sub_expr);
1992+
StrCat(").cast::<", GetUnsafeTypeAsString(expr->getType()->getPointeeType()),
1993+
">()");
19961994
} else {
1997-
StrCat(dest_pointee_const ? ".as_ptr()" : ".as_mut_ptr()");
1995+
Convert(sub_expr);
1996+
if (clang::isa<clang::StringLiteral>(sub_expr) ||
1997+
clang::isa<clang::PredefinedExpr>(sub_expr)) {
1998+
StrCat(".as_ptr()");
1999+
if (!dest_pointee_const) {
2000+
StrCat(".cast_mut()");
2001+
}
2002+
} else {
2003+
StrCat(dest_pointee_const ? ".as_ptr()" : ".as_mut_ptr()");
2004+
}
19982005
}
19992006
break;
20002007
}

tests/unit/out/unsafe/union_tagged_struct_arms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 {
8383
let mut p_list: Branch = <Branch>::default();
8484
p_list.choice = Choice_enum::C_LIST;
8585
p_list.index = 0;
86-
p_list.v.list.items = items_4.as_mut_ptr();
86+
p_list.v.list.items = (&raw mut items_4).cast::<*mut u8>();
8787
p_list.v.list.count = 3_i64;
8888
p_list.v.list.cursor = 1_i64;
8989
assert!(((((p_list.v.list.count) == (3_i64)) as i32) != 0));

0 commit comments

Comments
 (0)