Skip to content
Open
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
8 changes: 8 additions & 0 deletions c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,14 @@ impl<'c> Translation<'c> {
// Join ty and cur_ty to the smaller of the two types. If the
// types are not cast-compatible, abort the fold.
let ty_kind = self.ast_context.resolve_type(ty).kind.clone();
if matches!(ty_kind, CTypeKind::Function(..)) {
// TODO This is a temporary workaround for #1321 (portable types in const macros).
// The workaround for most types is to create a const macro with non-portable type
// and insert casts at use sites, but this doesn't work the same for fn ptr types.
// So don't translate fn ptr const macros yet until #1321 is fixed.
return Err(format_err!("fn ptr const macros not yet supported due to non-portable types; see #1321"));
}

if let Some((canon_val, canon_ty)) = canonical {
let canon_ty_kind = self.ast_context.resolve_type(canon_ty).kind.clone();
if let Some(smaller_ty) =
Expand Down
11 changes: 10 additions & 1 deletion c2rust-transpile/tests/snapshots/os-specific/macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int size_of_dynamic(int n) {
}
#endif

// From Lua's `lobject.c`.
// From `lua`'s `lobject.c`.

#define POS "\"]"
/* number of chars of a literal string without the ending \0 */
Expand All @@ -28,3 +28,12 @@ int size_of_dynamic(int n) {
void memcpy_str_literal(char *out) {
memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
}

// From `python2`'s `bytes_methods.c`.

#define Py_MEMCPY memcpy

void f(void *x) {
size_t len = 0;
Py_MEMCPY(x, x, len);
}
5 changes: 5 additions & 0 deletions c2rust-transpile/tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ pub unsafe extern "C" fn memcpy_str_literal(mut out: *mut core::ffi::c_char) {
.wrapping_mul(::core::mem::size_of::<core::ffi::c_char>() as size_t),
);
}
#[no_mangle]
pub unsafe extern "C" fn f(mut x: *mut core::ffi::c_void) {
let mut len: size_t = 0 as size_t;
memcpy(x, x, len);
}
5 changes: 5 additions & 0 deletions c2rust-transpile/tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ pub unsafe extern "C" fn memcpy_str_literal(mut out: *mut core::ffi::c_char) {
.wrapping_mul(::core::mem::size_of::<core::ffi::c_char>() as size_t),
);
}
#[no_mangle]
pub unsafe extern "C" fn f(mut x: *mut core::ffi::c_void) {
let mut len: size_t = 0 as size_t;
memcpy(x, x, len);
}