-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add invariant to VecDeque::pop_* that len < cap if pop successful
Similar to #114370 for VecDeque instead of Vec.
- Loading branch information
1 parent
73476d4
commit e822937
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//@ compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::collections::VecDeque; | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @noop_back( | ||
pub fn noop_back(v: &mut VecDeque<u8>) { | ||
// 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_back() { | ||
v.push_back(x); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @noop_front( | ||
pub fn noop_front(v: &mut VecDeque<u8>) { | ||
// 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_front() { | ||
v.push_front(x); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @move_byte_front_to_back( | ||
pub fn move_byte_front_to_back(v: &mut VecDeque<u8>) { | ||
// 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_front() { | ||
v.push_back(x); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @move_byte_back_to_front( | ||
pub fn move_byte_back_to_front(v: &mut VecDeque<u8>) { | ||
// 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_back() { | ||
v.push_front(x); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @push_back_byte( | ||
pub fn push_back_byte(v: &mut VecDeque<u8>) { | ||
// CHECK: call {{.*}}reserve_for_push | ||
v.push_back(3); | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @push_front_byte( | ||
pub fn push_front_byte(v: &mut VecDeque<u8>) { | ||
// CHECK: call {{.*}}reserve_for_push | ||
v.push_front(3); | ||
} |