Closed
Description
The following code (contrived for demonstration purposes) correctly checks for and avoids a division overflow condition (i64::MIN
input coerced to i64::MIN.abs()
output) but a regression in rustc 1.56.0 (still in latest nightly and latest 1.62.0 release) causes the optimizer to no longer skip the checked division and panic branch:
pub fn checked_div_i64(dividend: i64, divisor: i64) -> Option<i64> {
if dividend > i64::min_value() && divisor != 0 {
Some(dividend / divisor)
} else {
None
}
}
Godbolt link comparing 1.55.0 to 1.62.0
@rustbot label +regression-from-stable-to-stable +A-codegen +A-llvm +I-heavy +I-slow +T-compiler
Edit:
It might be worth adding some regression tests for this because it's happened and then was fixed a few times before (e.g. introduced in 1.47.0 and fixed in 1.48.0).
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to performance of generated code.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.