Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ bool Converter::ConvertVarDeclSkipInit(clang::VarDecl *decl) {
auto *method_or_null =
curr_function_ ? clang::dyn_cast<clang::CXXMethodDecl>(curr_function_)
: nullptr;
if (!qual_type.isConstQualified() && !qual_type->isReferenceType() &&
if ((hoisted_decls_.contains(decl) || !qual_type.isConstQualified()) &&
!qual_type->isReferenceType() &&
((method_or_null == nullptr) || !method_or_null->isVirtual()) &&
!IsGlobalVar(decl)) {
StrCat(keyword_mut_);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/goto_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ static int early(int n) {
goto out;
}
ret = 100;
const int intentionally_const_var = 22;
out:
return ret;
return ret + intentionally_const_var - intentionally_const_var;
}

static int from_loop(int n) {
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/out/refcount/goto_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::rc::{Rc, Weak};
pub fn early_0(n: i32) -> i32 {
let n: Value<i32> = Rc::new(RefCell::new(n));
let ret: Value<i32> = <Value<i32>>::default();
let intentionally_const_var: Value<i32> = <Value<i32>>::default();
goto_block!({
'__entry: {
*ret.borrow_mut() = 0;
Expand All @@ -17,9 +18,11 @@ pub fn early_0(n: i32) -> i32 {
goto!('out);
}
(*ret.borrow_mut()) = 100;
*intentionally_const_var.borrow_mut() = 22;
}
'out: {
return (*ret.borrow());
return (((*ret.borrow()) + (*intentionally_const_var.borrow()))
- (*intentionally_const_var.borrow()));
}
});
panic!("ub: non-void function does not return a value")
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/out/unsafe/goto_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn early_0(mut n: i32) -> i32 {
let mut ret: i32 = 0_i32;
let mut intentionally_const_var: i32 = 0_i32;
goto_block!({
'__entry: {
ret = 0;
Expand All @@ -16,9 +17,10 @@ pub unsafe fn early_0(mut n: i32) -> i32 {
goto!('out);
}
ret = 100;
intentionally_const_var = 22;
}
'out: {
return ret;
return (((ret) + (intentionally_const_var)) - (intentionally_const_var));
}
});
panic!("ub: non-void function does not return a value")
Expand Down
Loading