diff --git a/fuzzers/tint_ast_clone_fuzzer.cc b/fuzzers/tint_ast_clone_fuzzer.cc index 64100bfde4..f773aa4865 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(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 a1ed3894c9..9cb7e6717d 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(InputFormat input, OutputFormat output) CommonFuzzer::~CommonFuzzer() = default; int CommonFuzzer::Run(const uint8_t* data, size_t size) { + tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter); + Program program; #if TINT_BUILD_WGSL_READER