Skip to content

Commit

Permalink
transpile: Make cast from bool to pointer compile through size_t (#…
Browse files Browse the repository at this point in the history
…1134)

* Similar to #1030.

* Fixes #1077.
  • Loading branch information
kkysen authored Sep 22, 2024
2 parents 03b949c + 28cad01 commit 73bdbb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4282,6 +4282,13 @@ impl<'c> Translation<'c> {
target_ty,
)))
})
} else if target_ty_ctype.is_pointer() && source_ty_kind.is_bool() {
val.and_then(|x| {
Ok(WithStmts::new_val(mk().cast_expr(
mk().cast_expr(x, mk().path_ty(vec!["libc", "size_t"])),
target_ty,
)))
})
} else {
// Other numeric casts translate to Rust `as` casts,
// unless the cast is to a function pointer then use `transmute`.
Expand Down
1 change: 1 addition & 0 deletions tests/casts/src/casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ void cast_stuff(void) {

bool b = true;
float x15 = b;
void* x16 = (void*)b;
}

0 comments on commit 73bdbb8

Please sign in to comment.