-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function gets optimized away unless marked #[inline(never)] pub fn
#122516
Comments
@spcan Can you explain the specific problem? Is this causing trouble for you when actually producing a binary based on this library code? What cargo commands were you using, and what is the rest of your Cargo.toml like? Rust code adhering to the Rust ABI is not necessarily promising to reveal a legible public interface to arbitrary external code unless given the kind of coaxing you have, as the language does rely heavily on inlining for optimizations, and so generally when building your code, we kind of assume you want to not have public interfaces unless you... declare them public. And all that's needed, really, is declaring the relevant types and functions |
#[inline(never)] pub fn
The main problem is that the code should never be optimized away because it's operating on the input. The full gray code decoding algorithm gets removed and substituted by a single The assembly of the function that calls
Then the decimal function only contained the return statement equivalent. The |
How are you using that function when it gets optimized away? |
Removing any of |
Do you have any examples where this optimizing away means your rust code starts producing invalid values? |
The input to that |
Doing a |
I'm using nightly, so maybe it was doing something weird with a previously compiled dependency? IDK, seems to be fixed for now |
Closing this as the error does not appear to be occurring anymore. Will reopen if it reappears |
I am using this function to decode gray coded
u64
into decimal values (alsou64
).Target architecture is
thumbv8.main-none-eabihf
with RUSTFLAGS:The resulting code should be a function that transforms the input gray code into a decimal. Instead, the function gets optimized to directly return the input
u64
. The final assembly of this function is:To make the code correctly appear, the function must be marked with
#[inline(never)]
,#[no_mangle]
andextern "Rust"
. Additionally, if the function is a member of a structimpl
not matter what it always get optimized away.Correct function signature:
Correct assembly:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: