Description
The following code compiles and works correctly on x86_64
. However, the same code when compiled for aarch64
with opt-level = "s"
does not work.
https://github.com/berkus/mre-write_to
The culprit is the function show() in write_to.rs:44
(one-page version here -- this however is not enough for reproduction)
When used from the same module it correctly generates a &str from buffer slice. When used from another module the resulting str is "" (empty).
The original code location, where bug is easily reproducible by running makers test
is here
(Disclaimer: custom target file, should match LLVM layout for aarch64 however; custom linker script for OS kernel)
There, marking the function with #[inline]
makes it work correctly at call sites other than the same module (for example, from here). Removing inline modifier makes it produce "" (empty) strs. It still works correctly from within the same module (e.g. local unit tests pass).
Changing opt-level
from "s" to 2 or 3 also fixes the issue.
Replacing from_utf8_unchecked
with from_utf8().unwrap()
causes different behavior. Now opt-levels 2 and "s" produce empty strs while opt-level 3 works as intended.
It looks like code generation bug to me.
$ rustc --version
rustc 1.42.0-nightly (cd1ef39 2020-01-31)
Ready to provide more information or test possible fixes.