Skip to content

Commit f34cf2c

Browse files
committed
Fix #2
1 parent af238be commit f34cf2c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

rust/arith-overflow-buglist.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,34 @@ legitimate bugs. (We begin with such a case.)
144144
this writing. Instead we put in a workaround:
145145

146146
https://github.com/rust-lang/rust/pull/23489
147+
148+
### Overflow in benchmark iteration increment
149+
150+
The implementation of `#[bench]` was not prepared to deal
151+
with an overflow in the iteration count.
152+
153+
The arithmetic overflow checking forced that to fail on a
154+
benchmark like
155+
156+
```rust
157+
#[bench]
158+
fn foo(b: &mut test::Bencher) {}
159+
```
160+
161+
rather than return bogus results.
162+
163+
The iteration count is stored in a `u64`, so overflow sounds
164+
unlikely -- even though `n` is being multiplied by 2 on every
165+
increment, so it sounds plausible that we could get to very large
166+
numbers indeed, the fact that we have to actually *run* that many
167+
iterations is what gives me pause.
168+
169+
At this point I am assuming that the compiler is doing something
170+
to optimize away the looping when the benchmark code is empty:
171+
keep in mind that the `#[bench]` code above is not calling the
172+
`black_box` method of `b`. Maybe we should be requring that?
173+
174+
Anyway, the chosen fix was to just return the results so far before
175+
hitting the overflow:
176+
177+
https://github.com/rust-lang/rust/pull/23127

0 commit comments

Comments
 (0)