Skip to content

Commit fc0d3ae

Browse files
committed
workaround missed optimization in llvm18
1 parent bfe762e commit fc0d3ae

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

library/alloc/src/vec/into_iter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
224224
let exact = if T::IS_ZST {
225225
self.end.addr().wrapping_sub(self.ptr.as_ptr().addr())
226226
} else {
227-
unsafe { non_null!(self.end, T).sub_ptr(self.ptr) }
227+
// FIXME(#121239): this should use sub_ptr but llvm == 18 doesn't optimize as it should
228+
unsafe { non_null!(self.end, T).offset_from(self.ptr) as usize }
228229
};
229230
(exact, Some(exact))
230231
}

tests/codegen/vec-iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn vec_iter_len_nonnull(it: &vec::IntoIter<u8>) -> usize {
1313
// CHECK: load ptr
1414
// CHECK-SAME: !nonnull
1515
// CHECK-SAME: !noundef
16-
// CHECK: sub nuw
16+
// CHECK: sub
1717
// CHECK: ret
1818
it.len()
1919
}

0 commit comments

Comments
 (0)