Skip to content

Commit 9b892e0

Browse files
committed
[4.2][benchmark] Fix integer overflow issues on 32-bit platforms
The automatic scaling mechanism may end up with iteration counts greater than 2^31, leading to integer overflow. (cherry picked from commit f7c4832)
1 parent 255e747 commit 9b892e0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ func runBench(_ test: Test, _ c: TestConfig) -> BenchResults {
388388
// Compute the scaling factor if a fixed c.fixedNumIters is not specified.
389389
scale = c.fixedNumIters
390390
}
391+
// Make integer overflow less likely on platforms where Int is 32 bits wide.
392+
// FIXME: Switch BenchmarkInfo to use Int64 for the iteration scale, or fix
393+
// benchmarks to not let scaling get off the charts.
394+
scale = min(scale, UInt(Int.max) / 10_000)
391395

392396
// Rerun the test with the computed scale factor.
393397
if scale > 1 {

0 commit comments

Comments
 (0)