about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan McKay <me@dylanmckay.io>2019-06-09 01:57:40 +1200
committerDylan McKay <me@dylanmckay.io>2020-06-09 17:34:07 +1200
commit91bff8ccdfddd119a2239e625bfb52703844f227 (patch)
tree00872380315fef2ea053bd5e605dd55759f09655
parent690bb8af510c0cf4099eac512127948180dbc792 (diff)
downloadrust-91bff8ccdfddd119a2239e625bfb52703844f227.tar.gz
rust-91bff8ccdfddd119a2239e625bfb52703844f227.zip
[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.
-rw-r--r--src/libcore/ptr/mod.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs
index ecc70adda41..777284ca5c0 100644
--- a/src/libcore/ptr/mod.rs
+++ b/src/libcore/ptr/mod.rs
@@ -1345,14 +1345,24 @@ macro_rules! fnptr_impls_safety_abi {
         #[stable(feature = "fnptr_impls", since = "1.4.0")]
         impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-                fmt::Pointer::fmt(&(*self as *const ()), f)
+                // HACK: The intermediate cast as usize is required for AVR
+                // so that the address space of the source function pointer
+                // is preserved in the final function pointer.
+                //
+                // https://github.com/avr-rust/rust/issues/143
+                fmt::Pointer::fmt(&(*self as usize as *const ()), f)
             }
         }
 
         #[stable(feature = "fnptr_impls", since = "1.4.0")]
         impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-                fmt::Pointer::fmt(&(*self as *const ()), f)
+                // HACK: The intermediate cast as usize is required for AVR
+                // so that the address space of the source function pointer
+                // is preserved in the final function pointer.
+                //
+                // https://github.com/avr-rust/rust/issues/143
+                fmt::Pointer::fmt(&(*self as usize as *const ()), f)
             }
         }
     }