Skip to content

Commit 2cd9e5d

Browse files
authored
Fix converter crashes around freshness (#503)
1 parent 1c6b5ce commit 2cd9e5d

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,7 @@ bool Converter::VisitStmtExpr(clang::StmtExpr *expr) {
31593159
Convert(s);
31603160
}
31613161
}
3162+
SetFreshType(expr->getType());
31623163
return false;
31633164
}
31643165

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,9 +1770,7 @@ bool ConverterRefCount::VisitReturnStmt(clang::ReturnStmt *stmt) {
17701770

17711771
bool ConverterRefCount::VisitStmtExpr(clang::StmtExpr *expr) {
17721772
PushConversionKind push(*this, ConversionKind::FullRefCount);
1773-
Converter::VisitStmtExpr(expr);
1774-
SetFreshType(expr->getType());
1775-
return false;
1773+
return Converter::VisitStmtExpr(expr);
17761774
}
17771775

17781776
void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) {

‎tests/unit/out/refcount/stmt_expr.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ fn main_0() -> i32 {
4141
inner
4242
} == 100)
4343
);
44+
{
45+
counter.postfix_inc()
46+
};
47+
{
48+
if (counter != 2) {
49+
counter = 2;
50+
}
51+
};
52+
assert!((counter == 2));
4453
return 0;
4554
}
4655
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/stmt_expr.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ unsafe fn main_0() -> i32 {
4343
inner
4444
}) == (100))
4545
);
46+
{
47+
counter.postfix_inc()
48+
};
49+
{
50+
if ((counter) != (2)) {
51+
counter = 2;
52+
}
53+
};
54+
assert!(((counter) == (2)));
4655
return 0;
4756
}
4857
pub unsafe fn __cpp2rust_init_globals() {}

‎tests/unit/stmt_expr.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@ int main() {
3232
});
3333
inner;
3434
}) == 100);
35+
36+
({ counter++; });
37+
__extension__({
38+
if (counter != 2) {
39+
counter = 2;
40+
}
41+
});
42+
assert(counter == 2);
3543
return 0;
3644
}

0 commit comments

Comments
 (0)