-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Description
This is an interesting codegen bug (Note that this reproduces in a special case setting and in many regular contexts, this problem does not exist).
Expected behavior:
This code should just be a pointer comparison (ptr == end
leads to None
being returned)
use std::slice::Iter;
pub fn is_empty_1(xs: Iter<f32>) -> bool {
{xs}.next().is_none()
}
Actual behavior:
It compiles to the equivalent of ptr == end || ptr.is_null()
.
Playground link. Use release mode.
version: rustc 1.15.0-nightly (0bd2ce6 2016-11-19)
Additional notes:
This version has the expected codegen, without the null check.
pub fn is_empty_2(xs: Iter<f32>) -> bool {
xs.map(|&x| x).next().is_none()
}
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.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.