Add checking for ICEs in fuzzers

BUG=tint:668

Change-Id: I6b0bf79873b01140b1e87ea60abeb623b031af23
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45942
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/fuzzers/tint_ast_clone_fuzzer.cc b/fuzzers/tint_ast_clone_fuzzer.cc
index 64100bf..f773aa4 100644
--- a/fuzzers/tint_ast_clone_fuzzer.cc
+++ b/fuzzers/tint_ast_clone_fuzzer.cc
@@ -41,9 +41,18 @@
     }                                                  \
   } while (false)
 
+[[noreturn]] void TintInternalCompilerErrorReporter(
+    const tint::diag::List& diagnostics) {
+  auto printer = tint::diag::Printer::create(stderr, true);
+  tint::diag::Formatter{}.format(diagnostics, printer.get());
+  __builtin_trap();
+}
+
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   std::string str(reinterpret_cast<const char*>(data), size);
 
+  tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
+
   tint::Source::File file("test.wgsl", str);
 
   // Parse the wgsl, create the src program
diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc
index a1ed389..9cb7e67 100644
--- a/fuzzers/tint_common_fuzzer.cc
+++ b/fuzzers/tint_common_fuzzer.cc
@@ -26,6 +26,13 @@
 namespace tint {
 namespace fuzzers {
 
+[[noreturn]] void TintInternalCompilerErrorReporter(
+    const tint::diag::List& diagnostics) {
+  auto printer = tint::diag::Printer::create(stderr, true);
+  tint::diag::Formatter{}.format(diagnostics, printer.get());
+  __builtin_trap();
+}
+
 CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
     : input_(input),
       output_(output),
@@ -35,6 +42,8 @@
 CommonFuzzer::~CommonFuzzer() = default;
 
 int CommonFuzzer::Run(const uint8_t* data, size_t size) {
+  tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
+
   Program program;
 
 #if TINT_BUILD_WGSL_READER