Skip to content

Commit 93fc3aa

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 92b29c4 commit 93fc3aa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libcore/ptr/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,14 +1317,24 @@ macro_rules! fnptr_impls_safety_abi {
13171317
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13181318
impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
13191319
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1320-
fmt::Pointer::fmt(&(*self as *const ()), f)
1320+
// HACK: The intermediate cast as usize is required for AVR
1321+
// so that the address space of the source function pointer
1322+
// is preserved in the final function pointer.
1323+
//
1324+
// https://github.com/avr-rust/rust/issues/143
1325+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13211326
}
13221327
}
13231328

13241329
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13251330
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
13261331
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1327-
fmt::Pointer::fmt(&(*self as *const ()), f)
1332+
// HACK: The intermediate cast as usize is required for AVR
1333+
// so that the address space of the source function pointer
1334+
// is preserved in the final function pointer.
1335+
//
1336+
// https://github.com/avr-rust/rust/issues/143
1337+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13281338
}
13291339
}
13301340
}

0 commit comments

Comments
 (0)