Skip to content

Commit a913ed0

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 2f4b347 commit a913ed0

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
@@ -1307,14 +1307,24 @@ macro_rules! fnptr_impls_safety_abi {
13071307
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13081308
impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
13091309
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1310-
fmt::Pointer::fmt(&(*self as *const ()), f)
1310+
// HACK: The intermediate cast as usize is required for AVR
1311+
// so that the address space of the source function pointer
1312+
// is preserved in the final function pointer.
1313+
//
1314+
// https://github.com/avr-rust/rust/issues/143
1315+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13111316
}
13121317
}
13131318

13141319
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13151320
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
13161321
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1317-
fmt::Pointer::fmt(&(*self as *const ()), f)
1322+
// HACK: The intermediate cast as usize is required for AVR
1323+
// so that the address space of the source function pointer
1324+
// is preserved in the final function pointer.
1325+
//
1326+
// https://github.com/avr-rust/rust/issues/143
1327+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13181328
}
13191329
}
13201330
}

0 commit comments

Comments
 (0)