Skip to content

VecDeque benchmarks have UB #104096

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
RalfJung opened this issue Nov 7, 2022 · 0 comments · Fixed by #104097
Closed

VecDeque benchmarks have UB #104096

RalfJung opened this issue Nov 7, 2022 · 0 comments · Fixed by #104097

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2022

This benchmark function has UB:

}
#[bench]
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_pop_back_100(b: &mut test::Bencher) {
let mut deq = VecDeque::<i32>::with_capacity(101);
b.iter(|| {
deq.head = 100;
deq.tail = 0;
while !deq.is_empty() {
test::black_box(deq.pop_back());

It directly accesses private fields of VecDeque to set the head and tail pointers, but doesn't initialize the element in the middle so pop_back reads uninitialized memory.

Manishearth added a commit to Manishearth/rust that referenced this issue Nov 8, 2022
run alloc benchmarks in Miri and fix UB

Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB.

And that's a good thing since there was UB here: fixes rust-lang#104096.

r? `@thomcc`
@bors bors closed this as completed in 53b6a89 Nov 9, 2022
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Feb 10, 2023
run alloc benchmarks in Miri and fix UB

Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB.

And that's a good thing since there was UB here: fixes rust-lang/rust#104096.

r? ``@thomcc``
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant