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

已关闭 适合新手
#2,364 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@AnubhavMaheshwari 已经在做这个了。

开始于 2026年11月4日。

  • #2365 来自 @nitanshnagpal —— 已合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

从 issue 中关于 Runs 为空时崩溃的说明所提到的 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
平均合并
1 天 15 小时
30 天内合并 PR
28

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/benchmark 的其他 Issue

查看 google/benchmark 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。