Repository: rust
Issue: `core::ptr::copy_nonoverlapping` crashes when writing to odd addresses on ARM `thumbv7em-none-eabihf`
Labels: O-Arm,T-compiler,C-bug

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->
## Updated report

After some further investigation it seems that the `core::ptr::copy_nonoverlapping` function crashes when the dest address is not even on the `thumbv7em-none-eabihf` platform. In the example above I am copying two bytes and experience the crash when the address copied to is odd.

### MWE:
```rust
#[inline(never)]
fn mwe() {
    let buf1 = "424242";
    let mut buf2 = [0; 6];
    let buf1_ptr = buf1.as_ptr();
    let buf2_ptr = buf2.as_mut_ptr();

    // Crashes if n is odd, not if n is even
    let n = 1;

    unsafe {
        core::ptr::copy_nonoverlapping(buf1_ptr, buf2_ptr.offset(n), 2);
    }

    // Force usage of `buf2`
    write!(DummyWrite, "Test: {:?}", &buf2).unwrap();
}
```

## Original report
I am using the [`cortex-m-semihosting`] crate to write debug messages over SWD, however when writing multi-digit numbers the execution hangs. Looking at the stacktrace from gdb it seems that execution is stuck on `core::ptr::copy_nonoverlapping`. Experimenting with trivial uses of `core::ptr::copy_nonoverlapping` does not seem to hang.

```rust
hprintln!("Test: {}", 1); // works fine
hprintln!("Test: {}", 11); // hangs
```

### Meta

The same behaviour is also present in rust nightly.

Toolchain: `thumbv7em-none-eabihf`

`rustc --version --verbose`:
```
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0
```

### Stacktrace from gdb

```
#2  <signal handler called>
#3  0x0c004c96 in core::intrinsics::copy_nonoverlapping<u8> ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/core/src/intrinsics.rs:1866
#4  core::fmt::num::imp::fmt_u32 ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/core/src/fmt/num.rs:263
#5  core::fmt::num::imp::{{impl}}::fmt ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/core/src/fmt/num.rs:287
#6  0x0c0041c4 in core::fmt::run ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/core/src/fmt/mod.rs:1121
#7  core::fmt::write ()
    at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b//library/core/src/fmt/mod.rs:1089
#8  0x0c0026aa in core::fmt::Write::write_fmt<cortex_m_semihosting::hio::HStderr> (
    self=0x20000010 <cortex_m_semihosting::export::HSTDERR+4>, args=...)
    at /home/birk/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:182
#9  0x0c0025e4 in cortex_m_semihosting::export::hstderr_fmt::{{closure}} ()
    at /home/birk/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-semihosting-0.3.7/src/export.rs:49
#10 0x0c003068 in cortex_m::interrupt::free<closure-0,core::result::Result<(), ()>> (f=...)
    at /home/birk/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.7.2/src/interrupt.rs:64
#11 0x0c00251a in cortex_m_semihosting::export::hstderr_fmt (args=...)
    at /home/birk/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-semihosting-0.3.7/src/export.rs:44
#12 0x0c000474 in ex6::__cortex_m_rt_main () at /home/birk/docs/cam/p232/ex6/src/main.rs:41
#13 0x0c00031a in ex6::__cortex_m_rt_main_trampoline ()
    at /home/birk/docs/cam/p232/ex6/src/main.rs:20
```

[`cortex-m-semihosting`]: https://crates.io/crates/cortex-m-semihosting