Skip to content

Non-inlined recursive function produced different value when optimised #98192

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

Closed
mayanksharma3 opened this issue Jun 17, 2022 · 2 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@mayanksharma3
Copy link

mayanksharma3 commented Jun 17, 2022

I'm in the (fairly early) process of building a Rust fuzzer (here) and whilst running it, it came across this discrepancy between optimization levels on the latest released Rust version (1.61.0). It generated a huge file, but this is a reduced code snippet exhibiting the same behaviour.

I tried this code:

#[inline(never)]
fn fun27(var1374: &Box<i32>) -> ! {
    fun27(var1374)
}

fn main() {
    let var1040 = Box::from(1745183449i32);
    fun27(&var1040);
}

I expected to see this happen: Run forever (or stack overflow)

Instead, this happened: Crashes with a trace trap (shown below) while running, when run on any optimization level. Running on optimization level 0 does throw a stack overflow error (as expected)

Some changes that would stop the runtime error:

  • Removing the argument from fun27
  • Changing the argument from a heap value to something on the stack (like a plain i32 for example)
  • Removing the #[inline(never)] from fun27

Also, changing the return type of fun27 from ! to () doesn't throw a compilation error (should it?) but when run, the program gracefully exits with a 0 error code.

Meta

rustc --version --verbose:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: aarch64-apple-darwin
release: 1.61.0
LLVM version: 14.0.0
Backtrace

[1]    61641 trace trap  ./test

@mayanksharma3 mayanksharma3 added the C-bug Category: This is a bug. label Jun 17, 2022
@nikic
Copy link
Contributor

nikic commented Jun 17, 2022

This is likely a duplicate of #97428. Does it work on nightly?

@mayanksharma3
Copy link
Author

Ah yes, it does work on nightly. Thank you for linking me to the original issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants