Skip to content

Commit 73bdbb8

Browse files
authored
transpile: Make cast from bool to pointer compile through size_t (#1134)
* Similar to #1030. * Fixes #1077.
2 parents 03b949c + 28cad01 commit 73bdbb8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

c2rust-transpile/src/translator/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,13 @@ impl<'c> Translation<'c> {
42824282
target_ty,
42834283
)))
42844284
})
4285+
} else if target_ty_ctype.is_pointer() && source_ty_kind.is_bool() {
4286+
val.and_then(|x| {
4287+
Ok(WithStmts::new_val(mk().cast_expr(
4288+
mk().cast_expr(x, mk().path_ty(vec!["libc", "size_t"])),
4289+
target_ty,
4290+
)))
4291+
})
42854292
} else {
42864293
// Other numeric casts translate to Rust `as` casts,
42874294
// unless the cast is to a function pointer then use `transmute`.

tests/casts/src/casts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ void cast_stuff(void) {
3030

3131
bool b = true;
3232
float x15 = b;
33+
void* x16 = (void*)b;
3334
}

0 commit comments

Comments
 (0)