Closed
Description
The following code tries to parse a decimal integer followed by a newline. For some reason the compiler assumes that the parsed number will never be one. opt-level has to be 2, 3, s or z
fn main() {
let buffer = [49u8, 10];
let mut a : u64 = 0;
'read: loop {
for c in &buffer {
match c {
48..=57 => {
a*= 10;
a+= *c as u64 - 48;
}
10 => {
break 'read;
}
_ => {
unsafe { std::hint::unreachable_unchecked() };
}
}
}
}
if a == 1 {
println!("What did you expect?");
}
}
I expected to see this happen: When running the program it prints "What did you expect?"
Instead, this happened: The program doesn't print anything, just exits
Meta
rustc --version --verbose
:
rustc 1.43.0-nightly (823ff8cf1 2020-03-07)
binary: rustc
commit-hash: 823ff8cf1397a5772b1f6954b60576202bf91836
commit-date: 2020-03-07
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
On godbolt the issue seems to go back to version 1.38
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessBugs identified for the LLVM ICE-breaker groupHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.