From 0f5c26d5fd404bf2626748c0c19a05d5be6c77ab Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 25 Mar 2021 11:40:07 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Ben Clayton --- fuzzers/tint_ast_clone_fuzzer.cc | 9 +++++++++ fuzzers/tint_common_fuzzer.cc | 9 +++++++++ 2 files changed, 18 insertions(+) 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