-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 Vec::pop that len < cap if pop successful
Fixes: #114334
- Loading branch information
Showing
2 changed files
with
25 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,24 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @noop( | ||
pub fn noop(v: &mut Vec<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() { | ||
v.push(x) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
// CHECK-LABEL: @push_byte( | ||
pub fn push_byte(v: &mut Vec<u8>) { | ||
// CHECK: call {{.*}}reserve_for_push | ||
v.push(3); | ||
} |