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 <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Alastair Donaldson <afdx@google.com>
diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc
index ac4de23..3b46af5 100644
--- a/fuzzers/tint_common_fuzzer.cc
+++ b/fuzzers/tint_common_fuzzer.cc
@@ -37,19 +37,24 @@
 
 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,