[wgslfuzz] Validate against IR fuzzer preconditions When wrapping an IR fuzzer with a WGSL fuzzer, we should validate against the IR fuzzer precondition capabilities before running the fuzzer function. We should also not consider these validation failures to be bugs, as they are only signalling an issue with AST->IR or substitute overrides, both of which have their own IR fuzzers. This change is necessary in order to validate against the preconditions as described above. Change-Id: I9aea47d6ed3ffe8ba032a890e0ee7d95a23e63b6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/244158 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/cmd/fuzz/ir/fuzz.cc b/src/tint/cmd/fuzz/ir/fuzz.cc index 56fa4f3..8d5c4a8 100644 --- a/src/tint/cmd/fuzz/ir/fuzz.cc +++ b/src/tint/cmd/fuzz/ir/fuzz.cc
@@ -64,8 +64,9 @@ #if TINT_BUILD_WGSL_READER wgsl::Register({ fuzzer.name, - [fn = fuzzer.fn](const Program& program, const fuzz::wgsl::Context& context, - Slice<const std::byte> data) { + [fn = fuzzer.fn, pre_capabilities = fuzzer.pre_capabilities]( + const Program& program, const fuzz::wgsl::Context& context, + Slice<const std::byte> data) { if (program.AST().Enables().Any(tint::wgsl::reader::IsUnsupportedByIR)) { return; } @@ -101,13 +102,18 @@ } } - if (auto val = core::ir::Validate(ir.Get(), - core::ir::Capabilities{ - core::ir::Capability::kAllowMultipleEntryPoints, - }); - val != Success) { - TINT_ICE() << val.Failure(); + // Validate the IR against the fuzzer's preconditions before running. + // We don't consider validation failure here to be an issue, as it only signals that + // there is a bug somewhere in the components run above. Those components have their own + // IR fuzzers. + if (auto val = core::ir::Validate(ir.Get(), pre_capabilities); val != Success) { + if (context.options.verbose) { + std::cout + << " Failed to validate against fuzzer capabilities before running\n"; + } + return; } + // Copy relevant options from wgsl::Context to ir::Context fuzz::ir::Context ir_context; ir_context.options.filter = context.options.filter;