Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpile: Make cast from bool to pointer compile through size_t #1134

Merged
merged 1 commit into from
Sep 22, 2024
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
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"])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should change these to core::ffi:: instead of libc:: at some point, but it's fine here; that's what we've done so far.

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;
}
Loading