Skip to content

Commit cd79ff2

Browse files
committed
Revert "avoid phi node for pointers flowing into Vec appends #130998"
This reverts PR <#130998> because the added test seems to be flaky / non-deterministic, and has been failing in unrelated PRs during merge CI.
1 parent b6fdaf2 commit cd79ff2

4 files changed

Lines changed: 5 additions & 50 deletions

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
517517
to_add.push(llvm::CreateAllocKindAttr(cx.llcx, AllocKindFlags::Free));
518518
// applies to argument place instead of function place
519519
let allocated_pointer = AttributeKind::AllocatedPointer.create_attr(cx.llcx);
520-
let attrs: &[_] = if llvm_util::get_version() >= (21, 0, 0) {
521-
// "Does not capture provenance" means "if the function call stashes the pointer somewhere,
522-
// accessing that pointer after the function returns is UB". That is definitely the case here since
523-
// freeing will destroy the provenance.
524-
let captures_addr = AttributeKind::CapturesAddress.create_attr(cx.llcx);
525-
&[allocated_pointer, captures_addr]
526-
} else {
527-
&[allocated_pointer]
528-
};
529-
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), attrs);
520+
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), &[allocated_pointer]);
530521
}
531522
if let Some(align) = codegen_fn_attrs.alignment {
532523
llvm::set_alignment(llfn, align);

library/alloc/src/slice.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,9 @@ impl<T> [T] {
448448
// SAFETY:
449449
// allocated above with the capacity of `s`, and initialize to `s.len()` in
450450
// ptr::copy_to_non_overlapping below.
451-
if s.len() > 0 {
452-
unsafe {
453-
s.as_ptr().copy_to_nonoverlapping(v.as_mut_ptr(), s.len());
454-
v.set_len(s.len());
455-
}
451+
unsafe {
452+
s.as_ptr().copy_to_nonoverlapping(v.as_mut_ptr(), s.len());
453+
v.set_len(s.len());
456454
}
457455
v
458456
}

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,11 +2818,7 @@ impl<T, A: Allocator> Vec<T, A> {
28182818
let count = other.len();
28192819
self.reserve(count);
28202820
let len = self.len();
2821-
if count > 0 {
2822-
unsafe {
2823-
ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count)
2824-
};
2825-
}
2821+
unsafe { ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count) };
28262822
self.len += count;
28272823
}
28282824

tests/codegen-llvm/lib-optimizations/append-elements.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)