Skip to content

Commit 91bff8c

Browse files
committed
[AVR] Fix debug printing of function pointers
This commit fixes debug printing of function pointers on AVR. AVR does not support `addrspacecast` instructions, and so this patch modifies libcore so that a `ptrtoint` IR instruction is used and the address space cast is avoided.
1 parent 690bb8a commit 91bff8c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libcore/ptr/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1345,14 +1345,24 @@ macro_rules! fnptr_impls_safety_abi {
13451345
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13461346
impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
13471347
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1348-
fmt::Pointer::fmt(&(*self as *const ()), f)
1348+
// HACK: The intermediate cast as usize is required for AVR
1349+
// so that the address space of the source function pointer
1350+
// is preserved in the final function pointer.
1351+
//
1352+
// https://github.com/avr-rust/rust/issues/143
1353+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13491354
}
13501355
}
13511356

13521357
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13531358
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
13541359
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1355-
fmt::Pointer::fmt(&(*self as *const ()), f)
1360+
// HACK: The intermediate cast as usize is required for AVR
1361+
// so that the address space of the source function pointer
1362+
// is preserved in the final function pointer.
1363+
//
1364+
// https://github.com/avr-rust/rust/issues/143
1365+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13561366
}
13571367
}
13581368
}

0 commit comments

Comments
 (0)