From c34f08dd4589640e1a6657b69bb4473166be1fe6 Mon Sep 17 00:00:00 2001 From: Alastair Donaldson Date: Tue, 19 Oct 2021 20:58:43 +0000 Subject: [PATCH] Turn fuzzers' FatalError into a macro To enable better bug de-duplication with ClusterFuzz, FatalError has been turned into a macro. This means that frames one step further down the stack are considered by the de-duplicator. Change-Id: Ib5e4a87c9333960178fa17fafff38815293fb053 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66921 Reviewed-by: Ryan Harrison Kokoro: Kokoro Commit-Queue: Alastair Donaldson --- fuzzers/tint_common_fuzzer.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index ac4de239c0..3b46af5a3e 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -37,19 +37,24 @@ namespace fuzzers { namespace { -[[noreturn]] void FatalError(const tint::diag::List& diags, - const std::string& msg = "") { - auto printer = tint::diag::Printer::create(stderr, true); - if (!msg.empty()) { - printer->write(msg + "\n", {diag::Color::kRed, true}); - } - tint::diag::Formatter().format(diags, printer.get()); - __builtin_trap(); -} +// A macro is used to avoid FatalError creating its own stack frame. This leads +// to better de-duplication of bug reports, because ClusterFuzz only uses the +// top few stack frames for de-duplication, and a FatalError stack frame +// provides no useful information. +#define FatalError(diags, msg_string) \ + do { \ + std::string msg = msg_string; \ + auto printer = tint::diag::Printer::create(stderr, true); \ + if (!msg.empty()) { \ + printer->write(msg + "\n", {diag::Color::kRed, true}); \ + } \ + tint::diag::Formatter().format(diags, printer.get()); \ + __builtin_trap(); \ + } while (false) [[noreturn]] void TintInternalCompilerErrorReporter( const tint::diag::List& diagnostics) { - FatalError(diagnostics); + FatalError(diagnostics, ""); } bool SPIRVToolsValidationCheck(const tint::Program& program,