diff options
author | Alastair Donaldson <afdx@google.com> | 2020-10-17 00:58:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-17 00:58:09 +0300 |
commit | 502e98295625f5f07c7373d959e3403be5aa9de7 (patch) | |
tree | bed566778935ec09c58bbe08e2be276a2a0fdfdc /tools | |
parent | bf1a11dab70f24052023a2991ee93d4e6c8fe054 (diff) |
spirv-fuzz: Fix to TransformationInlineFunction (#3913)
This fixes a problem where TransformationInlineFunction could lead to
distinct instructions having identical unique ids. It adds a validity
check to detect this problem in general.
Fixes #3911.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/fuzz/fuzz.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/fuzz/fuzz.cpp b/tools/fuzz/fuzz.cpp index 97d3af912..5ee0fb18e 100644 --- a/tools/fuzz/fuzz.cpp +++ b/tools/fuzz/fuzz.cpp @@ -618,6 +618,34 @@ void DumpShader(spvtools::opt::IRContext* context, const char* filename) { DumpShader(binary, filename); } +// Dumps |transformations| to file |filename| in binary format. Useful for +// interactive debugging. +void DumpTransformationsBinary( + const spvtools::fuzz::protobufs::TransformationSequence& transformations, + const char* filename) { + std::ofstream transformations_file; + transformations_file.open(filename, std::ios::out | std::ios::binary); + transformations.SerializeToOstream(&transformations_file); + transformations_file.close(); +} + +// Dumps |transformations| to file |filename| in JSON format. Useful for +// interactive debugging. +void DumpTransformationsJson( + const spvtools::fuzz::protobufs::TransformationSequence& transformations, + const char* filename) { + std::string json_string; + auto json_options = google::protobuf::util::JsonOptions(); + json_options.add_whitespace = true; + auto json_generation_status = google::protobuf::util::MessageToJsonString( + transformations, &json_string, json_options); + if (json_generation_status == google::protobuf::util::Status::OK) { + std::ofstream transformations_json_file(filename); + transformations_json_file << json_string; + transformations_json_file.close(); + } +} + const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_3; int main(int argc, const char** argv) { |