-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
In code like the following, the compiler misses a possible optimization: in f1
, the length of dst
is equal to the length of bytes
, yet the compiler generates a call to len_mismatch_fail
.
pub fn f1(a: &mut [u8], offset: usize, bytes: &[u8]) {
if let Some(dst) = a.get_mut(offset..offset + bytes.len()) {
dst.copy_from_slice(bytes);
}
}
The compiler knows the lengths are equal (and thus, the panic is unreachable), because the following snippet optimizes the panic away:
pub fn f2(a: &mut [u8], offset: usize, bytes: &[u8]) {
if let Some(dst) = a.get_mut(offset..offset + bytes.len()) {
assert!(dst.len() == bytes.len());
dst.copy_from_slice(bytes);
}
}
This is a regression between rustc versions 1.51 and 1.52.
TaKO8Ki and TimNN
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.