[BUG] Segfault when all runs of a Complexity() benchmark are skipped

クローズ 初心者向け
#2,364 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@AnubhavMaheshwari がすでに取り組んでいます。

2026年11月4日 から。

  • #2365 @nitanshnagpal による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp

調査の方向性

Runs が空の場合のクラッシュについて issue の説明で挙げられている BenchmarkRunner::DoOneRepetition と RunBenchmarks から始めます。提供されたプログラムで Complexity() とスキップされた実行を使って再現し、その後、回帰テストを追加する適切な場所を見つけるためにベンチマークテストを調べます。すべてのスキップされた実行が報告され、後続のベンチマークも実行され、BigO または RMS の行が表示されなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug
If every run of a benchmark family using Complexity() is skipped, with either SkipWithMessage or SkipWithError, RunSpecifiedBenchmarks() segfaults. The remaining results are lost, and any later benchmarks don't run. The same benchmark without Complexity() exits normally.

System
- OS: macOS 26.6.2 (arm64)
- Compiler and version: Apple clang 21.0.0 (clang-2100.3.34.2)

To reproduce

  1. Sync to commit e508a65 (main) and build in Release mode.
  2. Compile and run this program, linked against the library:
#include <benchmark/benchmark.h>

static void BM_Sort(benchmark::State& state) {
  state.SkipWithMessage("not supported on this machine");
  for (auto _ : state) {
  }
  state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_Sort)->Range(8, 64)->Complexity();

BENCHMARK_MAIN();
  1. It prints the BM_Sort/8 row, then exits with a segfault (exit code 139) before printing BM_Sort/64.

Expected behavior
Both runs are reported as skipped, no BigO or RMS rows are printed, and the program exits normally.

Additional context
BenchmarkRunner::DoOneRepetition counts skipped runs in num_runs_done, but only adds non-skipped runs to Runs. When every run in a family is skipped, Runs is empty once the family finishes, and RunBenchmarks still calls reports_for_family->Runs.front().family_index. UBSan reports a reference binding to a null pointer there.

The same code is in v1.10.0, though I only ran the reproducer on main.

I'd like to work on this. I have a fix that takes the family index from the benchmark instance, plus a regression test, and can open a PR.

主要言語
C++
スター
10.5k
フォーク
1.8k
平均マージ
2日 2時間
マージ済み PR(30日)
30

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/benchmark のほかの issue

google/benchmark の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。