diff --git a/fuzzers/tint_ast_fuzzer/fuzzer.cc b/fuzzers/tint_ast_fuzzer/fuzzer.cc index 421ee4eb83..a6c31298b3 100644 --- a/fuzzers/tint_ast_fuzzer/fuzzer.cc +++ b/fuzzers/tint_ast_fuzzer/fuzzer.cc @@ -106,9 +106,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { fuzzer.EnableInspector(); fuzzer.Run(data, size); if (fuzzer.HasErrors()) { - std::cout << "Fuzzing " << target.name - << " produced an error:" << std::endl - << fuzzer.GetErrors() << std::endl; + std::cout << "Fuzzing " << target.name << " produced an error" + << std::endl; + auto printer = tint::diag::Printer::create(stderr, true); + tint::diag::Formatter{}.format(fuzzer.Diagnostics(), printer.get()); } } diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index 9e36291a5e..153cf8f917 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -217,7 +217,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { } if (!program.IsValid()) { - errors_ = diag::Formatter().format(program.Diagnostics()); + diagnostics_ = program.Diagnostics(); return 0; } @@ -234,68 +234,77 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { auto entry_points = inspector.GetEntryPoints(); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, inspector.error()); return 0; } for (auto& ep : entry_points) { auto remapped_name = inspector.GetRemappedNameForEntryPoint(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto constant_ids = inspector.GetConstantIDs(); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto uniform_bindings = inspector.GetUniformBufferResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto storage_bindings = inspector.GetStorageBufferResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto readonly_bindings = inspector.GetReadOnlyStorageBufferResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto sampler_bindings = inspector.GetSamplerResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto comparison_sampler_bindings = inspector.GetComparisonSamplerResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto sampled_texture_bindings = inspector.GetSampledTextureResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } auto multisampled_texture_bindings = inspector.GetMultisampledTextureResourceBindings(ep.name); if (inspector.has_error()) { - errors_ = inspector.error(); + diagnostics_.add_error(tint::diag::System::Inspector, + inspector.error()); return 0; } } diff --git a/fuzzers/tint_common_fuzzer.h b/fuzzers/tint_common_fuzzer.h index 3bdaf2334a..32475cccc6 100644 --- a/fuzzers/tint_common_fuzzer.h +++ b/fuzzers/tint_common_fuzzer.h @@ -110,8 +110,6 @@ class CommonFuzzer { int Run(const uint8_t* data, size_t size); - const std::string& GetErrors() const { return errors_; } - const std::vector& GetGeneratedSpirv() const { return generated_spirv_; } @@ -122,7 +120,9 @@ class CommonFuzzer { const std::string& GetGeneratedMsl() const { return generated_msl_; } - bool HasErrors() const { return !errors_.empty(); } + const tint::diag::List& Diagnostics() const { return diagnostics_; } + + bool HasErrors() const { return diagnostics_.contains_errors(); } private: InputFormat input_; @@ -130,7 +130,7 @@ class CommonFuzzer { transform::Manager* transform_manager_; transform::DataMap transform_inputs_; bool inspector_enabled_; - std::string errors_; + tint::diag::List diagnostics_; std::vector generated_spirv_; std::string generated_wgsl_; diff --git a/src/diagnostic/formatter.cc b/src/diagnostic/formatter.cc index 4b2087903c..e162c89a53 100644 --- a/src/diagnostic/formatter.cc +++ b/src/diagnostic/formatter.cc @@ -15,6 +15,7 @@ #include "src/diagnostic/formatter.h" #include +#include #include #include "src/diagnostic/diagnostic.h" @@ -96,9 +97,7 @@ struct Formatter::State { /// @param c the character to print `n` times /// @param n the number of times to print character `c` void repeat(char c, size_t n) { - while (n-- > 0) { - stream << c; - } + std::fill_n(std::ostream_iterator(stream), n, c); } private: