From 58d62fc271457a5d1cfdfc947c5039df6326a45e Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 10 Oct 2023 16:59:49 +1100 Subject: Don't accidentally detect the commit hash as an `fadd` instruction --- tests/codegen/target-feature-inline-closure.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/codegen') diff --git a/tests/codegen/target-feature-inline-closure.rs b/tests/codegen/target-feature-inline-closure.rs index d075706173f..54cb27242d5 100644 --- a/tests/codegen/target-feature-inline-closure.rs +++ b/tests/codegen/target-feature-inline-closure.rs @@ -31,3 +31,7 @@ unsafe fn without_avx(x: __m256) -> __m256 { }; add(x, x) } + +// Don't allow the above CHECK-NOT to accidentally match a commit hash in the +// compiler version. +// CHECK-LABEL: rustc version -- cgit 1.4.1-3-g733a5 From 0bcac8a7f25b994ddd3c2deda74dae04c677b816 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Wed, 2 Aug 2023 14:47:38 +0200 Subject: Add invariant to Vec::pop that len < cap if pop successful Fixes: https://github.com/rust-lang/rust/issues/114334 --- library/alloc/src/vec/mod.rs | 1 + tests/codegen/vec_pop_push_noop.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/codegen/vec_pop_push_noop.rs (limited to 'tests/codegen') diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 35015238e6e..3b12c1bee0b 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1956,6 +1956,7 @@ impl Vec { } else { unsafe { self.len -= 1; + core::intrinsics::assume(self.len < self.capacity()); Some(ptr::read(self.as_ptr().add(self.len()))) } } diff --git a/tests/codegen/vec_pop_push_noop.rs b/tests/codegen/vec_pop_push_noop.rs new file mode 100644 index 00000000000..8bc7b68a816 --- /dev/null +++ b/tests/codegen/vec_pop_push_noop.rs @@ -0,0 +1,24 @@ +// compile-flags: -O + +#![crate_type = "lib"] + +#[no_mangle] +// CHECK-LABEL: @noop( +pub fn noop(v: &mut Vec) { + // CHECK-NOT: reserve_for_push + // CHECK-NOT: call + // CHECK: tail call void @llvm.assume + // CHECK-NOT: reserve_for_push + // CHECK-NOT: call + // CHECK: ret + if let Some(x) = v.pop() { + v.push(x) + } +} + +#[no_mangle] +// CHECK-LABEL: @push_byte( +pub fn push_byte(v: &mut Vec) { + // CHECK: call {{.*}}reserve_for_push + v.push(3); +} -- cgit 1.4.1-3-g733a5