[tint][fuzz] Remove old fuzzers
All WGSL fuzzers have been reimplemented with the new `foo_fuzz.cc` framework.
SPIR-V fuzzers and mutation are removed for now.
Fixed: tint:2223
Change-Id: I4e4eebc1521c6dcdf59725f6d1b11c1e00cd1ec6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/186049
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index a8ba5d2..f01ff5e 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -293,10 +293,7 @@
testonly = true
deps = []
if (tint_has_fuzzers) {
- deps += [
- "${tint_src_dir}/cmd/fuzz/wgsl",
- "${tint_src_dir}/fuzzers",
- ]
+ deps += [ "${tint_src_dir}/cmd/fuzz/wgsl" ]
}
}
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index da7fda4..235349c 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -631,7 +631,6 @@
set(TINT_BUILD_TESTS FALSE)
set(TINT_BUILD_BENCHMARKS FALSE)
include("BUILD.cmake")
- add_subdirectory(fuzzers)
# Restore the build flags
set(TINT_BUILD_CMD_TOOLS ${SAVE_TINT_BUILD_CMD_TOOLS})
@@ -683,29 +682,22 @@
################################################################################
-# Additional fuzzer tests
+# Unit tests
################################################################################
if(TINT_BUILD_TESTS)
- if(${TINT_BUILD_FUZZERS})
- target_sources(tint_cmd_test_test_cmd PRIVATE
- fuzzers/mersenne_twister_engine.cc
- fuzzers/mersenne_twister_engine.h
- fuzzers/random_generator.cc
- fuzzers/random_generator.h
- fuzzers/random_generator_engine.cc
- fuzzers/random_generator_engine.h
- fuzzers/random_generator_test.cc
- )
- endif()
-
add_test(NAME tint_unittests COMMAND tint_cmd_test_test_cmd)
endif(TINT_BUILD_TESTS)
+
################################################################################
# Target aliases
################################################################################
add_library(libtint ALIAS tint_api)
+
+################################################################################
+# Install rules
+################################################################################
if (TINT_ENABLE_INSTALL)
# We need to recurse all folders and include all headers because tint.h includes most headers from src/tint
file(GLOB TINT_HEADERS "${DAWN_INCLUDE_DIR}/tint/*.h")
diff --git a/src/tint/fuzzers/BUILD.gn b/src/tint/fuzzers/BUILD.gn
deleted file mode 100644
index 3809954..0000000
--- a/src/tint/fuzzers/BUILD.gn
+++ /dev/null
@@ -1,369 +0,0 @@
-# Copyright 2022 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import("//build_overrides/build.gni")
-import("../../../scripts/tint_overrides_with_defaults.gni")
-
-# Fuzzers - Libfuzzer based fuzzing targets for Chromium
-# To run the fuzzers outside of Chromium, use the CMake based builds.
-
-if (tint_has_fuzzers) {
- import("//testing/libfuzzer/fuzzer_test.gni")
- import("../../../scripts/dawn_overrides_with_defaults.gni")
-
- fuzzer_corpus_wgsl_dir = "${target_gen_dir}/fuzzer_corpus_wgsl"
- fuzzer_corpus_wgsl_stamp = "${fuzzer_corpus_wgsl_dir}.stamp"
- action("tint_generate_wgsl_corpus") {
- script = "generate_wgsl_corpus.py"
- sources = [ "generate_wgsl_corpus.py" ]
- args = [
- "--stamp=" + rebase_path(fuzzer_corpus_wgsl_stamp, root_build_dir),
- rebase_path("${tint_root_dir}/test", root_build_dir),
- rebase_path(fuzzer_corpus_wgsl_dir, root_build_dir),
- ]
- outputs = [ fuzzer_corpus_wgsl_stamp ]
- }
-
- tint_fuzzer_common_libfuzzer_options = [
- "only_ascii=1",
- "max_len=10000",
- ]
-
- if (build_with_chromium) {
- tint_ast_fuzzer_common_libfuzzer_options =
- tint_fuzzer_common_libfuzzer_options + [
- "cross_over=0",
- "mutate_depth=1",
- "tint_enable_all_mutations=false",
- "tint_mutation_batch_size=5",
- ]
- }
-
- tint_regex_fuzzer_common_libfuzzer_options =
- tint_fuzzer_common_libfuzzer_options + [
- "cross_over=0",
- "mutate_depth=1",
- ]
-
- # fuzzer_test doesn't have configs members, so need to define them in an empty
- # source_set.
-
- source_set("tint_fuzzer_common_src") {
- public_configs = [
- "${tint_src_dir}:tint_config",
- "${tint_src_dir}:tint_common_config",
- ]
-
- public_deps = [
- "${tint_spirv_tools_dir}/:spvtools_val",
- "${tint_src_dir}/api",
- "${tint_src_dir}/api/common",
- "${tint_src_dir}/lang/core/type",
- "${tint_src_dir}/lang/glsl/writer",
- "${tint_src_dir}/lang/hlsl/writer",
- "${tint_src_dir}/lang/hlsl/writer/helpers",
- "${tint_src_dir}/lang/msl/writer",
- "${tint_src_dir}/lang/msl/writer/helpers",
- "${tint_src_dir}/lang/spirv/writer",
- "${tint_src_dir}/lang/spirv/writer/helpers",
- "${tint_src_dir}/lang/wgsl/ast",
- "${tint_src_dir}/lang/wgsl/ast/transform",
- "${tint_src_dir}/lang/wgsl/helpers",
- "${tint_src_dir}/lang/wgsl/inspector",
- "${tint_src_dir}/lang/wgsl/program",
- "${tint_src_dir}/lang/wgsl/reader",
- "${tint_src_dir}/lang/wgsl/resolver",
- "${tint_src_dir}/lang/wgsl/sem",
- "${tint_src_dir}/lang/wgsl/writer",
- "${tint_src_dir}/utils/diagnostic",
- "${tint_src_dir}/utils/math",
- "${tint_src_dir}/utils/text",
- ]
-
- sources = [
- "data_builder.h",
- "mersenne_twister_engine.cc",
- "mersenne_twister_engine.h",
- "random_generator.cc",
- "random_generator.h",
- "random_generator_engine.cc",
- "random_generator_engine.h",
- "shuffle_transform.cc",
- "shuffle_transform.h",
- "tint_common_fuzzer.cc",
- "tint_common_fuzzer.h",
- "tint_reader_writer_fuzzer.h",
- "transform_builder.h",
- ]
-
- if (is_mac) {
- sources += [ "//testing/libfuzzer/libfuzzer_exports.h" ]
- }
- }
-
- source_set("tint_fuzzer_common_with_init_src") {
- public_deps = [ ":tint_fuzzer_common_src" ]
-
- sources = [
- "cli.cc",
- "cli.h",
- "fuzzer_init.cc",
- "fuzzer_init.h",
- ]
- }
-
- if (tint_build_wgsl_reader && tint_build_wgsl_writer) {
- if (build_with_chromium) {
- fuzzer_test("tint_ast_wgsl_writer_fuzzer") {
- sources = [ "tint_ast_fuzzer/tint_ast_wgsl_writer_fuzzer.cc" ]
- deps = [ "tint_ast_fuzzer:tint_ast_fuzzer" ]
- libfuzzer_options = tint_ast_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- fuzzer_test("tint_regex_wgsl_writer_fuzzer") {
- sources = [ "tint_regex_fuzzer/tint_regex_wgsl_writer_fuzzer.cc" ]
- deps = [ "tint_regex_fuzzer:tint_regex_fuzzer" ]
- libfuzzer_options = tint_regex_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- if (tint_build_wgsl_reader && tint_build_spv_writer) {
- fuzzer_test("tint_all_transforms_fuzzer") {
- sources = [ "tint_all_transforms_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- if (build_with_chromium) {
- fuzzer_test("tint_ast_spv_writer_fuzzer") {
- sources = [ "tint_ast_fuzzer/tint_ast_spv_writer_fuzzer.cc" ]
- deps = [ "tint_ast_fuzzer:tint_ast_fuzzer" ]
- libfuzzer_options = tint_ast_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- fuzzer_test("tint_binding_remapper_fuzzer") {
- sources = [ "tint_binding_remapper_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- # Disable this fuzzer on windows + ASAN. See crbug.com/1357188.
- if (!(is_win && is_asan)) {
- fuzzer_test("tint_concurrency_fuzzer") {
- sources = [ "tint_concurrency_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- fuzzer_test("tint_first_index_offset_fuzzer") {
- sources = [ "tint_first_index_offset_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_regex_spv_writer_fuzzer") {
- sources = [ "tint_regex_fuzzer/tint_regex_spv_writer_fuzzer.cc" ]
- deps = [ "tint_regex_fuzzer:tint_regex_fuzzer" ]
- libfuzzer_options = tint_regex_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_renamer_fuzzer") {
- sources = [ "tint_renamer_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_robustness_fuzzer") {
- sources = [ "tint_robustness_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_single_entry_point_fuzzer") {
- sources = [ "tint_single_entry_point_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_vertex_pulling_fuzzer") {
- sources = [ "tint_vertex_pulling_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_wgsl_reader_spv_writer_fuzzer") {
- sources = [ "tint_wgsl_reader_spv_writer_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
- if (build_with_chromium) {
- fuzzer_test("tint_ast_hlsl_writer_fuzzer") {
- sources = [ "tint_ast_fuzzer/tint_ast_hlsl_writer_fuzzer.cc" ]
- deps = [ "tint_ast_fuzzer:tint_ast_fuzzer" ]
- libfuzzer_options = tint_ast_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- fuzzer_test("tint_regex_hlsl_writer_fuzzer") {
- sources = [ "tint_regex_fuzzer/tint_regex_hlsl_writer_fuzzer.cc" ]
- deps = [ "tint_regex_fuzzer:tint_regex_fuzzer" ]
- libfuzzer_options = tint_regex_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_wgsl_reader_hlsl_writer_fuzzer") {
- sources = [ "tint_wgsl_reader_hlsl_writer_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- if (tint_build_wgsl_reader && tint_build_msl_writer) {
- if (build_with_chromium) {
- fuzzer_test("tint_ast_msl_writer_fuzzer") {
- sources = [ "tint_ast_fuzzer/tint_ast_msl_writer_fuzzer.cc" ]
- deps = [ "tint_ast_fuzzer:tint_ast_fuzzer" ]
- libfuzzer_options = tint_ast_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- fuzzer_test("tint_regex_msl_writer_fuzzer") {
- sources = [ "tint_regex_fuzzer/tint_regex_msl_writer_fuzzer.cc" ]
- deps = [ "tint_regex_fuzzer:tint_regex_fuzzer" ]
- libfuzzer_options = tint_regex_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
-
- fuzzer_test("tint_wgsl_reader_msl_writer_fuzzer") {
- sources = [ "tint_wgsl_reader_msl_writer_fuzzer.cc" ]
- deps = [ ":tint_fuzzer_common_with_init_src" ]
- dict = "dictionary.txt"
- libfuzzer_options = tint_fuzzer_common_libfuzzer_options
- seed_corpus = fuzzer_corpus_wgsl_dir
- seed_corpus_deps = [ ":tint_generate_wgsl_corpus" ]
- }
- }
-
- group("fuzzers") {
- testonly = true
- deps = []
-
- if (tint_build_wgsl_reader && tint_build_wgsl_writer) {
- deps += [ ":tint_regex_wgsl_writer_fuzzer" ]
- if (build_with_chromium) {
- deps += [ ":tint_ast_wgsl_writer_fuzzer" ]
- }
- }
- if (tint_build_wgsl_reader && tint_build_spv_writer) {
- deps += [
- ":tint_all_transforms_fuzzer",
- ":tint_binding_remapper_fuzzer",
- ":tint_first_index_offset_fuzzer",
- ":tint_regex_spv_writer_fuzzer",
- ":tint_renamer_fuzzer",
- ":tint_robustness_fuzzer",
- ":tint_single_entry_point_fuzzer",
- ":tint_vertex_pulling_fuzzer",
- ":tint_wgsl_reader_spv_writer_fuzzer",
- ]
- if (build_with_chromium) {
- deps += [ ":tint_ast_spv_writer_fuzzer" ]
- }
- }
- if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
- deps += [
- ":tint_regex_hlsl_writer_fuzzer",
- ":tint_wgsl_reader_hlsl_writer_fuzzer",
- ]
- if (build_with_chromium) {
- deps += [ ":tint_ast_hlsl_writer_fuzzer" ]
- }
- }
- if (tint_build_wgsl_reader && tint_build_msl_writer) {
- deps += [
- ":tint_regex_msl_writer_fuzzer",
- ":tint_wgsl_reader_msl_writer_fuzzer",
- ]
- if (build_with_chromium) {
- deps += [ ":tint_ast_msl_writer_fuzzer" ]
- }
- }
- }
-} else {
- group("fuzzers") {
- }
-}
diff --git a/src/tint/fuzzers/CMakeLists.txt b/src/tint/fuzzers/CMakeLists.txt
deleted file mode 100644
index 134f6ca..0000000
--- a/src/tint/fuzzers/CMakeLists.txt
+++ /dev/null
@@ -1,102 +0,0 @@
-# Copyright 2020 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-function(add_tint_fuzzer NAME)
- add_executable(${NAME}
- ${NAME}.cc
- cli.cc
- cli.h
- data_builder.h
- fuzzer_init.cc
- fuzzer_init.h
- mersenne_twister_engine.cc
- mersenne_twister_engine.h
- random_generator.cc
- random_generator.h
- random_generator_engine.cc
- random_generator_engine.h
- shuffle_transform.cc
- shuffle_transform.h
- tint_common_fuzzer.cc
- tint_common_fuzzer.h
- tint_reader_writer_fuzzer.h
- transform_builder.h
- )
- tint_fuzzer_compile_options(${NAME})
- if(TINT_BUILD_SPV_READER OR TINT_BUILD_SPV_WRITER)
- tint_spvheaders_compile_options(${NAME})
- tint_spvtools_compile_options(${NAME})
- endif()
- target_link_libraries(${NAME} PRIVATE tint_lang_hlsl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE tint_lang_msl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE tint_lang_spirv_writer_helpers)
- target_compile_options(${NAME} PRIVATE -Wno-missing-prototypes)
-endfunction()
-
-if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
- add_tint_fuzzer(tint_all_transforms_fuzzer)
- add_tint_fuzzer(tint_binding_remapper_fuzzer)
- add_tint_fuzzer(tint_concurrency_fuzzer)
- add_tint_fuzzer(tint_first_index_offset_fuzzer)
- add_tint_fuzzer(tint_renamer_fuzzer)
- add_tint_fuzzer(tint_robustness_fuzzer)
- add_tint_fuzzer(tint_single_entry_point_fuzzer)
- add_tint_fuzzer(tint_vertex_pulling_fuzzer)
- add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_HLSL_WRITER})
- add_tint_fuzzer(tint_wgsl_reader_hlsl_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_MSL_WRITER})
- add_tint_fuzzer(tint_wgsl_reader_msl_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_WGSL_WRITER})
- add_tint_fuzzer(tint_spv_reader_wgsl_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_SPV_WRITER})
- add_tint_fuzzer(tint_spv_reader_spv_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_HLSL_WRITER})
- add_tint_fuzzer(tint_spv_reader_hlsl_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_MSL_WRITER})
- add_tint_fuzzer(tint_spv_reader_msl_writer_fuzzer)
-endif()
-
-if (${TINT_BUILD_AST_FUZZER})
- add_subdirectory(tint_ast_fuzzer)
-endif()
-
-if (${TINT_BUILD_REGEX_FUZZER})
- add_subdirectory(tint_regex_fuzzer)
-endif()
diff --git a/src/tint/fuzzers/cli.cc b/src/tint/fuzzers/cli.cc
deleted file mode 100644
index 101ec27..0000000
--- a/src/tint/fuzzers/cli.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/cli.h"
-
-#include <cstring>
-#include <iostream>
-#include <limits>
-#include <sstream>
-#include <string>
-#include <utility>
-
-namespace tint::fuzzers {
-namespace {
-
-const char* const kHelpMessage = R"(
-This is a fuzzer for the Tint compiler that works by mutating the AST.
-
-Below is a list of all supported parameters for this fuzzer. You may want to
-run it with -help=1 to check out libfuzzer parameters.
-
- -tint_dump_input=
- If `true`, the fuzzer will dump input data to a file with
- name tint_input_<hash>.spv/wgsl, where the hash is the hash
- of the input data.
-
- -tint_help
- Show this message. Note that there is also a -help=1
- parameter that will display libfuzzer's help message.
-
- -tint_enforce_validity=
- If `true`, the fuzzer will enforce that Tint does not
- generate invalid shaders. Currently `false` by default
- since options provided by the fuzzer are not guaranteed
- to be correct.
- See https://bugs.chromium.org/p/tint/issues/detail?id=1356
-)";
-
-[[noreturn]] void InvalidParam(const std::string& param) {
- std::cout << "Invalid value for " << param << std::endl;
- std::cout << kHelpMessage << std::endl;
- exit(1);
-}
-
-bool ParseBool(const std::string& value, bool* out) {
- if (value.compare("true") == 0) {
- *out = true;
- } else if (value.compare("false") == 0) {
- *out = false;
- } else {
- return false;
- }
- return true;
-}
-
-} // namespace
-
-CliParams ParseCliParams(int* argc, char** argv) {
- CliParams cli_params;
- auto help = false;
-
- for (int i = *argc - 1; i > 0; --i) {
- std::string param(argv[i]);
- auto recognized_parameter = true;
-
- if (std::string::npos != param.find("-tint_dump_input=")) {
- if (!ParseBool(param.substr(std::string("-tint_dump_input=").length()),
- &cli_params.dump_input)) {
- InvalidParam(param);
- }
- } else if (std::string::npos != param.find("-tint_help")) {
- help = true;
- } else if (std::string::npos != param.find("-tint_enforce_validity=")) {
- if (!ParseBool(param.substr(std::string("-tint_enforce_validity=").length()),
- &cli_params.enforce_validity)) {
- InvalidParam(param);
- }
- } else {
- recognized_parameter = false;
- }
-
- if (recognized_parameter) {
- // Remove the recognized parameter from the list of all parameters by
- // swapping it with the last one. This will suppress warnings in the
- // libFuzzer about unrecognized parameters. By default, libFuzzer thinks
- // that all user-defined parameters start with two dashes. However, we are
- // forced to use a single one to make the fuzzer compatible with the
- // ClusterFuzz.
- std::swap(argv[i], argv[*argc - 1]);
- *argc -= 1;
- }
- }
-
- if (help) {
- std::cout << kHelpMessage << std::endl;
- exit(0);
- }
-
- return cli_params;
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/cli.h b/src/tint/fuzzers/cli.h
deleted file mode 100644
index f8aea36..0000000
--- a/src/tint/fuzzers/cli.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_CLI_H_
-#define SRC_TINT_FUZZERS_CLI_H_
-
-#include <cstdint>
-
-namespace tint::fuzzers {
-
-/// CLI parameters accepted by the fuzzer. Type -tint_help in the CLI to see the
-/// help message
-struct CliParams {
- /// Log contents of input shader
- bool dump_input = false;
- /// Throw error if shader becomes invalid during run
- bool enforce_validity = false;
-};
-
-/// @brief Parses CLI parameters.
-///
-/// This function will exit the process with non-zero return code if some
-/// parameters are invalid. This function will remove recognized parameters from
-/// `argv` and adjust `argc` accordingly.
-///
-/// @param argc - the total number of parameters.
-/// @param argv - array of all CLI parameters.
-/// @return parsed parameters.
-CliParams ParseCliParams(int* argc, char** argv);
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_CLI_H_
diff --git a/src/tint/fuzzers/data_builder.h b/src/tint/fuzzers/data_builder.h
deleted file mode 100644
index 41138b7..0000000
--- a/src/tint/fuzzers/data_builder.h
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_DATA_BUILDER_H_
-#define SRC_TINT_FUZZERS_DATA_BUILDER_H_
-
-#include <cassert>
-#include <functional>
-#include <optional>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "src/tint/fuzzers/random_generator.h"
-
-namespace tint::fuzzers {
-
-/// Builder for generic pseudo-random data
-class DataBuilder {
- public:
- /// @brief Initializes the internal engine using a seed value
- /// @param seed - seed value passed to engine
- explicit DataBuilder(uint64_t seed) : generator_(seed) {}
-
- /// @brief Initializes the internal engine using seed data
- /// @param data - data fuzzer to calculate seed from
- /// @param size - size of data buffer
- explicit DataBuilder(const uint8_t* data, size_t size)
- : generator_(RandomGenerator::CalculateSeed(data, size)) {
- assert(data != nullptr && "|data| must be !nullptr");
- }
-
- /// Destructor
- ~DataBuilder() = default;
-
- /// Move Constructor
- DataBuilder(DataBuilder&&) = default;
-
- /// Generate pseudo-random data of a specific type
- /// @tparam T - type of data to produce
- /// @returns pseudo-random data of type T
- template <typename T>
- T build() {
- return BuildImpl<T>::impl(this);
- }
-
- /// Generate pseudo-random data of a specific type in a vector
- /// @tparam T - data type held vector
- /// @returns pseudo-random data of type std::vector<T>
- template <typename T>
- std::vector<T> vector() {
- auto count = build<uint8_t>();
- std::vector<T> out(count);
- for (uint8_t i = 0; i < count; i++) {
- out[i] = build<T>();
- }
- return out;
- }
-
- /// Generate complex pseudo-random data of a specific type in a vector
- /// @tparam T - data type held vector
- /// @tparam Callback - callback that takes in a DataBuilder* and returns a T
- /// @param generate - callback for generating each instance of T
- /// @returns pseudo-random data of type std::vector<T>
- template <typename T, typename Callback>
- std::vector<T> vector(Callback generate) {
- auto count = build<uint8_t>();
- std::vector<T> out(count);
- for (size_t i = 0; i < count; i++) {
- out[i] = generate(this);
- }
- return out;
- }
-
- /// Generate an pseudo-random entry to a enum class.
- /// Assumes enum is tightly packed starting at 0.
- /// @tparam T - type of enum class
- /// @param count - number of entries in enum class
- /// @returns a random enum class entry
- template <typename T>
- T enum_class(uint32_t count) {
- return static_cast<T>(generator_.Get4Bytes() % count);
- }
-
- private:
- RandomGenerator generator_;
-
- // Disallow copy & assign
- DataBuilder(const DataBuilder&) = delete;
- DataBuilder& operator=(const DataBuilder&) = delete;
-
- /// Get N bytes of pseudo-random data
- /// @param out - pointer to location to save data
- /// @param n - number of bytes to get
- void build(void* out, size_t n) {
- assert(out != nullptr && "|out| cannot be nullptr");
- assert(n > 0 && "|n| must be > 0");
-
- generator_.GetNBytes(reinterpret_cast<uint8_t*>(out), n);
- }
-
- /// Generate pseudo-random data of a specific type into an output var
- /// @tparam T - type of data to produce
- /// @param out - output var to generate into
- template <typename T>
- void build(T& out) {
- out = build<T>();
- }
-
- /// Implementation of ::build<T>()
- /// @tparam T - type of data to produce
- template <typename T>
- struct BuildImpl {
- /// Generate a pseudo-random variable of type T
- /// @param b - data builder to use
- /// @returns a variable of type T filled with pseudo-random data
- static T impl(DataBuilder* b) {
- T out{};
- if constexpr (tint::HasReflection<T>) {
- ForeachField(out, [&](auto& field) { b->build(field); });
- } else if constexpr (std::is_standard_layout_v<T>) {
- b->build(&out, sizeof(T));
- } else {
- static_assert(sizeof(T) == 0, "cannot build type");
- }
- return out;
- }
- };
-};
-
-/// Specialization for bool
-template <>
-struct DataBuilder::BuildImpl<bool> {
- /// Generate a pseudo-random bool
- /// @param b - data builder to use
- /// @returns a boolean with even odds of being true or false
- static bool impl(DataBuilder* b) { return b->generator_.GetBool(); }
-};
-
-/// Specialization for std::string
-template <>
-struct DataBuilder::BuildImpl<std::string> {
- /// Generate a pseudo-random string
- /// @param b - data builder to use
- /// @returns a string filled with pseudo-random data
- static std::string impl(DataBuilder* b) {
- auto count = b->build<uint8_t>();
- if (count == 0) {
- return "";
- }
- std::vector<uint8_t> source(count);
- b->build(source.data(), count);
- return {source.begin(), source.end()};
- }
-};
-
-/// Specialization for std::optional
-template <typename T>
-struct DataBuilder::BuildImpl<std::optional<T>> {
- /// Generate a pseudo-random optional<T>
- /// @param b - data builder to use
- /// @returns a either a nullopt, or a randomly filled T
- static std::optional<T> impl(DataBuilder* b) {
- if (b->build<bool>()) {
- return b->build<T>();
- }
- return std::nullopt;
- }
-};
-
-/// Specialization for std::unordered_map<K, V>
-template <typename K, typename V>
-struct DataBuilder::BuildImpl<std::unordered_map<K, V>> {
- /// Generate a pseudo-random std::unordered_map<K, V>
- /// @param b - data builder to use
- /// @returns std::unordered_map<K, V> filled with
- /// pseudo-random data
- static std::unordered_map<K, V> impl(DataBuilder* b) {
- std::unordered_map<K, V> out;
- uint8_t count = b->build<uint8_t>();
- for (uint8_t i = 0; i < count; ++i) {
- out.emplace(b->build<K>(), b->build<V>());
- }
- return out;
- }
-};
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_DATA_BUILDER_H_
diff --git a/src/tint/fuzzers/dictionary.txt b/src/tint/fuzzers/dictionary.txt
deleted file mode 100644
index 59742d7..0000000
--- a/src/tint/fuzzers/dictionary.txt
+++ /dev/null
@@ -1,296 +0,0 @@
-"!"
-"!="
-"%"
-"%="
-"&"
-"&&"
-"&="
-"("
-")"
-"*"
-"*="
-"+"
-"++"
-"+="
-","
-"-"
-"--"
-"-="
-"->"
-"."
-"/"
-"/="
-":"
-";"
-"<"
-"<<"
-"<<="
-"<="
-"="
-"=="
-">"
-">="
-">>"
-">>="
-"@"
-"["
-"]"
-"^"
-"^="
-"_"
-"{"
-"|"
-"|="
-"||"
-"}"
-"~"
-"a"
-"abs"
-"acos"
-"acosh"
-"@align"
-"all"
-"any"
-"array"
-"arrayLength"
-"asin"
-"asinh"
-"atan"
-"atan2"
-"atanh"
-"atomic"
-"atomicAdd"
-"atomicAnd"
-"atomicLoad"
-"atomicMax"
-"atomicMin"
-"atomicOr"
-"atomicStore"
-"atomicSub"
-"atomicXor"
-"b"
-"@binding"
-"bitcast"
-"bool"
-"break"
-"@builtin"
-"@builtin(frag_depth)"
-"@builtin(front_facing)"
-"@builtin(global_invocation_id)"
-"@builtin(instance_index)"
-"@builtin(local_invocation_id)"
-"@builtin(local_invocation_index)"
-"@builtin(num_workgroups)"
-"@builtin(position)"
-"@builtin(sample_index)"
-"@builtin(sample_mask)"
-"@builtin(vertex_index)"
-"@builtin(workgroup_id)"
-"case"
-"ceil"
-"center"
-"centroid"
-"clamp"
-"@compute"
-"@const"
-"const"
-"continue"
-"continuing"
-"cos"
-"cosh"
-"countLeadingZeros"
-"countOneBits"
-"countTrailingZeros"
-"cross"
-"default"
-"degrees"
-"determinant"
-"discard"
-"distance"
-"dot"
-"dot4I8Packed"
-"dot4U8Packed"
-"dpdx"
-"dpdxCoarse"
-"dpdxFine"
-"dpdy"
-"dpdyCoarse"
-"dpdyFine"
-"else"
-"enable"
-"exp"
-"exp2"
-"extractBits"
-"f16"
-"f32"
-"faceForward"
-"fallthrough"
-"false"
-"firstLeadingBit"
-"firstTrailingBit"
-"flat"
-"floor"
-"fma"
-"fn"
-"for"
-"fract"
-"frag_depth"
-"@fragment"
-"frexp"
-"front_facing"
-"function"
-"fwidth"
-"fwidthCoarse"
-"fwidthFine"
-"g"
-"global_invocation_id"
-"@group"
-"i32"
-"@id"
-"if"
-"insertBits"
-"instance_index"
-"@interpolate"
-"@invariant"
-"inverseSqrt"
-"ldexp"
-"length"
-"let"
-"linear"
-"local_invocation_id"
-"local_invocation_index"
-"@location"
-"log"
-"log2"
-"loop"
-"mat2x2"
-"mat2x3"
-"mat2x4"
-"mat3x2"
-"mat3x3"
-"mat3x4"
-"mat4x2"
-"mat4x3"
-"mat4x4"
-"max"
-"min"
-"mix"
-"modf"
-"normalize"
-"num_workgroups"
-"override"
-"pack2x16float"
-"pack2x16snorm"
-"pack2x16unorm"
-"pack4x8snorm"
-"pack4x8unorm"
-"perspective"
-"position"
-"pow"
-"private"
-"ptr"
-"quantizeToF16"
-"r"
-"r32float"
-"r32sint"
-"r32uint"
-"radians"
-"read"
-"read_write"
-"reflect"
-"refract"
-"return"
-"reverseBits"
-"rg32float"
-"rg32sint"
-"rg32uint"
-"rgba16float"
-"rgba16sint"
-"rgba16uint"
-"rgba32float"
-"rgba32sint"
-"rgba32uint"
-"rgba8sint"
-"rgba8snorm"
-"rgba8uint"
-"rgba8unorm"
-"round"
-"sample"
-"sample_index"
-"sample_mask"
-"sampler"
-"sampler_comparison"
-"saturate"
-"select"
-"sign"
-"sin"
-"sinh"
-"@size"
-"smoothstep"
-"sqrt"
-"staticAssert"
-"step"
-"storage"
-"storageBarrier"
-"struct"
-"switch"
-"tan"
-"tanh"
-"texture_1d"
-"texture_2d"
-"texture_2d_array"
-"texture_3d"
-"texture_cube"
-"texture_cube_array"
-"texture_depth_2d"
-"texture_depth_2d_array"
-"texture_depth_cube"
-"texture_depth_cube_array"
-"texture_depth_multisampled_2d"
-"textureDimensions"
-"textureGather"
-"textureGatherCompare"
-"textureLoad"
-"texture_multisampled_2d"
-"textureNumLayers"
-"textureNumLevels"
-"textureNumSamples"
-"textureSample"
-"textureSampleBias"
-"textureSampleCompare"
-"textureSampleCompareLevel"
-"textureSampleGrad"
-"textureSampleLevel"
-"texture_storage_1d"
-"texture_storage_2d"
-"texture_storage_2d_array"
-"texture_storage_3d"
-"textureStore"
-"transpose"
-"true"
-"trunc"
-"type"
-"u32"
-"uniform"
-"unpack2x16float"
-"unpack2x16snorm"
-"unpack2x16unorm"
-"unpack4x8snorm"
-"unpack4x8unorm"
-"var"
-"vec2"
-"vec3"
-"vec4"
-"@vertex"
-"vertex_index"
-"w"
-"while"
-"workgroup"
-"workgroupBarrier"
-"workgroupUniformLoad"
-"workgroup_id"
-"@workgroup_size"
-"write"
-"x"
-"y"
-"z"
diff --git a/src/tint/fuzzers/fuzzer_init.cc b/src/tint/fuzzers/fuzzer_init.cc
deleted file mode 100644
index 6abf53e..0000000
--- a/src/tint/fuzzers/fuzzer_init.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cstddef>
-
-#include "src/tint/fuzzers/cli.h"
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "testing/libfuzzer/libfuzzer_exports.h"
-
-namespace tint::fuzzers {
-
-namespace {
-CliParams cli_params;
-}
-
-const CliParams& GetCliParams() {
- return cli_params;
-}
-
-extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
- cli_params = ParseCliParams(argc, *argv);
- return 0;
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/fuzzer_init.h b/src/tint/fuzzers/fuzzer_init.h
deleted file mode 100644
index ee1ba0d..0000000
--- a/src/tint/fuzzers/fuzzer_init.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_FUZZER_INIT_H_
-#define SRC_TINT_FUZZERS_FUZZER_INIT_H_
-
-#include "src/tint/fuzzers/cli.h"
-
-namespace tint::fuzzers {
-
-/// Returns the common CliParams parsed and populated by LLVMFuzzerInitialize()
-const CliParams& GetCliParams();
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_FUZZER_INIT_H_
diff --git a/src/tint/fuzzers/generate_spirv_corpus.py b/src/tint/fuzzers/generate_spirv_corpus.py
deleted file mode 100644
index 9e74b18..0000000
--- a/src/tint/fuzzers/generate_spirv_corpus.py
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2021 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# Collect all .spvasm files under a given directory, assemble them using
-# spirv-as, and emit the assembled binaries to a given corpus directory,
-# flattening their file names by replacing path separators with underscores.
-# If the output directory already exists, it will be deleted and re-created.
-# Files ending with ".expected.spvasm" are skipped.
-#
-# The intended use of this script is to generate a corpus of SPIR-V
-# binaries for fuzzing.
-#
-# Usage:
-# generate_spirv_corpus.py <input_dir> <corpus_dir> <path to spirv-as>
-
-import os
-import pathlib
-import shutil
-import subprocess
-import sys
-
-
-def list_spvasm_files(root_search_dir):
- for root, folders, files in os.walk(root_search_dir):
- for filename in folders + files:
- if pathlib.Path(filename).suffix == ".spvasm":
- yield os.path.join(root, filename)
-
-
-def main():
- if len(sys.argv) != 4:
- print("Usage: " + sys.argv[0] +
- " <input dir> <output dir> <spirv-as path>")
- return 1
- input_dir: str = os.path.abspath(sys.argv[1].rstrip(os.sep))
- corpus_dir: str = os.path.abspath(sys.argv[2])
- spirv_as_path: str = os.path.abspath(sys.argv[3])
- if os.path.exists(corpus_dir):
- shutil.rmtree(corpus_dir)
- os.makedirs(corpus_dir)
-
- # It might be that some of the attempts to convert SPIR-V assembly shaders
- # into SPIR-V binaries go wrong. It is sensible to tolerate a small number
- # of such errors, to avoid fuzzer preparation failing due to bugs in
- # spirv-as. But it is important to know when a large number of failures
- # occur, in case something is more deeply wrong.
- num_errors = 0
- max_tolerated_errors = 10
- logged_errors = ""
-
- for in_file in list_spvasm_files(input_dir):
- if ".expected." in in_file:
- continue
- out_file = os.path.splitext(
- corpus_dir + os.sep +
- in_file[len(input_dir) + 1:].replace(os.sep, '_'))[0] + ".spv"
- cmd = [
- spirv_as_path, "--target-env", "spv1.3", in_file, "-o", out_file
- ]
- proc = subprocess.Popen(cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- stdout, stderr = proc.communicate()
- if proc.returncode != 0:
- num_errors += 1
- logged_errors += "Error running " + " ".join(
- cmd) + ": " + stdout.decode('utf-8') + stderr.decode('utf-8')
-
- if num_errors > max_tolerated_errors:
- print("Too many (" + str(num_errors) +
- ") errors occurred while generating the SPIR-V corpus.")
- print(logged_errors)
- return 1
-
-
-if __name__ == "__main__":
- sys.exit(main())
diff --git a/src/tint/fuzzers/generate_wgsl_corpus.py b/src/tint/fuzzers/generate_wgsl_corpus.py
deleted file mode 100644
index 1cd6ea9..0000000
--- a/src/tint/fuzzers/generate_wgsl_corpus.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2021 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# Collect all .wgsl files under a given directory and copy them to a given
-# corpus directory, flattening their file names by replacing path
-# separators with underscores. If the output directory already exists, it
-# will be deleted and re-created. Files ending with ".expected.spvasm" are
-# skipped.
-#
-# The intended use of this script is to generate a corpus of WGSL shaders
-# for fuzzing.
-#
-# Usage:
-# generate_wgsl_corpus.py <input_dir> <corpus_dir>
-
-import optparse
-import os
-import pathlib
-import shutil
-import sys
-
-
-def list_wgsl_files(root_search_dir):
- for root, folders, files in os.walk(root_search_dir):
- for filename in folders + files:
- if pathlib.Path(filename).suffix == '.wgsl':
- yield os.path.join(root, filename)
-
-
-def main():
- parser = optparse.OptionParser(
- usage="usage: %prog [option] input-dir output-dir")
- parser.add_option('--stamp', dest='stamp', help='stamp file')
- options, args = parser.parse_args(sys.argv[1:])
- if len(args) != 2:
- parser.error("incorrect number of arguments")
- input_dir: str = os.path.abspath(args[0].rstrip(os.sep))
- corpus_dir: str = os.path.abspath(args[1])
- if os.path.exists(corpus_dir):
- shutil.rmtree(corpus_dir)
- os.makedirs(corpus_dir)
- for in_file in list_wgsl_files(input_dir):
- if in_file.endswith(".expected.wgsl"):
- continue
- out_file = in_file[len(input_dir) + 1:].replace(os.sep, '_')
- shutil.copy(in_file, corpus_dir + os.sep + out_file)
- if options.stamp:
- pathlib.Path(options.stamp).touch(mode=0o644, exist_ok=True)
-
-
-if __name__ == "__main__":
- sys.exit(main())
diff --git a/src/tint/fuzzers/mersenne_twister_engine.cc b/src/tint/fuzzers/mersenne_twister_engine.cc
deleted file mode 100644
index a0913bb..0000000
--- a/src/tint/fuzzers/mersenne_twister_engine.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/mersenne_twister_engine.h"
-
-#include <algorithm>
-#include <cassert>
-
-#include "src/tint/utils/math/hash.h"
-
-namespace tint::fuzzers {
-
-namespace {
-
-/// Generate integer from uniform distribution
-/// @tparam I - integer type
-/// @param engine - random number engine to use
-/// @param lower - Lower bound of integer generated
-/// @param upper - Upper bound of integer generated
-/// @returns i, where lower <= i < upper
-template <typename I>
-I RandomInteger(std::mt19937_64* engine, I lower, I upper) {
- assert(lower < upper && "|lower| must be strictly less than |upper|");
- return std::uniform_int_distribution<I>(lower, upper - 1)(*engine);
-}
-
-} // namespace
-
-MersenneTwisterEngine::MersenneTwisterEngine(uint64_t seed) : engine_(seed) {}
-
-uint32_t MersenneTwisterEngine::RandomUInt32(uint32_t lower, uint32_t upper) {
- return RandomInteger(&engine_, lower, upper);
-}
-
-uint64_t MersenneTwisterEngine::RandomUInt64(uint64_t lower, uint64_t upper) {
- return RandomInteger(&engine_, lower, upper);
-}
-
-void MersenneTwisterEngine::RandomNBytes(uint8_t* dest, size_t n) {
- assert(dest && "|dest| must not be nullptr");
- std::generate(dest, dest + n,
- std::independent_bits_engine<std::mt19937_64, 8, uint8_t>(engine_));
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/mersenne_twister_engine.h b/src/tint/fuzzers/mersenne_twister_engine.h
deleted file mode 100644
index 25450fb..0000000
--- a/src/tint/fuzzers/mersenne_twister_engine.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_MERSENNE_TWISTER_ENGINE_H_
-#define SRC_TINT_FUZZERS_MERSENNE_TWISTER_ENGINE_H_
-
-#include <random>
-
-#include "src/tint/fuzzers/random_generator_engine.h"
-
-namespace tint::fuzzers {
-
-/// Standard MT based random number generation
-class MersenneTwisterEngine : public RandomGeneratorEngine {
- public:
- /// @brief Initializes using provided seed
- /// @param seed - seed value to use
- explicit MersenneTwisterEngine(uint64_t seed);
- ~MersenneTwisterEngine() override = default;
-
- /// Generate random uint32_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- uint32_t RandomUInt32(uint32_t lower, uint32_t upper) override;
-
- /// Get random uint64_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- uint64_t RandomUInt64(uint64_t lower, uint64_t upper) override;
-
- /// Get N bytes of pseudo-random data
- /// @param dest - memory location to store data
- /// @param n - number of bytes of data to generate
- void RandomNBytes(uint8_t* dest, size_t n) override;
-
- private:
- // Disallow copy & assign
- MersenneTwisterEngine(const MersenneTwisterEngine&) = delete;
- MersenneTwisterEngine& operator=(const MersenneTwisterEngine&) = delete;
-
- std::mt19937_64 engine_;
-}; // class MersenneTwisterEngine
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_MERSENNE_TWISTER_ENGINE_H_
diff --git a/src/tint/fuzzers/random_generator.cc b/src/tint/fuzzers/random_generator.cc
deleted file mode 100644
index 5bcf4cd..0000000
--- a/src/tint/fuzzers/random_generator.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/random_generator.h"
-
-#include <algorithm>
-#include <cassert>
-#include <utility>
-
-#include "src/tint/fuzzers/mersenne_twister_engine.h"
-#include "src/tint/fuzzers/random_generator_engine.h"
-
-namespace tint::fuzzers {
-
-namespace {
-
-/// Calculate the hash for the contents of a c-style data buffer
-/// This is intentionally not implemented as a generic override of HashCombine
-/// in "src/tint/utils/math/hash.h", because it conflicts with the vardiac override
-/// for the case where a pointer and an integer are being hashed.
-/// @param data - pointer to buffer to be hashed
-/// @param size - number of elements in buffer
-/// @returns hash of the data in the buffer
-size_t HashBuffer(const uint8_t* data, const size_t size) {
- size_t hash = std::hash<size_t>{}(size);
- for (size_t i = 0; i < size; i++) {
- hash ^= (static_cast<uint64_t>(data[i]) * 31) + (0x7f4a7c16 ^ (hash >> 2));
- }
- return hash;
-}
-
-} // namespace
-
-RandomGenerator::RandomGenerator(std::unique_ptr<RandomGeneratorEngine> engine)
- : engine_(std::move(engine)) {}
-
-RandomGenerator::RandomGenerator(uint64_t seed)
- : RandomGenerator(std::make_unique<MersenneTwisterEngine>(seed)) {}
-
-uint32_t RandomGenerator::GetUInt32(uint32_t lower, uint32_t upper) {
- assert(lower < upper && "|lower| must be strictly less than |upper|");
- return engine_->RandomUInt32(lower, upper);
-}
-
-uint32_t RandomGenerator::GetUInt32(uint32_t bound) {
- assert(bound > 0 && "|bound| must be greater than 0");
- return engine_->RandomUInt32(0u, bound);
-}
-
-uint64_t RandomGenerator::GetUInt64(uint64_t lower, uint64_t upper) {
- assert(lower < upper && "|lower| must be strictly less than |upper|");
- return engine_->RandomUInt64(lower, upper);
-}
-
-uint64_t RandomGenerator::GetUInt64(uint64_t bound) {
- assert(bound > 0 && "|bound| must be greater than 0");
- return engine_->RandomUInt64(static_cast<uint64_t>(0), bound);
-}
-
-uint8_t RandomGenerator::GetByte() {
- uint8_t result;
- engine_->RandomNBytes(&result, 1);
- return result;
-}
-
-uint32_t RandomGenerator::Get4Bytes() {
- uint32_t result;
- engine_->RandomNBytes(reinterpret_cast<uint8_t*>(&result), 4);
- return result;
-}
-
-void RandomGenerator::GetNBytes(uint8_t* dest, size_t n) {
- assert(dest && "|dest| must not be nullptr");
- engine_->RandomNBytes(dest, n);
-}
-
-bool RandomGenerator::GetBool() {
- return engine_->RandomUInt32(0u, 2u);
-}
-
-bool RandomGenerator::GetWeightedBool(uint32_t percentage) {
- static const uint32_t kMaxPercentage = 100;
- assert(percentage <= kMaxPercentage && "|percentage| needs to be within [0, 100]");
- return engine_->RandomUInt32(0u, kMaxPercentage) < percentage;
-}
-
-uint64_t RandomGenerator::CalculateSeed(const uint8_t* data, size_t size) {
- assert(data != nullptr && "|data| must be !nullptr");
-
- // Number of bytes we want to skip at the start of data for the hash.
- // Fewer bytes may be skipped when `size` is small.
- // Has lower precedence than kHashDesiredMinBytes.
- static const int64_t kHashDesiredLeadingSkipBytes = 5;
- // Minimum number of bytes we want to use in the hash.
- // Used for short buffers.
- static const int64_t kHashDesiredMinBytes = 4;
- // Maximum number of bytes we want to use in the hash.
- static const int64_t kHashDesiredMaxBytes = 32;
- auto size_i64 = static_cast<int64_t>(size);
- auto hash_begin_i64 = std::min(kHashDesiredLeadingSkipBytes,
- std::max<int64_t>(size_i64 - kHashDesiredMinBytes, 0));
- auto hash_end_i64 = std::min(hash_begin_i64 + kHashDesiredMaxBytes, size_i64);
- auto hash_begin = static_cast<size_t>(hash_begin_i64);
- auto hash_size = static_cast<size_t>(hash_end_i64) - hash_begin;
- return HashBuffer(data + hash_begin, hash_size);
-}
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/random_generator.h b/src/tint/fuzzers/random_generator.h
deleted file mode 100644
index 708e94ae..0000000
--- a/src/tint/fuzzers/random_generator.h
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_RANDOM_GENERATOR_H_
-#define SRC_TINT_FUZZERS_RANDOM_GENERATOR_H_
-
-#include <memory>
-#include <random>
-#include <vector>
-
-#include "src/tint/fuzzers/random_generator_engine.h"
-
-namespace tint::fuzzers {
-
-/// Pseudo random generator utility class for fuzzing
-class RandomGenerator {
- public:
- /// @brief Initializes using provided engine
- /// @param engine - engine implementation to use
- explicit RandomGenerator(std::unique_ptr<RandomGeneratorEngine> engine);
-
- /// @brief Creates a MersenneTwisterEngine and initializes using that
- /// @param seed - seed value to use for engine
- explicit RandomGenerator(uint64_t seed);
-
- /// Destructor
- ~RandomGenerator() = default;
-
- /// Move Constructor
- RandomGenerator(RandomGenerator&&) = default;
-
- /// Get uint32_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- uint32_t GetUInt32(uint32_t lower, uint32_t upper);
-
- /// Get uint32_t value from uniform distribution.
- /// @param bound - Upper bound of integer generated
- /// @returns i, where 0 <= i < bound
- uint32_t GetUInt32(uint32_t bound);
-
- /// Get uint32_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- uint64_t GetUInt64(uint64_t lower, uint64_t upper);
-
- /// Get uint64_t value from uniform distribution.
- /// @param bound - Upper bound of integer generated
- /// @returns i, where 0 <= i < bound
- uint64_t GetUInt64(uint64_t bound);
-
- /// Get 1 byte of pseudo-random data
- /// Should be more efficient then calling GetNBytes(1);
- /// @returns 1-byte of random data
- uint8_t GetByte();
-
- /// Get 4 bytes of pseudo-random data
- /// Should be more efficient then calling GetNBytes(4);
- /// @returns 4-bytes of random data
- uint32_t Get4Bytes();
-
- /// Get N bytes of pseudo-random data
- /// @param dest - memory location to store data
- /// @param n - number of bytes of data to get
- void GetNBytes(uint8_t* dest, size_t n);
-
- /// Get random bool with even odds
- /// @returns true 50% of the time and false %50 of time.
- bool GetBool();
-
- /// Get random bool with weighted odds
- /// @param percentage - likelihood of true being returned
- /// @returns true |percentage|% of the time, and false (100 - |percentage|)%
- /// of the time.
- bool GetWeightedBool(uint32_t percentage);
-
- /// Returns a randomly-chosen element from vector v.
- /// @param v - the vector from which the random element will be selected.
- /// @return a random element of vector v.
- template <typename T>
- inline T GetRandomElement(const std::vector<T>& v) {
- return v[GetUInt64(0, v.size())];
- }
-
- /// Calculate a seed value based on a blob of data.
- /// Currently hashes bytes near the front of the buffer, after skipping N
- /// bytes.
- /// @param data - pointer to data to base calculation off of, must be !nullptr
- /// @param size - number of elements in |data|, must be > 0
- /// @returns calculated seed value
- static uint64_t CalculateSeed(const uint8_t* data, size_t size);
-
- private:
- // Disallow copy & assign
- RandomGenerator(const RandomGenerator&) = delete;
- RandomGenerator& operator=(const RandomGenerator&) = delete;
-
- std::unique_ptr<RandomGeneratorEngine> engine_;
-}; // class RandomGenerator
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_RANDOM_GENERATOR_H_
diff --git a/src/tint/fuzzers/random_generator_engine.cc b/src/tint/fuzzers/random_generator_engine.cc
deleted file mode 100644
index 7af04a8..0000000
--- a/src/tint/fuzzers/random_generator_engine.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/random_generator_engine.h"
-
-namespace tint::fuzzers {
-
-// Not in header to avoid weak vtable warnings from clang
-RandomGeneratorEngine::RandomGeneratorEngine() = default;
-RandomGeneratorEngine::~RandomGeneratorEngine() = default;
-RandomGeneratorEngine::RandomGeneratorEngine(RandomGeneratorEngine&&) = default;
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/random_generator_engine.h b/src/tint/fuzzers/random_generator_engine.h
deleted file mode 100644
index ad55c65..0000000
--- a/src/tint/fuzzers/random_generator_engine.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_RANDOM_GENERATOR_ENGINE_H_
-#define SRC_TINT_FUZZERS_RANDOM_GENERATOR_ENGINE_H_
-
-#include <memory>
-#include <random>
-#include <vector>
-
-namespace tint::fuzzers {
-
-/// Wrapper interface around STL random number engine
-class RandomGeneratorEngine {
- public:
- /// Constructor
- RandomGeneratorEngine();
-
- /// Destructor
- virtual ~RandomGeneratorEngine();
-
- /// Move Constructor
- RandomGeneratorEngine(RandomGeneratorEngine&&);
-
- /// Generates a random uint32_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- virtual uint32_t RandomUInt32(uint32_t lower, uint32_t upper) = 0;
-
- /// Generates a random uint64_t value from uniform distribution.
- /// @param lower - lower bound of integer generated
- /// @param upper - upper bound of integer generated
- /// @returns i, where lower <= i < upper
- virtual uint64_t RandomUInt64(uint64_t lower, uint64_t upper) = 0;
-
- /// Generates N bytes of pseudo-random data
- /// @param dest - memory location to store data
- /// @param n - number of bytes of data to generate
- virtual void RandomNBytes(uint8_t* dest, size_t n) = 0;
-
- private:
- // Disallow copy & assign
- RandomGeneratorEngine(const RandomGeneratorEngine&) = delete;
- RandomGeneratorEngine& operator=(const RandomGeneratorEngine&) = delete;
-}; // class RandomGeneratorEngine
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_RANDOM_GENERATOR_ENGINE_H_
diff --git a/src/tint/fuzzers/random_generator_test.cc b/src/tint/fuzzers/random_generator_test.cc
deleted file mode 100644
index c1c2098..0000000
--- a/src/tint/fuzzers/random_generator_test.cc
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/random_generator.h"
-
-#include <memory>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/mersenne_twister_engine.h"
-
-namespace tint::fuzzers {
-namespace {
-
-/// Implementation of RandomGeneratorEngine that just returns a stream of
-/// monotonically increasing numbers.
-class MonotonicEngine : public RandomGeneratorEngine {
- public:
- uint32_t RandomUInt32(uint32_t, uint32_t) override { return next_++; }
-
- uint64_t RandomUInt64(uint64_t, uint64_t) override { return next_++; }
-
- void RandomNBytes(uint8_t*, size_t) override {
- assert(false && "MonotonicDelegate does not implement RandomNBytes");
- }
-
- private:
- uint32_t next_ = 0;
-};
-
-class RandomGeneratorTest : public testing::Test {
- public:
- void SetUp() override { rng_ = std::make_unique<RandomGenerator>(0); }
-
- void TearDown() override {}
-
- protected:
- std::unique_ptr<RandomGenerator> rng_;
-};
-
-#ifndef NDEBUG
-TEST_F(RandomGeneratorTest, GetUInt32ReversedBoundsCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt32(10, 5), ".*");
-}
-
-TEST_F(RandomGeneratorTest, GetUInt32EmptyBoundsCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt32(5, 5), ".*");
-}
-
-TEST_F(RandomGeneratorTest, GetUInt32ZeroBoundCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt32(0u), ".*");
-}
-#endif // NDEBUG
-
-TEST_F(RandomGeneratorTest, GetUInt32SingularReturnsOneValue) {
- {
- uint32_t result = rng_->GetUInt32(5u, 6u);
- ASSERT_EQ(5u, result);
- }
- {
- uint32_t result = rng_->GetUInt32(1u);
- ASSERT_EQ(0u, result);
- }
-}
-
-TEST_F(RandomGeneratorTest, GetUInt32StaysInBounds) {
- {
- uint32_t result = rng_->GetUInt32(5u, 10u);
- ASSERT_LE(5u, result);
- ASSERT_GT(10u, result);
- }
- {
- uint32_t result = rng_->GetUInt32(10u);
- ASSERT_LE(0u, result);
- ASSERT_GT(10u, result);
- }
-}
-
-#ifndef NDEBUG
-TEST_F(RandomGeneratorTest, GetUInt64ReversedBoundsCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt64(10, 5), ".*");
-}
-
-TEST_F(RandomGeneratorTest, GetUInt64EmptyBoundsCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt64(5, 5), ".*");
-}
-
-TEST_F(RandomGeneratorTest, GetUInt64ZeroBoundCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetUInt64(0u), ".*");
-}
-#endif // NDEBUG
-
-TEST_F(RandomGeneratorTest, GetUInt64SingularReturnsOneValue) {
- {
- uint64_t result = rng_->GetUInt64(5u, 6u);
- ASSERT_EQ(5u, result);
- }
- {
- uint64_t result = rng_->GetUInt64(1u);
- ASSERT_EQ(0u, result);
- }
-}
-
-TEST_F(RandomGeneratorTest, GetUInt64StaysInBounds) {
- {
- uint64_t result = rng_->GetUInt64(5u, 10u);
- ASSERT_LE(5u, result);
- ASSERT_GT(10u, result);
- }
- {
- uint64_t result = rng_->GetUInt64(10u);
- ASSERT_LE(0u, result);
- ASSERT_GT(10u, result);
- }
-}
-
-TEST_F(RandomGeneratorTest, GetByte) {
- rng_->GetByte();
-}
-
-#ifndef NDEBUG
-TEST_F(RandomGeneratorTest, GetNBytesNullDataBufferCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetNBytes(nullptr, 5), ".*");
-}
-#endif // NDEBUG
-
-TEST_F(RandomGeneratorTest, GetNBytes) {
- std::vector<uint8_t> data;
- for (uint32_t i = 25; i < 1000u; i = i + 25) {
- data.resize(i);
- rng_->GetNBytes(data.data(), data.size());
- }
-}
-
-TEST_F(RandomGeneratorTest, GetBool) {
- rng_->GetBool();
-}
-
-TEST_F(RandomGeneratorTest, GetWeightedBoolZeroAlwaysFalse) {
- ASSERT_FALSE(rng_->GetWeightedBool(0));
-}
-
-TEST_F(RandomGeneratorTest, GetWeightedBoolHundredAlwaysTrue) {
- ASSERT_TRUE(rng_->GetWeightedBool(100));
-}
-
-#ifndef NDEBUG
-TEST_F(RandomGeneratorTest, GetWeightedBoolAboveHundredCrashes) {
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetWeightedBool(101), ".*");
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetWeightedBool(500), ".*");
-}
-#endif // NDEBUG
-
-TEST_F(RandomGeneratorTest, GetWeightedBool) {
- for (uint32_t i = 0; i <= 100; i++) {
- rng_ = std::make_unique<RandomGenerator>(std::make_unique<MonotonicEngine>());
- for (uint32_t j = 0; j <= 100; j++) {
- if (j < i) {
- ASSERT_TRUE(rng_->GetWeightedBool(i));
- } else {
- ASSERT_FALSE(rng_->GetWeightedBool(i));
- }
- }
- }
-}
-
-#ifndef NDEBUG
-TEST_F(RandomGeneratorTest, GetRandomElementEmptyVectorCrashes) {
- std::vector<uint8_t> v;
- EXPECT_DEATH_IF_SUPPORTED(rng_->GetRandomElement(v), ".*");
-}
-#endif // NDEBUG
-
-TEST_F(RandomGeneratorTest, GetRandomElement) {
- std::vector<uint32_t> v;
- for (uint32_t i = 25; i < 100u; i = i + 25) {
- rng_ = std::make_unique<RandomGenerator>(std::make_unique<MonotonicEngine>());
- v.resize(i);
- std::iota(v.begin(), v.end(), 0);
- for (uint32_t j = 0; j < i; j++) {
- EXPECT_EQ(j, rng_->GetRandomElement(v));
- }
- }
-}
-
-} // namespace
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/shuffle_transform.cc b/src/tint/fuzzers/shuffle_transform.cc
deleted file mode 100644
index c3504e9..0000000
--- a/src/tint/fuzzers/shuffle_transform.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/shuffle_transform.h"
-
-#include <random>
-#include <utility>
-
-#include "src/tint/lang/wgsl/program/clone_context.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/resolver/resolve.h"
-
-namespace tint::fuzzers {
-
-ShuffleTransform::ShuffleTransform(size_t seed) : seed_(seed) {}
-
-ast::transform::Transform::ApplyResult ShuffleTransform::Apply(const Program& src,
- const ast::transform::DataMap&,
- ast::transform::DataMap&) const {
- ProgramBuilder b;
- program::CloneContext ctx{&b, &src, /* auto_clone_symbols */ true};
-
- auto decls = src.AST().GlobalDeclarations();
- auto rng = std::mt19937_64{seed_};
- std::shuffle(std::begin(decls), std::end(decls), rng);
- for (auto* decl : decls) {
- b.AST().AddGlobalDeclaration(ctx.Clone(decl));
- }
-
- ctx.Clone();
- return resolver::Resolve(b);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/shuffle_transform.h b/src/tint/fuzzers/shuffle_transform.h
deleted file mode 100644
index 748f0ce..0000000
--- a/src/tint/fuzzers/shuffle_transform.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_SHUFFLE_TRANSFORM_H_
-#define SRC_TINT_FUZZERS_SHUFFLE_TRANSFORM_H_
-
-#include "src/tint/lang/wgsl/ast/transform/transform.h"
-
-namespace tint::fuzzers {
-
-/// ShuffleTransform reorders the module scope declarations into a random order
-class ShuffleTransform : public ast::transform::Transform {
- public:
- /// Constructor
- /// @param seed the random seed to use for the shuffling
- explicit ShuffleTransform(size_t seed);
-
- /// @copydoc ast::transform::Transform::Apply
- ApplyResult Apply(const Program& program,
- const ast::transform::DataMap& inputs,
- ast::transform::DataMap& outputs) const override;
-
- private:
- size_t seed_;
-};
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_SHUFFLE_TRANSFORM_H_
diff --git a/src/tint/fuzzers/tint_all_transforms_fuzzer.cc b/src/tint/fuzzers/tint_all_transforms_fuzzer.cc
deleted file mode 100644
index bf29374..0000000
--- a/src/tint/fuzzers/tint_all_transforms_fuzzer.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/random_generator.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- {
- TransformBuilder tb(data, size);
- tb.AddTransform<ShuffleTransform>();
- tb.AddPlatformIndependentPasses();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- fuzzer.Run(data, size);
- }
-
-#if TINT_BUILD_HLSL_WRITER
- {
- TransformBuilder tb(data, size);
- tb.AddTransform<ShuffleTransform>();
- tb.AddPlatformIndependentPasses();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- fuzzer.Run(data, size);
- }
-#endif // TINT_BUILD_HLSL_WRITER
-
-#if TINT_BUILD_MSL_WRITER
- {
- TransformBuilder tb(data, size);
- tb.AddTransform<ShuffleTransform>();
- tb.AddPlatformIndependentPasses();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- fuzzer.Run(data, size);
- }
-#endif // TINT_BUILD_MSL_WRITER
-#if TINT_BUILD_SPV_WRITER
- {
- TransformBuilder tb(data, size);
- tb.AddTransform<ShuffleTransform>();
- tb.AddPlatformIndependentPasses();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- fuzzer.Run(data, size);
- }
-#endif // TINT_BUILD_SPV_WRITER
-
- return 0;
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/BUILD.gn b/src/tint/fuzzers/tint_ast_fuzzer/BUILD.gn
deleted file mode 100644
index 171ba14..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/BUILD.gn
+++ /dev/null
@@ -1,104 +0,0 @@
-# Copyright 2022 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import("//build_overrides/build.gni")
-import("../../../../scripts/tint_overrides_with_defaults.gni")
-
-if (build_with_chromium) {
- import("//third_party/protobuf/proto_library.gni")
- import("../../../../scripts/dawn_overrides_with_defaults.gni")
-
- proto_library("tint_ast_fuzzer_proto") {
- sources = [ "protobufs/tint_ast_fuzzer.proto" ]
- generate_python = false
- use_protobuf_full = true
- }
-
- source_set("tint_ast_fuzzer") {
- public_configs = [
- "${tint_src_dir}:tint_config",
- "${tint_src_dir}:tint_common_config",
- ]
-
- include_dirs = [ "${target_gen_dir}/../../../.." ]
-
- deps = [
- ":tint_ast_fuzzer_proto",
- "${tint_src_dir}/fuzzers:tint_fuzzer_common_src",
- "${tint_src_dir}/lang/core",
- "${tint_src_dir}/lang/wgsl/ast",
- "${tint_src_dir}/lang/wgsl/program",
- "${tint_src_dir}/lang/wgsl/resolver",
- "${tint_src_dir}/lang/wgsl/sem",
- "${tint_src_dir}/utils/rtti",
- "//third_party/protobuf:protobuf_full",
- ]
-
- sources = [
- "cli.cc",
- "cli.h",
- "expression_size.cc",
- "expression_size.h",
- "fuzzer.cc",
- "jump_tracker.cc",
- "jump_tracker.h",
- "mutation.cc",
- "mutation.h",
- "mutation_finder.cc",
- "mutation_finder.h",
- "mutation_finders/change_binary_operators.cc",
- "mutation_finders/change_binary_operators.h",
- "mutation_finders/change_unary_operators.cc",
- "mutation_finders/change_unary_operators.h",
- "mutation_finders/delete_statements.cc",
- "mutation_finders/delete_statements.h",
- "mutation_finders/replace_identifiers.cc",
- "mutation_finders/replace_identifiers.h",
- "mutation_finders/wrap_unary_operators.cc",
- "mutation_finders/wrap_unary_operators.h",
- "mutations/change_binary_operator.cc",
- "mutations/change_binary_operator.h",
- "mutations/change_unary_operator.cc",
- "mutations/change_unary_operator.h",
- "mutations/delete_statement.cc",
- "mutations/delete_statement.h",
- "mutations/replace_identifier.cc",
- "mutations/replace_identifier.h",
- "mutations/wrap_unary_operator.cc",
- "mutations/wrap_unary_operator.h",
- "mutator.cc",
- "mutator.h",
- "node_id_map.cc",
- "node_id_map.h",
- "override_cli_params.h",
- "probability_context.cc",
- "probability_context.h",
- "protobufs/tint_ast_fuzzer.h",
- "util.h",
- ]
- }
-}
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/CMakeLists.txt b/src/tint/fuzzers/tint_ast_fuzzer/CMakeLists.txt
deleted file mode 100644
index d4a7050..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/CMakeLists.txt
+++ /dev/null
@@ -1,172 +0,0 @@
-# Copyright 2021 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-function(add_tint_ast_fuzzer NAME)
- add_executable(${NAME} ${NAME}.cc ${AST_FUZZER_SOURCES})
- target_link_libraries(${NAME} PRIVATE libtint_ast_fuzzer tint_lang_hlsl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE libtint_ast_fuzzer tint_lang_msl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE libtint_ast_fuzzer tint_lang_spirv_writer_helpers)
- tint_fuzzer_compile_options(${NAME})
- if(TINT_BUILD_SPV_READER OR TINT_BUILD_SPV_WRITER)
- tint_spvheaders_compile_options(${NAME})
- tint_spvtools_compile_options(${NAME})
- endif()
- target_compile_definitions(${NAME} PRIVATE CUSTOM_MUTATOR)
- target_include_directories(${NAME} PRIVATE ${CMAKE_BINARY_DIR})
- target_compile_options(${NAME} PRIVATE
- -Wno-conditional-uninitialized
- -Wno-covered-switch-default
- -Wno-shadow-field-in-constructor
- -Wno-shorten-64-to-32
- -Wno-undef)
-endfunction()
-
-set(PROTOBUF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/protobufs/tint_ast_fuzzer.proto)
-
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobufs)
-
-add_custom_command(
- OUTPUT
- ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc
- ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.h
- COMMAND
- "protobuf::protoc" -I=${CMAKE_CURRENT_SOURCE_DIR}/protobufs
- --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/protobufs ${PROTOBUF_SOURCES}
- DEPENDS ${PROTOBUF_SOURCES}
- COMMENT "Generate protobuf sources from proto definition file.")
-
-set(LIBTINT_AST_FUZZER_SOURCES
- ../mersenne_twister_engine.h
- ../random_generator.h
- ../random_generator_engine.h
- expression_size.h
- jump_tracker.h
- mutation.h
- mutation_finder.h
- mutation_finders/change_binary_operators.h
- mutation_finders/change_unary_operators.h
- mutation_finders/delete_statements.h
- mutation_finders/replace_identifiers.h
- mutation_finders/wrap_unary_operators.h
- mutations/change_binary_operator.h
- mutations/change_unary_operator.h
- mutations/delete_statement.h
- mutations/replace_identifier.h
- mutations/wrap_unary_operator.h
- mutator.h
- node_id_map.h
- probability_context.h
- protobufs/tint_ast_fuzzer.h
- util.h
- ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.h)
-
-set(LIBTINT_AST_FUZZER_SOURCES ${LIBTINT_AST_FUZZER_SOURCES}
- ../mersenne_twister_engine.cc
- ../random_generator.cc
- ../random_generator_engine.cc
- expression_size.cc
- jump_tracker.cc
- mutation.cc
- mutation_finder.cc
- mutation_finders/change_binary_operators.cc
- mutation_finders/change_unary_operators.cc
- mutation_finders/delete_statements.cc
- mutation_finders/replace_identifiers.cc
- mutation_finders/wrap_unary_operators.cc
- mutations/change_binary_operator.cc
- mutations/change_unary_operator.cc
- mutations/delete_statement.cc
- mutations/replace_identifier.cc
- mutations/wrap_unary_operator.cc
- mutator.cc
- node_id_map.cc
- probability_context.cc
- ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc)
-
-set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc PROPERTIES COMPILE_FLAGS -w)
-
-# Add static library target.
-add_library(libtint_ast_fuzzer STATIC ${LIBTINT_AST_FUZZER_SOURCES})
-target_link_libraries(libtint_ast_fuzzer protobuf::libprotobuf tint_api_sanitize_fuzzer)
-tint_default_compile_options(libtint_ast_fuzzer)
-target_include_directories(libtint_ast_fuzzer PRIVATE ${CMAKE_BINARY_DIR})
-target_compile_options(libtint_ast_fuzzer PRIVATE
- -Wno-conditional-uninitialized
- -Wno-covered-switch-default
- -Wno-shadow-field-in-constructor
- -Wno-shorten-64-to-32
- -Wno-undef)
-
-set(AST_FUZZER_SOURCES
- cli.cc
- cli.h
- fuzzer.cc
- override_cli_params.h
- ../tint_common_fuzzer.cc
- ../tint_common_fuzzer.h)
-
-set_source_files_properties(fuzzer.cc PROPERTIES COMPILE_FLAGS -Wno-missing-prototypes)
-
-# Add libfuzzer targets.
-# Targets back-ends according to command line arguments.
-add_tint_ast_fuzzer(tint_ast_fuzzer)
-# Targets back-ends individually.
-add_tint_ast_fuzzer(tint_ast_hlsl_writer_fuzzer)
-add_tint_ast_fuzzer(tint_ast_msl_writer_fuzzer)
-add_tint_ast_fuzzer(tint_ast_spv_writer_fuzzer)
-add_tint_ast_fuzzer(tint_ast_wgsl_writer_fuzzer)
-
-# Add tests.
-if (${TINT_BUILD_TESTS})
- set(TEST_SOURCES
- expression_size_test.cc
- jump_tracker_test.cc
- mutations/change_binary_operator_test.cc
- mutations/change_unary_operator_test.cc
- mutations/delete_statement_test.cc
- mutations/replace_identifier_test.cc
- mutations/wrap_unary_operator_test.cc)
-
- add_executable(tint_ast_fuzzer_unittests ${TEST_SOURCES})
-
- target_include_directories(
- tint_ast_fuzzer_unittests PRIVATE ${gmock_SOURCE_DIR}/include)
- target_link_libraries(tint_ast_fuzzer_unittests gmock_main libtint_ast_fuzzer)
- tint_default_compile_options(tint_ast_fuzzer_unittests)
- target_compile_options(tint_ast_fuzzer_unittests PRIVATE
- -Wno-global-constructors
- -Wno-weak-vtables
- -Wno-conditional-uninitialized
- -Wno-covered-switch-default
- -Wno-shadow-field-in-constructor
- -Wno-shorten-64-to-32
- -Wno-undef)
-
- target_include_directories(tint_ast_fuzzer_unittests PRIVATE ${CMAKE_BINARY_DIR})
-
- add_test(NAME tint_ast_fuzzer_unittests COMMAND tint_ast_fuzzer_unittests)
-endif ()
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/cli.cc b/src/tint/fuzzers/tint_ast_fuzzer/cli.cc
deleted file mode 100644
index 8639c59..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/cli.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-
-#include <cstring>
-#include <iostream>
-#include <limits>
-#include <sstream>
-#include <string>
-#include <utility>
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-const char* const kHelpMessage = R"(
-This is a fuzzer for the Tint compiler that works by mutating the AST.
-
-Below is a list of all supported parameters for this fuzzer. You may want to
-run it with -help=1 to check out libfuzzer parameters.
-
- -tint_enable_all_mutations=
- If `false`, the fuzzer will only apply mutations from a
- randomly selected subset of mutation types. Otherwise,
- all mutation types will be considered. This must be one
- of `true` or `false` (without `). By default it's `false`.
-
- -tint_fuzzing_target=
- Specifies the shading language to target during fuzzing.
- This must be one or a combination of `wgsl`, `spv`, `hlsl`,
- `msl` (without `) separated by commas. By default it's
- `wgsl,msl,hlsl,spv`.
-
- -tint_help
- Show this message. Note that there is also a -help=1
- parameter that will display libfuzzer's help message.
-
- -tint_mutation_batch_size=
- The number of mutations to apply in a single libfuzzer
- mutation session. This must be a numeric value that fits
- in type `uint32_t`. By default it's 5.
-)";
-
-bool HasPrefix(const char* str, const char* prefix) {
- return strncmp(str, prefix, strlen(prefix)) == 0;
-}
-
-[[noreturn]] void InvalidParam(const char* param) {
- std::cout << "Invalid value for " << param << std::endl;
- std::cout << kHelpMessage << std::endl;
- exit(1);
-}
-
-bool ParseBool(const char* value, bool* out) {
- if (!strcmp(value, "true")) {
- *out = true;
- } else if (!strcmp(value, "false")) {
- *out = false;
- } else {
- return false;
- }
- return true;
-}
-
-bool ParseUint32(const char* value, uint32_t* out) {
- auto parsed = strtoul(value, nullptr, 10);
- if (parsed > std::numeric_limits<uint32_t>::max()) {
- return false;
- }
- *out = static_cast<uint32_t>(parsed);
- return true;
-}
-
-bool ParseFuzzingTarget(const char* value, FuzzingTarget* out) {
- if (!strcmp(value, "wgsl")) {
- *out = FuzzingTarget::kWgsl;
- } else if (!strcmp(value, "spv")) {
- *out = FuzzingTarget::kSpv;
- } else if (!strcmp(value, "msl")) {
- *out = FuzzingTarget::kMsl;
- } else if (!strcmp(value, "hlsl")) {
- *out = FuzzingTarget::kHlsl;
- } else {
- return false;
- }
- return true;
-}
-
-} // namespace
-
-CliParams ParseCliParams(int* argc, char** argv) {
- CliParams cli_params;
- auto help = false;
-
- for (int i = *argc - 1; i > 0; --i) {
- auto param = argv[i];
- auto recognized_parameter = true;
-
- if (HasPrefix(param, "-tint_enable_all_mutations=")) {
- if (!ParseBool(param + sizeof("-tint_enable_all_mutations=") - 1,
- &cli_params.enable_all_mutations)) {
- InvalidParam(param);
- }
- } else if (HasPrefix(param, "-tint_mutation_batch_size=")) {
- if (!ParseUint32(param + sizeof("-tint_mutation_batch_size=") - 1,
- &cli_params.mutation_batch_size)) {
- InvalidParam(param);
- }
- } else if (HasPrefix(param, "-tint_fuzzing_target=")) {
- auto result = FuzzingTarget::kNone;
-
- std::stringstream ss(param + sizeof("-tint_fuzzing_target=") - 1);
- for (std::string value; std::getline(ss, value, ',');) {
- auto tmp = FuzzingTarget::kNone;
- if (!ParseFuzzingTarget(value.c_str(), &tmp)) {
- InvalidParam(param);
- }
- result = result | tmp;
- }
-
- if (result == FuzzingTarget::kNone) {
- InvalidParam(param);
- }
-
- cli_params.fuzzing_target = result;
- } else if (!strcmp(param, "-tint_help")) {
- help = true;
- } else {
- recognized_parameter = false;
- }
-
- if (recognized_parameter) {
- // Remove the recognized parameter from the list of all parameters by
- // swapping it with the last one. This will suppress warnings in the
- // libFuzzer about unrecognized parameters. By default, libFuzzer thinks
- // that all user-defined parameters start with two dashes. However, we are
- // forced to use a single one to make the fuzzer compatible with the
- // ClusterFuzz.
- std::swap(argv[i], argv[*argc - 1]);
- *argc -= 1;
- }
- }
-
- if (help) {
- std::cout << kHelpMessage << std::endl;
- exit(0);
- }
-
- return cli_params;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/cli.h b/src/tint/fuzzers/tint_ast_fuzzer/cli.h
deleted file mode 100644
index 575b2da..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/cli.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_CLI_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_CLI_H_
-
-#include <cstdint>
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// The backend this fuzzer will test.
-enum class FuzzingTarget {
- kNone = 0,
- kHlsl = 1 << 0,
- kMsl = 1 << 1,
- kSpv = 1 << 2,
- kWgsl = 1 << 3,
- kAll = kHlsl | kMsl | kSpv | kWgsl
-};
-
-inline FuzzingTarget operator|(FuzzingTarget a, FuzzingTarget b) {
- return static_cast<FuzzingTarget>(static_cast<int>(a) | static_cast<int>(b));
-}
-
-inline FuzzingTarget operator&(FuzzingTarget a, FuzzingTarget b) {
- return static_cast<FuzzingTarget>(static_cast<int>(a) & static_cast<int>(b));
-}
-
-/// CLI parameters accepted by the fuzzer. Type -tint_help in the CLI to see the
-/// help message
-struct CliParams {
- /// Whether to use all mutation finders or only a randomly selected subset of
- /// them.
- bool enable_all_mutations = false;
-
- /// The maximum number of mutations applied during a single mutation session
- /// (i.e. a call to `ast_fuzzer::Mutate` function).
- uint32_t mutation_batch_size = 5;
-
- /// Compiler backends we want to fuzz.
- FuzzingTarget fuzzing_target = FuzzingTarget::kAll;
-};
-
-/// @brief Parses CLI parameters.
-///
-/// This function will exit the process with non-zero return code if some
-/// parameters are invalid. This function will remove recognized parameters from
-/// `argv` and adjust `argc` accordingly.
-///
-/// @param argc - the total number of parameters.
-/// @param argv - array of all CLI parameters.
-/// @return parsed parameters.
-CliParams ParseCliParams(int* argc, char** argv);
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_CLI_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/expression_size.cc b/src/tint/fuzzers/tint_ast_fuzzer/expression_size.cc
deleted file mode 100644
index 214b19a..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/expression_size.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/expression_size.h"
-
-#include "src/tint/lang/wgsl/ast/traverse_expressions.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-ExpressionSize::ExpressionSize(const Program& program) {
- // By construction, all the children of an AST node are encountered before the
- // node itself when iterating through a program's AST nodes. Computing
- // expression sizes exploits this property: the size of a compound expression
- // is computed based on the already-computed sizes of its sub-expressions.
- for (const auto* node : program.ASTNodes().Objects()) {
- const auto* expr_ast_node = node->As<ast::Expression>();
- if (expr_ast_node == nullptr) {
- continue;
- }
- size_t expr_size = 0;
- ast::TraverseExpressions(expr_ast_node, [&](const ast::Expression* expression) {
- if (expression == expr_ast_node) {
- expr_size++;
- return ast::TraverseAction::Descend;
- }
- expr_size += expr_to_size_.at(expression);
- return ast::TraverseAction::Skip;
- });
- expr_to_size_[expr_ast_node] = expr_size;
- }
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/expression_size.h b/src/tint/fuzzers/tint_ast_fuzzer/expression_size.h
deleted file mode 100644
index 644ff92..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/expression_size.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_EXPRESSION_SIZE_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_EXPRESSION_SIZE_H_
-
-#include <unordered_map>
-
-#include "src/tint/lang/wgsl/ast/expression.h"
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// This class computes the size of the subtree rooted at each expression in a
-/// program, and allows these sizes to be subsequently queried.
-class ExpressionSize {
- public:
- /// Initializes expression size information for the given program.
- /// @param program - the program for which expression sizes will be computed;
- /// must remain in scope as long as this instance exists.
- explicit ExpressionSize(const Program& program);
-
- /// Returns the size of the subtree rooted at the given expression.
- /// @param expression - the expression whose size should be returned.
- /// @return the size of the subtree rooted at `expression`.
- size_t operator()(const ast::Expression* expression) const {
- return expr_to_size_.at(expression);
- }
-
- private:
- std::unordered_map<const ast::Expression*, size_t> expr_to_size_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_EXPRESSION_SIZE_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/expression_size_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/expression_size_test.cc
deleted file mode 100644
index 7a03a80..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/expression_size_test.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/expression_size.h"
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/lang/wgsl/ast/binary_expression.h"
-#include "src/tint/lang/wgsl/ast/expression.h"
-#include "src/tint/lang/wgsl/ast/int_literal_expression.h"
-#include "src/tint/lang/wgsl/program/program.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-TEST(ExpressionSizeTest, Basic) {
- std::string content = R"(
- fn main() {
- let a = (0 + 0) * (0 + 0);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- ExpressionSize expression_size(program);
- for (const auto* node : program.ASTNodes().Objects()) {
- const auto* expr = node->As<ast::Expression>();
- if (expr == nullptr) {
- continue;
- }
- if (expr->Is<ast::IntLiteralExpression>()) {
- ASSERT_EQ(1, expression_size(expr));
- } else {
- const auto* binary_expr = expr->As<ast::BinaryExpression>();
- ASSERT_TRUE(binary_expr != nullptr);
- switch (binary_expr->op) {
- case core::BinaryOp::kAdd:
- ASSERT_EQ(3, expression_size(expr));
- break;
- case core::BinaryOp::kMultiply:
- ASSERT_EQ(7, expression_size(expr));
- break;
- default:
- FAIL();
- }
- }
- }
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/fuzzer.cc
deleted file mode 100644
index cdb0491..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/fuzzer.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cstddef>
-#include <cstdint>
-
-#include "src/tint/fuzzers/random_generator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-#include "testing/libfuzzer/libfuzzer_exports.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-CliParams cli_params{};
-
-extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
- // Parse CLI parameters. `ParseCliParams` will call `exit` if some parameter
- // is invalid.
- cli_params = ParseCliParams(argc, *argv);
- // For some fuzz targets it is desirable to force the values of certain CLI
- // parameters after parsing.
- OverrideCliParams(cli_params);
- return 0;
-}
-
-extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data,
- size_t size,
- size_t max_size,
- unsigned seed) {
- Source::File file("test.wgsl", {reinterpret_cast<char*>(data), size});
- auto program = wgsl::reader::Parse(&file);
- if (!program.IsValid()) {
- std::cout << "Trying to mutate an invalid program:" << std::endl
- << program.Diagnostics() << std::endl;
- return 0;
- }
-
- // Run the mutator.
- RandomGenerator generator(seed);
- ProbabilityContext probability_context(&generator);
- program = Mutate(std::move(program), &probability_context, cli_params.enable_all_mutations,
- cli_params.mutation_batch_size, nullptr);
-
- if (!program.IsValid()) {
- std::cout << "Mutator produced invalid WGSL:" << std::endl
- << " seed: " << seed << std::endl
- << program.Diagnostics() << std::endl;
- return 0;
- }
-
- auto result = wgsl::writer::Generate(program, wgsl::writer::Options());
- if (result != Success) {
- std::cout << "Can't generate WGSL for a valid tint::Program:" << std::endl
- << result.Failure() << std::endl;
- return 0;
- }
-
- if (result->wgsl.size() > max_size) {
- return 0;
- }
-
- // No need to worry about the \0 here. The reason is that if \0 is included by
- // developer by mistake, it will be considered a part of the string and will
- // cause all sorts of strange bugs. Thus, unless `data` below is used as a raw
- // C string, the \0 symbol should be ignored.
- std::memcpy( // NOLINT - clang-tidy warns about lack of null termination.
- data, result->wgsl.data(), result->wgsl.size());
- return result->wgsl.size();
-}
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size == 0) {
- return 0;
- }
-
- struct Target {
- FuzzingTarget fuzzing_target;
- OutputFormat output_format;
- const char* name;
- };
-
- Target targets[] = {{FuzzingTarget::kWgsl, OutputFormat::kWGSL, "WGSL"},
- {FuzzingTarget::kHlsl, OutputFormat::kHLSL, "HLSL"},
- {FuzzingTarget::kMsl, OutputFormat::kMSL, "MSL"},
- {FuzzingTarget::kSpv, OutputFormat::kSpv, "SPV"}};
-
- for (auto target : targets) {
- if ((target.fuzzing_target & cli_params.fuzzing_target) != target.fuzzing_target) {
- continue;
- }
-
- TransformBuilder tb(data, size);
- tb.AddTransform<tint::ast::transform::Robustness>();
-
- CommonFuzzer fuzzer(InputFormat::kWGSL, target.output_format);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
-
- fuzzer.Run(data, size);
- if (fuzzer.HasErrors()) {
- std::cout << "Fuzzing " << target.name << " produced an error" << std::endl
- << fuzzer.Diagnostics() << std::endl;
- }
- }
-
- return 0;
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.cc b/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.cc
deleted file mode 100644
index 9176045..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.cc
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h"
-
-#include <cassert>
-#include <unordered_set>
-
-#include "src/tint/lang/wgsl/ast/break_statement.h"
-#include "src/tint/lang/wgsl/ast/discard_statement.h"
-#include "src/tint/lang/wgsl/ast/for_loop_statement.h"
-#include "src/tint/lang/wgsl/ast/loop_statement.h"
-#include "src/tint/lang/wgsl/ast/return_statement.h"
-#include "src/tint/lang/wgsl/ast/switch_statement.h"
-#include "src/tint/lang/wgsl/ast/while_statement.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-JumpTracker::JumpTracker(const Program& program) {
- // Consider every AST node, looking for break and return statements.
- for (auto* node : program.ASTNodes().Objects()) {
- auto* stmt = node->As<ast::Statement>();
- if (stmt == nullptr) {
- continue;
- }
- if (stmt->As<ast::BreakStatement>()) {
- // This break statement either exits a loop or a switch statement.
- // Walk up the AST until either a loop or switch statement is found. In the former case,
- // it is the innermost loop containing the break statement, and thus all the nodes
- // encountered along the way are nodes that contain a break from the innermost loop.
-
- // This records the statements encountered when walking up the AST from the break
- // statement to the innermost enclosing loop or switch statement.
- std::unordered_set<const ast::Statement*> candidate_statements;
- for (const ast::Statement* current = stmt;;
- current =
- As<sem::Statement>(program.Sem().Get(current))->Parent()->Declaration()) {
- if (current->Is<ast::ForLoopStatement>() || current->Is<ast::LoopStatement>() ||
- current->Is<ast::WhileStatement>()) {
- // A loop has been encountered, thus all that statements recorded until this
- // point contain a break from their innermost loop.
- for (auto* candidate : candidate_statements) {
- contains_break_for_innermost_loop_.insert(candidate);
- }
- break;
- }
- if (current->Is<ast::SwitchStatement>()) {
- // A switch statement has been encountered, so the break does not correspond to
- // a loop break.
- break;
- }
- candidate_statements.insert(current);
- }
- } else if (stmt->As<ast::ReturnStatement>()) {
- // Walk up the AST from the return statement, recording that every node encountered
- // along the way contains a return.
- const ast::Statement* current = stmt;
- while (true) {
- contains_return_.insert(current);
- auto* parent = program.Sem().Get(current)->Parent();
- if (parent == nullptr) {
- break;
- }
- current = parent->Declaration();
- }
- }
- }
-}
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h b/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h
deleted file mode 100644
index 617af09..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_JUMP_TRACKER_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_JUMP_TRACKER_H_
-
-#include <unordered_set>
-
-#include "src/tint/lang/wgsl/ast/statement.h"
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// This class computes information on which statements contain loop breaks and returns.
-/// It could be extended to handle other jumps, such as switch breaks and loop continues, should
-/// such information prove useful.
-class JumpTracker {
- public:
- /// Initializes jump tracking information for the given program.
- /// @param program - the program for which jumps will be tracked;
- /// must remain in scope as long as this instance exists.
- explicit JumpTracker(const Program& program);
-
- /// Indicates whether a statement contains a break statement for the innermost loop (if any).
- /// @param statement - the statement of interest.
- /// @return true if and only if the statement is, or contains, a break for the innermost
- /// enclosing loop.
- bool ContainsBreakForInnermostLoop(const ast::Statement& statement) const {
- return contains_break_for_innermost_loop_.count(&statement) > 0;
- }
-
- /// Indicates whether a statement contains a return statement.
- /// @param statement - the statement of interest.
- /// @return true if and only if the statement is, or contains, a return statement.
- bool ContainsReturn(const ast::Statement& statement) const {
- return contains_return_.count(&statement) > 0;
- }
-
- private:
- std::unordered_set<const ast::Statement*> contains_break_for_innermost_loop_;
- std::unordered_set<const ast::Statement*> contains_return_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_JUMP_TRACKER_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker_test.cc
deleted file mode 100644
index 0fdbc5a..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/jump_tracker_test.cc
+++ /dev/null
@@ -1,258 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h"
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/lang/wgsl/ast/block_statement.h"
-#include "src/tint/lang/wgsl/ast/break_statement.h"
-#include "src/tint/lang/wgsl/ast/discard_statement.h"
-#include "src/tint/lang/wgsl/ast/for_loop_statement.h"
-#include "src/tint/lang/wgsl/ast/if_statement.h"
-#include "src/tint/lang/wgsl/ast/loop_statement.h"
-#include "src/tint/lang/wgsl/ast/module.h"
-#include "src/tint/lang/wgsl/ast/return_statement.h"
-#include "src/tint/lang/wgsl/ast/switch_statement.h"
-#include "src/tint/lang/wgsl/ast/while_statement.h"
-#include "src/tint/lang/wgsl/program/program.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-TEST(JumpTrackerTest, Breaks) {
- std::string content = R"(
-fn main() {
- var x : u32;
- for (var i : i32 = 0; i < 100; i++) {
- if (i == 40) {
- {
- break;
- }
- }
- for (var j : i32 = 0; j < 10; j++) {
- loop {
- if (i > j) {
- break;
- }
- continuing {
- i++;
- j-=2;
- }
- }
- switch (j) {
- case 0: {
- if (i == j) {
- break;
- }
- i = i + 1;
- continue;
- }
- default: {
- break;
- }
- }
- }
- }
-}
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- JumpTracker jump_tracker(program);
-
- const auto* outer_loop_body =
- program.AST().Functions()[0]->body->statements[1]->As<ast::ForLoopStatement>()->body;
- const auto* first_if = outer_loop_body->statements[0]->As<ast::IfStatement>();
- const auto* first_if_body = first_if->body;
- const auto* block_in_first_if = first_if_body->statements[0]->As<ast::BlockStatement>();
- const auto* break_in_first_if = block_in_first_if->statements[0]->As<ast::BreakStatement>();
-
- const auto* innermost_loop_body = outer_loop_body->statements[1]
- ->As<ast::ForLoopStatement>()
- ->body->statements[0]
- ->As<ast::LoopStatement>()
- ->body;
- const auto* innermost_loop_if = innermost_loop_body->statements[0]->As<ast::IfStatement>();
- const auto* innermost_loop_if_body = innermost_loop_if->body;
- const auto* break_in_innermost_loop =
- innermost_loop_if_body->statements[0]->As<ast::BreakStatement>();
-
- std::unordered_set<const ast::Statement*> containing_loop_break = {
- outer_loop_body, first_if,
- first_if_body, block_in_first_if,
- break_in_first_if, innermost_loop_body,
- innermost_loop_if, innermost_loop_if_body,
- break_in_innermost_loop};
-
- for (auto* node : program.ASTNodes().Objects()) {
- auto* stmt = node->As<ast::Statement>();
- if (stmt == nullptr) {
- continue;
- }
- if (containing_loop_break.count(stmt) > 0) {
- ASSERT_TRUE(jump_tracker.ContainsBreakForInnermostLoop(*stmt));
- } else {
- ASSERT_FALSE(jump_tracker.ContainsBreakForInnermostLoop(*stmt));
- }
- }
-}
-
-TEST(JumpTrackerTest, Returns) {
- std::string content = R"(
-fn main() {
- var x : u32;
- for (var i : i32 = 0; i < 100; i++) {
- if (i == 40) {
- {
- return;
- }
- }
- for (var j : i32 = 0; j < 10; j++) {
- loop {
- if (i > j) {
- return;
- }
- continuing {
- i++;
- j-=2;
- }
- }
- switch (j) {
- case 0: {
- if (i == j) {
- break;
- }
- i = i + 1;
- continue;
- }
- default: {
- return;
- }
- }
- }
- }
-}
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- JumpTracker jump_tracker(program);
-
- const auto* function_body = program.AST().Functions()[0]->body;
- const auto* outer_loop = function_body->statements[1]->As<ast::ForLoopStatement>();
- const auto* outer_loop_body = outer_loop->body;
- const auto* first_if = outer_loop_body->statements[0]->As<ast::IfStatement>();
- const auto* first_if_body = first_if->body;
- const auto* block_in_first_if = first_if_body->statements[0]->As<ast::BlockStatement>();
- const auto* return_in_first_if = block_in_first_if->statements[0]->As<ast::ReturnStatement>();
- const auto* inner_for_loop = outer_loop_body->statements[1]->As<ast::ForLoopStatement>();
- const auto* inner_for_loop_body = inner_for_loop->body;
- const auto* innermost_loop = inner_for_loop_body->statements[0]->As<ast::LoopStatement>();
- const auto* innermost_loop_body = innermost_loop->body;
- const auto* innermost_loop_if = innermost_loop_body->statements[0]->As<ast::IfStatement>();
- const auto* innermost_loop_if_body = innermost_loop_if->body;
- const auto* return_in_innermost_loop =
- innermost_loop_if_body->statements[0]->As<ast::ReturnStatement>();
- const auto* switch_statement = inner_for_loop_body->statements[1]->As<ast::SwitchStatement>();
- const auto* default_statement = switch_statement->body[1];
- const auto* default_statement_body = default_statement->body;
- const auto* return_in_default_statement =
- default_statement_body->statements[0]->As<ast::ReturnStatement>();
-
- std::unordered_set<const ast::Statement*> containing_return = {
- function_body, outer_loop,
- outer_loop_body, first_if,
- first_if_body, block_in_first_if,
- return_in_first_if, inner_for_loop,
- inner_for_loop_body, innermost_loop,
- innermost_loop_body, innermost_loop_if,
- innermost_loop_if_body, return_in_innermost_loop,
- switch_statement, default_statement,
- default_statement_body, return_in_default_statement};
-
- for (auto* node : program.ASTNodes().Objects()) {
- auto* stmt = node->As<ast::Statement>();
- if (stmt == nullptr) {
- continue;
- }
- if (containing_return.count(stmt) > 0) {
- ASSERT_TRUE(jump_tracker.ContainsReturn(*stmt));
- } else {
- ASSERT_FALSE(jump_tracker.ContainsReturn(*stmt));
- }
- }
-}
-
-TEST(JumpTrackerTest, WhileLoop) {
- std::string content = R"(
-fn main() {
- var x : u32;
- x = 0;
- while (x < 100) {
- if (x > 50) {
- break;
- }
- x = x + 1;
- }
-}
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- JumpTracker jump_tracker(program);
-
- const auto* while_loop_body =
- program.AST().Functions()[0]->body->statements[2]->As<ast::WhileStatement>()->body;
- const auto* if_statement = while_loop_body->statements[0]->As<ast::IfStatement>();
- const auto* if_statement_body = if_statement->body;
- const auto* break_in_if = if_statement_body->statements[0]->As<ast::BreakStatement>();
-
- std::unordered_set<const ast::Statement*> containing_loop_break = {
- while_loop_body, if_statement, if_statement_body, break_in_if};
-
- for (auto* node : program.ASTNodes().Objects()) {
- auto* stmt = node->As<ast::Statement>();
- if (stmt == nullptr) {
- continue;
- }
- if (containing_loop_break.count(stmt) > 0) {
- ASSERT_TRUE(jump_tracker.ContainsBreakForInnermostLoop(*stmt));
- } else {
- ASSERT_FALSE(jump_tracker.ContainsBreakForInnermostLoop(*stmt));
- }
- }
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation.cc
deleted file mode 100644
index b40adb6..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-Mutation::~Mutation() = default;
-
-std::unique_ptr<Mutation> Mutation::FromMessage(const protobufs::Mutation& message) {
- switch (message.mutation_case()) {
- case protobufs::Mutation::kChangeUnaryOperator:
- return std::make_unique<MutationChangeUnaryOperator>(message.change_unary_operator());
- case protobufs::Mutation::kReplaceIdentifier:
- return std::make_unique<MutationReplaceIdentifier>(message.replace_identifier());
- case protobufs::Mutation::kChangeBinaryOperator:
- return std::make_unique<MutationChangeBinaryOperator>(message.change_binary_operator());
- case protobufs::Mutation::kDeleteStatement:
- return std::make_unique<MutationDeleteStatement>(message.delete_statement());
- case protobufs::Mutation::kWrapUnaryOperator:
- return std::make_unique<MutationWrapUnaryOperator>(message.wrap_unary_operator());
- case protobufs::Mutation::MUTATION_NOT_SET:
- assert(false && "Mutation is not set");
- break;
- }
- return nullptr;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation.h
deleted file mode 100644
index f2b0cce..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_H_
-
-#include <memory>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.h"
-
-#include "src/tint/lang/wgsl/program/clone_context.h"
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// The base class for all the mutations in the fuzzer. Children must override
-/// three methods:
-/// - `IsApplicable` - checks whether it is possible to apply the mutation
-/// in a manner that will lead to a valid program.
-/// - `Apply` - applies the mutation.
-/// - `ToMessage` - converts the mutation data into a protobuf message.
-class Mutation {
- public:
- /// Virtual destructor.
- virtual ~Mutation();
-
- /// @brief Determines whether this mutation is applicable to the `program`.
- ///
- /// @param program - the program this mutation will be applied to. The program
- /// must be valid.
- /// @param node_id_map - the map from `tint::ast::` nodes to their ids.
- /// @return `true` if `Apply` method can be called without breaking the
- /// semantics of the `program`.
- /// @return `false` otherwise.
- virtual bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const = 0;
-
- /// @brief Applies this mutation to the `clone_context`.
- ///
- /// Precondition: `IsApplicable` must return `true` when invoked on the same
- /// `node_id_map` and `clone_context.src` instance of `tint::Program`. A new
- /// `tint::Program` that arises in `clone_context` must be valid.
- ///
- /// @param node_id_map - the map from `tint::ast::` nodes to their ids.
- /// @param clone_context - the context that will clone the program with some
- /// changes introduced by this mutation.
- /// @param new_node_id_map - this map will store ids for the mutated and
- /// cloned program. This argument cannot be a `nullptr` nor can it point
- /// to the same object as `node_id_map`.
- virtual void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const = 0;
-
- /// @return a protobuf message for this mutation.
- virtual protobufs::Mutation ToMessage() const = 0;
-
- /// @brief Converts a protobuf message into the mutation instance.
- ///
- /// @param message - a protobuf message.
- /// @return the instance of this class.
- static std::unique_ptr<Mutation> FromMessage(const protobufs::Mutation& message);
-};
-
-using MutationList = std::vector<std::unique_ptr<Mutation>>;
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.cc
deleted file mode 100644
index d6d3d90..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationFinder::~MutationFinder() = default;
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h
deleted file mode 100644
index 6a34c0b..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDER_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDER_H_
-
-#include <memory>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Instances of this class traverse the `tint::Program`, looking for
-/// opportunities to apply mutations and return them to the caller.
-///
-/// Ideally, the behaviour of this class (precisely, its `FindMutations` method)
-/// should not be probabilistic. This is useful when mutation finders are used
-/// for test case reduction, because it enables the test case reducer to
-/// systematically explore all available mutations. There may be some
-/// exceptions, however. For example, if a huge number of mutations is returned,
-/// it would make sense to apply only a probabilistically selected subset of
-/// them.
-class MutationFinder {
- public:
- /// Virtual destructor.
- virtual ~MutationFinder();
-
- /// @brief Traverses the `program`, looking for opportunities to apply
- /// mutations.
- ///
- /// @param program - the program being fuzzed.
- /// @param node_id_map - a map from `tint::ast::` nodes in the `program` to
- /// their unique ids.
- /// @param probability_context - determines various probabilistic stuff in the
- /// mutator. This should ideally be used as less as possible.
- /// @return all the found mutations.
- virtual MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const = 0;
-
- /// @brief Compute a probability of applying a single mutation, returned by
- /// this class.
- ///
- /// @param probability_context - contains information about various
- /// non-deterministic stuff in the fuzzer.
- /// @return a number in the range [0; 100] which is a chance of applying a
- /// mutation.
- virtual uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const = 0;
-};
-
-using MutationFinderList = std::vector<std::unique_ptr<MutationFinder>>;
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDER_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.cc
deleted file mode 100644
index a28115b..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.h"
-
-#include <memory>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h"
-#include "src/tint/lang/wgsl/ast/binary_expression.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationList MutationFinderChangeBinaryOperators::FindMutations(
- const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const {
- MutationList result;
-
- // Go through each binary expression in the AST and add a mutation that
- // replaces its operator with some other type-compatible operator.
-
- const std::vector<core::BinaryOp> all_binary_operators = {core::BinaryOp::kAnd,
- core::BinaryOp::kOr,
- core::BinaryOp::kXor,
- core::BinaryOp::kLogicalAnd,
- core::BinaryOp::kLogicalOr,
- core::BinaryOp::kEqual,
- core::BinaryOp::kNotEqual,
- core::BinaryOp::kLessThan,
- core::BinaryOp::kGreaterThan,
- core::BinaryOp::kLessThanEqual,
- core::BinaryOp::kGreaterThanEqual,
- core::BinaryOp::kShiftLeft,
- core::BinaryOp::kShiftRight,
- core::BinaryOp::kAdd,
- core::BinaryOp::kSubtract,
- core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide,
- core::BinaryOp::kModulo};
-
- for (const auto* node : program.ASTNodes().Objects()) {
- const auto* binary_expr = As<ast::BinaryExpression>(node);
- if (!binary_expr) {
- continue;
- }
-
- // Get vector of all operators this could be replaced with.
- std::vector<core::BinaryOp> allowed_replacements;
- for (auto candidate_op : all_binary_operators) {
- if (MutationChangeBinaryOperator::CanReplaceBinaryOperator(program, *binary_expr,
- candidate_op)) {
- allowed_replacements.push_back(candidate_op);
- }
- }
-
- if (!allowed_replacements.empty()) {
- // Choose an available replacement operator at random.
- const core::BinaryOp replacement =
- allowed_replacements[probability_context->GetRandomIndex(allowed_replacements)];
- // Add a mutation according to the chosen replacement.
- result.push_back(std::make_unique<MutationChangeBinaryOperator>(
- node_id_map->GetId(binary_expr), replacement));
- }
- }
-
- return result;
-}
-
-uint32_t MutationFinderChangeBinaryOperators::GetChanceOfApplyingMutation(
- ProbabilityContext* probability_context) const {
- return probability_context->GetChanceOfChangingBinaryOperators();
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.h
deleted file mode 100644
index 6550173..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_BINARY_OPERATORS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_BINARY_OPERATORS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Looks for opportunities to apply `MutationChangeBinaryOperator`.
-///
-/// Concretely, for each binary expression in the module, tries to replace it
-/// with a different, type-compatible operator.
-class MutationFinderChangeBinaryOperators : public MutationFinder {
- public:
- MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const override;
- uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const override;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_BINARY_OPERATORS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc
deleted file mode 100644
index 9cfa04c..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.h"
-
-#include <memory>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/core/type/reference.h"
-#include "src/tint/lang/wgsl/ast/unary_op_expression.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationList MutationFinderChangeUnaryOperators::FindMutations(
- const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* /*unused*/) const {
- MutationList result;
-
- // Iterate through all AST nodes and for each valid unary op expression node,
- // try to replace the node's unary operator.
- for (const auto* node : program.ASTNodes().Objects()) {
- const auto* unary_expr = tint::As<ast::UnaryOpExpression>(node);
-
- // Transformation applies only when the node represents a valid unary
- // expression.
- if (!unary_expr) {
- continue;
- }
-
- // Get the type of the unary expression.
- const auto* type = program.Sem().Get(unary_expr)->Type();
- const auto* basic_type = type->Is<core::type::Reference>()
- ? type->As<core::type::Reference>()->StoreType()
- : type;
-
- // Only signed integer or vector of signed integer can be mutated.
- if (!basic_type->is_signed_integer_scalar_or_vector()) {
- continue;
- }
-
- // Only complement and negation operators can be swapped.
- if (!(unary_expr->op == core::UnaryOp::kComplement ||
- unary_expr->op == core::UnaryOp::kNegation)) {
- continue;
- }
-
- result.push_back(std::make_unique<MutationChangeUnaryOperator>(
- node_id_map->GetId(unary_expr),
- MutationChangeUnaryOperator::ToggleOperator(unary_expr->op)));
- }
-
- return result;
-}
-
-uint32_t MutationFinderChangeUnaryOperators::GetChanceOfApplyingMutation(
- ProbabilityContext* probability_context) const {
- return probability_context->GetChanceOfChangingUnaryOperators();
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.h
deleted file mode 100644
index 68322e2..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_UNARY_OPERATORS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_UNARY_OPERATORS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Looks for opportunities to apply
-/// `MutationFinderChangeUnaryOperators`.
-///
-/// Concretely, for each unary expression in the module, try to change its
-/// operator with a permitted one.
-class MutationFinderChangeUnaryOperators : public MutationFinder {
- public:
- MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const override;
- uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const override;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_CHANGE_UNARY_OPERATORS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.cc
deleted file mode 100644
index b2a650e..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.h"
-
-#include <memory>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-#include "src/tint/lang/wgsl/sem/value_expression.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationList MutationFinderDeleteStatements::FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* /*unused*/) const {
- MutationList result;
-
- JumpTracker jump_tracker(program);
-
- // Consider every statement node in the AST.
- for (auto* node : program.ASTNodes().Objects()) {
- auto* statement_node = tint::As<ast::Statement>(node);
-
- if (!statement_node) {
- continue;
- }
-
- const auto* statement_sem_node =
- tint::As<sem::Statement>(program.Sem().Get(statement_node));
-
- // Semantic information for the node is required in order to delete it.
- if (!statement_sem_node) {
- continue;
- }
-
- // Check that this kind of statement can be deleted.
- if (!MutationDeleteStatement::CanBeDeleted(*statement_node, program, jump_tracker)) {
- continue;
- }
-
- result.push_back(
- std::make_unique<MutationDeleteStatement>(node_id_map->GetId(statement_node)));
- }
-
- return result;
-}
-
-uint32_t MutationFinderDeleteStatements::GetChanceOfApplyingMutation(
- ProbabilityContext* probability_context) const {
- return probability_context->GetChanceOfDeletingStatements();
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.h
deleted file mode 100644
index 89e9346..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_DELETE_STATEMENTS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_DELETE_STATEMENTS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Looks for opportunities to apply
-/// `MutationFinderDeleteStatements`.
-///
-/// Considers statements for deletion if their deletion would not make the module invalid.
-class MutationFinderDeleteStatements : public MutationFinder {
- public:
- MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const override;
- uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const override;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_DELETE_STATEMENTS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.cc
deleted file mode 100644
index ab7a596..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.h"
-
-#include <memory>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-
-#include "src/tint/lang/wgsl/sem/statement.h"
-#include "src/tint/lang/wgsl/sem/value_expression.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationList MutationFinderReplaceIdentifiers::FindMutations(
- const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const {
- MutationList result;
-
- // Go through each variable in the AST and for each user of that variable, try
- // to replace it with some other variable usage.
-
- for (const auto* node : program.SemNodes().Objects()) {
- const auto* sem_variable = tint::As<sem::Variable>(node);
- if (!sem_variable) {
- continue;
- }
-
- // Iterate over all users of `sem_variable`.
- for (const auto* user : sem_variable->Users()) {
- // Get all variables that can be used to replace the `user` of
- // `sem_variable`.
- auto candidate_variables =
- util::GetAllVarsInScope(program, user->Stmt(), [user](const sem::Variable* var) {
- return var != user->Variable() && var->Type() == user->Type();
- });
-
- if (candidate_variables.empty()) {
- // No suitable replacements have been found.
- continue;
- }
-
- const auto* replacement =
- candidate_variables[probability_context->GetRandomIndex(candidate_variables)];
-
- result.push_back(std::make_unique<MutationReplaceIdentifier>(
- node_id_map->GetId(user->Declaration()),
- node_id_map->GetId(replacement->Declaration())));
- }
- }
-
- return result;
-}
-
-uint32_t MutationFinderReplaceIdentifiers::GetChanceOfApplyingMutation(
- ProbabilityContext* probability_context) const {
- return probability_context->GetChanceOfReplacingIdentifiers();
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.h
deleted file mode 100644
index e3867aa..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_REPLACE_IDENTIFIERS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_REPLACE_IDENTIFIERS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Looks for opportunities to apply `MutationReplaceIdentifier`.
-///
-/// Concretely, for each variable in the module, tries to replace its users with
-/// the uses of some other variables.
-class MutationFinderReplaceIdentifiers : public MutationFinder {
- public:
- MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const override;
- uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const override;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_REPLACE_IDENTIFIERS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc
deleted file mode 100644
index 34a0df0..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.h"
-
-#include <memory>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/expression_size.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-#include "src/tint/lang/wgsl/sem/value_expression.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-namespace {
-const size_t kMaxExpressionSize = 50;
-} // namespace
-
-MutationList MutationFinderWrapUnaryOperators::FindMutations(
- const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const {
- MutationList result;
-
- ExpressionSize expression_size(program);
-
- // Iterate through all ast nodes and for each expression node, try to wrap
- // the inside a valid unary operator based on the type of the expression.
- for (const auto* node : program.ASTNodes().Objects()) {
- const auto* expr_ast_node = tint::As<ast::Expression>(node);
-
- // Transformation applies only when the node represents a valid expression.
- if (!expr_ast_node) {
- continue;
- }
-
- if (expression_size(expr_ast_node) > kMaxExpressionSize) {
- continue;
- }
-
- const auto* expr_sem_node = program.Sem().GetVal(expr_ast_node);
-
- // Transformation applies only when the semantic node for the given
- // expression is present.
- if (!expr_sem_node) {
- continue;
- }
-
- std::vector<core::UnaryOp> valid_operators =
- MutationWrapUnaryOperator::GetValidUnaryWrapper(*expr_sem_node);
-
- // Transformation only applies when there are available unary operators
- // for the given expression.
- if (valid_operators.empty()) {
- continue;
- }
-
- core::UnaryOp unary_op_wrapper =
- valid_operators[probability_context->GetRandomIndex(valid_operators)];
-
- result.push_back(std::make_unique<MutationWrapUnaryOperator>(
- node_id_map->GetId(expr_ast_node), node_id_map->TakeFreshId(), unary_op_wrapper));
- }
-
- return result;
-}
-
-uint32_t MutationFinderWrapUnaryOperators::GetChanceOfApplyingMutation(
- ProbabilityContext* probability_context) const {
- return probability_context->GetChanceOfWrappingUnaryOperators();
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.h b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.h
deleted file mode 100644
index 25e9ef4..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_WRAP_UNARY_OPERATORS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_WRAP_UNARY_OPERATORS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Looks for opportunities to apply
-/// `MutationFinderWrapUnaryOperators`.
-///
-/// For each expression in the module, try to wrap it within
-/// a unary operator.
-class MutationFinderWrapUnaryOperators : public MutationFinder {
- public:
- MutationList FindMutations(const tint::Program& program,
- NodeIdMap* node_id_map,
- ProbabilityContext* probability_context) const override;
- uint32_t GetChanceOfApplyingMutation(ProbabilityContext* probability_context) const override;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATION_FINDERS_WRAP_UNARY_OPERATORS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc
deleted file mode 100644
index 02cd113..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc
+++ /dev/null
@@ -1,474 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h"
-
-#include <utility>
-
-#include "src/tint/lang/core/type/bool.h"
-#include "src/tint/lang/core/type/reference.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-namespace {
-
-bool IsSuitableForShift(const core::type::Type* lhs_type, const core::type::Type* rhs_type) {
- // `a << b` requires b to be an unsigned scalar or vector, and `a` to be an
- // integer scalar or vector with the same width as `b`. Similar for `a >> b`.
-
- if (rhs_type->is_unsigned_integer_scalar()) {
- return lhs_type->is_integer_scalar();
- }
- if (rhs_type->is_unsigned_integer_vector()) {
- return lhs_type->is_unsigned_integer_vector();
- }
- return false;
-}
-
-bool CanReplaceAddSubtractWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- // The program is assumed to be well-typed, so this method determines when
- // 'new_operator' can be used as a type-preserving replacement in an '+' or
- // '-' expression.
- switch (new_operator) {
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- // '+' and '-' are fully type compatible.
- return true;
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kXor:
- // These operators do not have a mixed vector-scalar form, and only work
- // on integer types.
- return lhs_type == rhs_type && lhs_type->is_integer_scalar_or_vector();
- case core::BinaryOp::kMultiply:
- // '+' and '*' are largely type-compatible, but for matrices they are only
- // type-compatible if the matrices are square.
- return !lhs_type->is_float_matrix() || lhs_type->is_square_float_matrix();
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- // '/' is not defined for matrices.
- return lhs_type->is_numeric_scalar_or_vector() &&
- rhs_type->is_numeric_scalar_or_vector();
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return IsSuitableForShift(lhs_type, rhs_type);
- default:
- return false;
- }
-}
-
-bool CanReplaceMultiplyWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- // The program is assumed to be well-typed, so this method determines when
- // 'new_operator' can be used as a type-preserving replacement in a '*'
- // expression.
- switch (new_operator) {
- case core::BinaryOp::kMultiply:
- return true;
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- // '*' is type-compatible with '+' and '-' for square matrices, and for
- // numeric scalars/vectors.
- if (lhs_type->is_square_float_matrix() && rhs_type->is_square_float_matrix()) {
- return true;
- }
- return lhs_type->is_numeric_scalar_or_vector() &&
- rhs_type->is_numeric_scalar_or_vector();
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kXor:
- // These operators require homogeneous integer types.
- return lhs_type == rhs_type && lhs_type->is_integer_scalar_or_vector();
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- // '/' is not defined for matrices.
- return lhs_type->is_numeric_scalar_or_vector() &&
- rhs_type->is_numeric_scalar_or_vector();
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return IsSuitableForShift(lhs_type, rhs_type);
- default:
- return false;
- }
-}
-
-bool CanReplaceDivideOrModuloWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- // The program is assumed to be well-typed, so this method determines when
- // 'new_operator' can be used as a type-preserving replacement in a '/'
- // expression.
- switch (new_operator) {
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- case core::BinaryOp::kMultiply:
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- // These operators work in all contexts where '/' works.
- return true;
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kXor:
- // These operators require homogeneous integer types.
- return lhs_type == rhs_type && lhs_type->is_integer_scalar_or_vector();
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return IsSuitableForShift(lhs_type, rhs_type);
- default:
- return false;
- }
-}
-
-bool CanReplaceLogicalAndLogicalOrWith(core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kLogicalAnd:
- case core::BinaryOp::kLogicalOr:
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kEqual:
- case core::BinaryOp::kNotEqual:
- // These operators all work whenever '&&' and '||' work.
- return true;
- default:
- return false;
- }
-}
-
-bool CanReplaceAndOrWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- // '&' and '|' work in all the same contexts.
- return true;
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- case core::BinaryOp::kMultiply:
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- case core::BinaryOp::kXor:
- // '&' and '|' can be applied to booleans. In all other contexts,
- // integer numeric operators work.
- return !lhs_type->is_bool_scalar_or_vector();
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return IsSuitableForShift(lhs_type, rhs_type);
- case core::BinaryOp::kLogicalAnd:
- case core::BinaryOp::kLogicalOr:
- // '&' and '|' can be applied to booleans, and for boolean scalar
- // scalar contexts, their logical counterparts work.
- return lhs_type->Is<core::type::Bool>();
- case core::BinaryOp::kEqual:
- case core::BinaryOp::kNotEqual:
- // '&' and '|' can be applied to booleans, and in these contexts equality
- // comparison operators also work.
- return lhs_type->is_bool_scalar_or_vector();
- default:
- return false;
- }
-}
-
-bool CanReplaceXorWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- case core::BinaryOp::kMultiply:
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kXor:
- // '^' only works on integer types, and in any such context, all other
- // integer operators also work.
- return true;
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return IsSuitableForShift(lhs_type, rhs_type);
- default:
- return false;
- }
-}
-
-bool CanReplaceShiftLeftShiftRightWith(const core::type::Type* lhs_type,
- const core::type::Type* rhs_type,
- core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- // These operators are type-compatible.
- return true;
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- case core::BinaryOp::kMultiply:
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- case core::BinaryOp::kXor:
- // Shift operators allow mixing of signed and unsigned arguments, but in
- // the case where the arguments are homogeneous, they are type-compatible
- // with other numeric operators.
- return lhs_type == rhs_type;
- default:
- return false;
- }
-}
-
-bool CanReplaceEqualNotEqualWith(const core::type::Type* lhs_type, core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kEqual:
- case core::BinaryOp::kNotEqual:
- // These operators are type-compatible.
- return true;
- case core::BinaryOp::kLessThan:
- case core::BinaryOp::kLessThanEqual:
- case core::BinaryOp::kGreaterThan:
- case core::BinaryOp::kGreaterThanEqual:
- // An equality comparison between numeric types can be changed to an
- // ordered comparison.
- return lhs_type->is_numeric_scalar_or_vector();
- case core::BinaryOp::kLogicalAnd:
- case core::BinaryOp::kLogicalOr:
- // An equality comparison between boolean scalars can be turned into a
- // logical operation.
- return lhs_type->Is<core::type::Bool>();
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- // An equality comparison between boolean scalars or vectors can be turned
- // into a component-wise non-short-circuit logical operation.
- return lhs_type->is_bool_scalar_or_vector();
- default:
- return false;
- }
-}
-
-bool CanReplaceLessThanLessThanEqualGreaterThanGreaterThanEqualWith(core::BinaryOp new_operator) {
- switch (new_operator) {
- case core::BinaryOp::kEqual:
- case core::BinaryOp::kNotEqual:
- case core::BinaryOp::kLessThan:
- case core::BinaryOp::kLessThanEqual:
- case core::BinaryOp::kGreaterThan:
- case core::BinaryOp::kGreaterThanEqual:
- // Ordered comparison operators can be interchanged, and equality
- // operators can be used in their place.
- return true;
- default:
- return false;
- }
-}
-} // namespace
-
-MutationChangeBinaryOperator::MutationChangeBinaryOperator(
- protobufs::MutationChangeBinaryOperator message)
- : message_(std::move(message)) {}
-
-MutationChangeBinaryOperator::MutationChangeBinaryOperator(uint32_t binary_expr_id,
- core::BinaryOp new_operator) {
- message_.set_binary_expr_id(binary_expr_id);
- message_.set_new_operator(static_cast<uint32_t>(new_operator));
-}
-
-bool MutationChangeBinaryOperator::CanReplaceBinaryOperator(
- const Program& program,
- const ast::BinaryExpression& binary_expr,
- core::BinaryOp new_operator) {
- if (new_operator == binary_expr.op) {
- // An operator should not be replaced with itself, as this would be a no-op.
- return false;
- }
-
- // Get the types of the operators.
- const auto* lhs_type = program.Sem().GetVal(binary_expr.lhs)->Type();
- const auto* rhs_type = program.Sem().GetVal(binary_expr.rhs)->Type();
-
- // If these are reference types, unwrap them to get the pointee type.
- const core::type::Type* lhs_basic_type =
- lhs_type->Is<core::type::Reference>() ? lhs_type->As<core::type::Reference>()->StoreType()
- : lhs_type;
- const core::type::Type* rhs_basic_type =
- rhs_type->Is<core::type::Reference>() ? rhs_type->As<core::type::Reference>()->StoreType()
- : rhs_type;
-
- switch (binary_expr.op) {
- case core::BinaryOp::kAdd:
- case core::BinaryOp::kSubtract:
- return CanReplaceAddSubtractWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kMultiply:
- return CanReplaceMultiplyWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kDivide:
- case core::BinaryOp::kModulo:
- return CanReplaceDivideOrModuloWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kAnd:
- case core::BinaryOp::kOr:
- return CanReplaceAndOrWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kXor:
- return CanReplaceXorWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kShiftLeft:
- case core::BinaryOp::kShiftRight:
- return CanReplaceShiftLeftShiftRightWith(lhs_basic_type, rhs_basic_type, new_operator);
- case core::BinaryOp::kLogicalAnd:
- case core::BinaryOp::kLogicalOr:
- return CanReplaceLogicalAndLogicalOrWith(new_operator);
- case core::BinaryOp::kEqual:
- case core::BinaryOp::kNotEqual:
- return CanReplaceEqualNotEqualWith(lhs_basic_type, new_operator);
- case core::BinaryOp::kLessThan:
- case core::BinaryOp::kLessThanEqual:
- case core::BinaryOp::kGreaterThan:
- case core::BinaryOp::kGreaterThanEqual:
- return CanReplaceLessThanLessThanEqualGreaterThanGreaterThanEqualWith(new_operator);
- assert(false && "Unreachable");
- return false;
- }
-}
-
-bool MutationChangeBinaryOperator::IsApplicable(const Program& program,
- const NodeIdMap& node_id_map) const {
- const auto* binary_expr_node =
- As<ast::BinaryExpression>(node_id_map.GetNode(message_.binary_expr_id()));
- if (binary_expr_node == nullptr) {
- // Either the id does not exist, or does not correspond to a binary
- // expression.
- return false;
- }
- // Check whether the replacement is acceptable.
- const auto new_operator = static_cast<core::BinaryOp>(message_.new_operator());
- return CanReplaceBinaryOperator(program, *binary_expr_node, new_operator);
-}
-
-void MutationChangeBinaryOperator::Apply(const NodeIdMap& node_id_map,
- program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const {
- // Get the node whose operator is to be replaced.
- const auto* binary_expr_node =
- As<ast::BinaryExpression>(node_id_map.GetNode(message_.binary_expr_id()));
-
- // Clone the binary expression, with the appropriate new operator.
- const ast::BinaryExpression* cloned_replacement;
- switch (static_cast<core::BinaryOp>(message_.new_operator())) {
- case core::BinaryOp::kAnd:
- cloned_replacement = clone_context.dst->And(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kOr:
- cloned_replacement = clone_context.dst->Or(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kXor:
- cloned_replacement = clone_context.dst->Xor(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kLogicalAnd:
- cloned_replacement =
- clone_context.dst->LogicalAnd(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kLogicalOr:
- cloned_replacement =
- clone_context.dst->LogicalOr(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kEqual:
- cloned_replacement =
- clone_context.dst->Equal(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kNotEqual:
- cloned_replacement =
- clone_context.dst->NotEqual(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kLessThan:
- cloned_replacement =
- clone_context.dst->LessThan(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kGreaterThan:
- cloned_replacement =
- clone_context.dst->GreaterThan(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kLessThanEqual:
- cloned_replacement =
- clone_context.dst->LessThanEqual(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kGreaterThanEqual:
- cloned_replacement =
- clone_context.dst->GreaterThanEqual(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kShiftLeft:
- cloned_replacement = clone_context.dst->Shl(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kShiftRight:
- cloned_replacement = clone_context.dst->Shr(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kAdd:
- cloned_replacement = clone_context.dst->Add(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kSubtract:
- cloned_replacement = clone_context.dst->Sub(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kMultiply:
- cloned_replacement = clone_context.dst->Mul(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kDivide:
- cloned_replacement = clone_context.dst->Div(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- case core::BinaryOp::kModulo:
- cloned_replacement = clone_context.dst->Mod(clone_context.Clone(binary_expr_node->lhs),
- clone_context.Clone(binary_expr_node->rhs));
- break;
- }
- // Set things up so that the original binary expression will be replaced with
- // its clone, and update the id mapping.
- clone_context.Replace(binary_expr_node, cloned_replacement);
- new_node_id_map->Add(cloned_replacement, message_.binary_expr_id());
-}
-
-protobufs::Mutation MutationChangeBinaryOperator::ToMessage() const {
- protobufs::Mutation mutation;
- *mutation.mutable_change_binary_operator() = message_;
- return mutation;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h
deleted file mode 100644
index a052bc4..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_BINARY_OPERATOR_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_BINARY_OPERATOR_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-
-#include "src/tint/lang/wgsl/ast/binary_expression.h"
-#include "src/tint/lang/wgsl/program/program.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @see MutationChangeBinaryOperator::Apply
-class MutationChangeBinaryOperator : public Mutation {
- public:
- /// @brief Constructs an instance of this mutation from a protobuf message.
- /// @param message - protobuf message
- explicit MutationChangeBinaryOperator(protobufs::MutationChangeBinaryOperator message);
-
- /// @brief Constructor.
- /// @param binary_expr_id - the id of a binary expression.
- /// @param new_operator - a new binary operator to replace the one used in the
- /// expression.
- MutationChangeBinaryOperator(uint32_t binary_expr_id, core::BinaryOp new_operator);
-
- /// @copybrief Mutation::IsApplicable
- ///
- /// The mutation is applicable iff:
- /// - `binary_expr_id` is a valid id of an `ast::BinaryExpression`.
- /// - `new_operator` is type-compatible with the arguments of the binary
- /// expression.
- ///
- /// @copydetails Mutation::IsApplicable
- bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const override;
-
- /// @copybrief Mutation::Apply
- ///
- /// Replaces binary operator in the binary expression corresponding to
- /// `binary_expr_id` with `new_operator`.
- ///
- /// @copydetails Mutation::Apply
- void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const override;
-
- protobufs::Mutation ToMessage() const override;
-
- /// @brief Determines whether replacing the operator of a binary expression
- /// with another operator would preserve well-typedness.
- /// @param program - the program that owns the binary expression.
- /// @param binary_expr - the binary expression being considered for mutation.
- /// @param new_operator - a new binary operator to be checked as a candidate
- /// replacement for the binary expression's operator.
- /// @return `true` if and only if the replacement would be well-typed.
- static bool CanReplaceBinaryOperator(const Program& program,
- const ast::BinaryExpression& binary_expr,
- core::BinaryOp new_operator);
-
- private:
- protobufs::MutationChangeBinaryOperator message_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_BINARY_OPERATOR_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator_test.cc
deleted file mode 100644
index af8f240..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator_test.cc
+++ /dev/null
@@ -1,642 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.h"
-
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-std::string OpToString(core::BinaryOp op) {
- switch (op) {
- case core::BinaryOp::kAnd:
- return "&";
- case core::BinaryOp::kOr:
- return "|";
- case core::BinaryOp::kXor:
- return "^";
- case core::BinaryOp::kLogicalAnd:
- return "&&";
- case core::BinaryOp::kLogicalOr:
- return "||";
- case core::BinaryOp::kEqual:
- return "==";
- case core::BinaryOp::kNotEqual:
- return "!=";
- case core::BinaryOp::kLessThan:
- return "<";
- case core::BinaryOp::kGreaterThan:
- return ">";
- case core::BinaryOp::kLessThanEqual:
- return "<=";
- case core::BinaryOp::kGreaterThanEqual:
- return ">=";
- case core::BinaryOp::kShiftLeft:
- return "<<";
- case core::BinaryOp::kShiftRight:
- return ">>";
- case core::BinaryOp::kAdd:
- return "+";
- case core::BinaryOp::kSubtract:
- return "-";
- case core::BinaryOp::kMultiply:
- return "*";
- case core::BinaryOp::kDivide:
- return "/";
- case core::BinaryOp::kModulo:
- return "%";
- }
- TINT_UNREACHABLE() << "unhandled BinaryOp: " << op;
- return "<error>";
-}
-
-TEST(ChangeBinaryOperatorTest, NotApplicable_Simple) {
- std::string content = R"(
- fn main() {
- let a : i32 = 1 + 2;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements;
-
- const auto* a_var = main_fn_stmts[0]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(a_var, nullptr);
-
- auto a_var_id = node_id_map.GetId(a_var);
-
- const auto* sum_expr = a_var->initializer->As<ast::BinaryExpression>();
- ASSERT_NE(sum_expr, nullptr);
-
- auto sum_expr_id = node_id_map.GetId(sum_expr);
- ASSERT_NE(sum_expr_id, 0);
-
- // binary_expr_id is invalid.
- EXPECT_FALSE(MutationChangeBinaryOperator(0, core::BinaryOp::kSubtract)
- .IsApplicable(program, node_id_map));
-
- // binary_expr_id is not a binary expression.
- EXPECT_FALSE(MutationChangeBinaryOperator(a_var_id, core::BinaryOp::kSubtract)
- .IsApplicable(program, node_id_map));
-
- // new_operator is applicable to the argument types.
- EXPECT_FALSE(MutationChangeBinaryOperator(0, core::BinaryOp::kLogicalAnd)
- .IsApplicable(program, node_id_map));
-
- // new_operator does not have the right result type.
- EXPECT_FALSE(MutationChangeBinaryOperator(0, core::BinaryOp::kLessThan)
- .IsApplicable(program, node_id_map));
-}
-
-TEST(ChangeBinaryOperatorTest, Applicable_Simple) {
- std::string shader = R"(fn main() {
- let a : i32 = (1 + 2);
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements;
-
- const auto* a_var = main_fn_stmts[0]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(a_var, nullptr);
-
- const auto* sum_expr = a_var->initializer->As<ast::BinaryExpression>();
- ASSERT_NE(sum_expr, nullptr);
-
- auto sum_expr_id = node_id_map.GetId(sum_expr);
- ASSERT_NE(sum_expr_id, 0);
-
- ASSERT_TRUE(MaybeApplyMutation(
- program, MutationChangeBinaryOperator(sum_expr_id, core::BinaryOp::kSubtract), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- let a : i32 = (1 - 2);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-void CheckMutations(const std::string& lhs_type,
- const std::string& rhs_type,
- const std::string& result_type,
- core::BinaryOp original_operator,
- const std::unordered_set<core::BinaryOp>& allowed_replacement_operators) {
- std::stringstream shader;
- shader << "fn foo(a : " << lhs_type << ", b : " << rhs_type + ") {\n"
- << " let r : " << result_type << " = (a " + OpToString(original_operator)
- << " b);\n}\n";
-
- const std::vector<core::BinaryOp> all_operators = {core::BinaryOp::kAnd,
- core::BinaryOp::kOr,
- core::BinaryOp::kXor,
- core::BinaryOp::kLogicalAnd,
- core::BinaryOp::kLogicalOr,
- core::BinaryOp::kEqual,
- core::BinaryOp::kNotEqual,
- core::BinaryOp::kLessThan,
- core::BinaryOp::kGreaterThan,
- core::BinaryOp::kLessThanEqual,
- core::BinaryOp::kGreaterThanEqual,
- core::BinaryOp::kShiftLeft,
- core::BinaryOp::kShiftRight,
- core::BinaryOp::kAdd,
- core::BinaryOp::kSubtract,
- core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide,
- core::BinaryOp::kModulo};
-
- for (auto new_operator : all_operators) {
- Source::File file("test.wgsl", shader.str());
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& stmts = program.AST().Functions()[0]->body->statements;
-
- const auto* r_var = stmts[0]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(r_var, nullptr);
-
- const auto* binary_expr = r_var->initializer->As<ast::BinaryExpression>();
- ASSERT_NE(binary_expr, nullptr);
-
- auto binary_expr_id = node_id_map.GetId(binary_expr);
- ASSERT_NE(binary_expr_id, 0);
-
- MutationChangeBinaryOperator mutation(binary_expr_id, new_operator);
-
- std::stringstream expected_shader;
- expected_shader << "fn foo(a : " << lhs_type << ", b : " << rhs_type << ") {\n"
- << " let r : " << result_type << " = (a " << OpToString(new_operator)
- << " b);\n}\n";
-
- if (allowed_replacement_operators.count(new_operator) == 0) {
- ASSERT_FALSE(mutation.IsApplicable(program, node_id_map));
- if (new_operator != binary_expr->op) {
- Source::File invalid_file("test.wgsl", expected_shader.str());
- auto invalid_program = wgsl::reader::Parse(&invalid_file);
- ASSERT_FALSE(invalid_program.IsValid()) << program.Diagnostics();
- }
- } else {
- ASSERT_TRUE(
- MaybeApplyMutation(program, mutation, node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- ASSERT_EQ(expected_shader.str(), result->wgsl);
- }
- }
-}
-
-TEST(ChangeBinaryOperatorTest, AddSubtract) {
- for (auto op : {core::BinaryOp::kAdd, core::BinaryOp::kSubtract}) {
- const core::BinaryOp other_op =
- op == core::BinaryOp::kAdd ? core::BinaryOp::kSubtract : core::BinaryOp::kAdd;
- for (std::string type : {"i32", "vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- CheckMutations(type, type, type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor});
- }
- for (std::string type : {"u32", "vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- CheckMutations(
- type, type, type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor, core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight});
- }
- for (std::string type : {"f32", "vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- CheckMutations(type, type, type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- std::string scalar_type = "i32";
- CheckMutations(vector_type, scalar_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- std::string scalar_type = "u32";
- CheckMutations(vector_type, scalar_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- std::string scalar_type = "f32";
- CheckMutations(vector_type, scalar_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, op,
- {other_op, core::BinaryOp::kMultiply, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string square_matrix_type : {"mat2x2<f32>", "mat3x3<f32>", "mat4x4<f32>"}) {
- CheckMutations(square_matrix_type, square_matrix_type, square_matrix_type, op,
- {other_op, core::BinaryOp::kMultiply});
- }
- for (std::string non_square_matrix_type : {"mat2x3<f32>", "mat2x4<f32>", "mat3x2<f32>",
- "mat3x4<f32>", "mat4x2<f32>", "mat4x3<f32>"}) {
- CheckMutations(non_square_matrix_type, non_square_matrix_type, non_square_matrix_type,
- op, {other_op});
- }
- }
-}
-
-TEST(ChangeBinaryOperatorTest, Mul) {
- for (std::string type : {"i32", "vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor});
- }
- for (std::string type : {"u32", "vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- CheckMutations(
- type, type, type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor, core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight});
- }
- for (std::string type : {"f32", "vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- std::string scalar_type = "i32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- std::string scalar_type = "u32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- std::string scalar_type = "f32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kDivide,
- core::BinaryOp::kModulo});
- }
- for (std::string square_matrix_type : {"mat2x2<f32>", "mat3x3<f32>", "mat4x4<f32>"}) {
- CheckMutations(square_matrix_type, square_matrix_type, square_matrix_type,
- core::BinaryOp::kMultiply,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract});
- }
-
- CheckMutations("vec2<f32>", "mat2x2<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec2<f32>", "mat3x2<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec2<f32>", "mat4x2<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat2x2<f32>", "vec2<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x2<f32>", "mat3x2<f32>", "mat3x2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x2<f32>", "mat4x2<f32>", "mat4x2<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat2x3<f32>", "vec2<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x3<f32>", "mat2x2<f32>", "mat2x3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x3<f32>", "mat3x2<f32>", "mat3x3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x3<f32>", "mat4x2<f32>", "mat4x3<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat2x4<f32>", "vec2<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x4<f32>", "mat2x2<f32>", "mat2x4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x4<f32>", "mat3x2<f32>", "mat3x4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat2x4<f32>", "mat4x2<f32>", "mat4x4<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("vec3<f32>", "mat2x3<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec3<f32>", "mat3x3<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec3<f32>", "mat4x3<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat3x2<f32>", "vec3<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x2<f32>", "mat2x3<f32>", "mat2x2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x2<f32>", "mat3x3<f32>", "mat3x2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x2<f32>", "mat4x3<f32>", "mat4x2<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat3x3<f32>", "vec3<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x3<f32>", "mat2x3<f32>", "mat2x3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x3<f32>", "mat4x3<f32>", "mat4x3<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat3x4<f32>", "vec3<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x4<f32>", "mat2x3<f32>", "mat2x4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x4<f32>", "mat3x3<f32>", "mat3x4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat3x4<f32>", "mat4x3<f32>", "mat4x4<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("vec4<f32>", "mat2x4<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec4<f32>", "mat3x4<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("vec4<f32>", "mat4x4<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat4x2<f32>", "vec4<f32>", "vec2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x2<f32>", "mat2x4<f32>", "mat2x2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x2<f32>", "mat3x4<f32>", "mat3x2<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x2<f32>", "mat4x4<f32>", "mat4x2<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat4x3<f32>", "vec4<f32>", "vec3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x3<f32>", "mat2x4<f32>", "mat2x3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x3<f32>", "mat3x4<f32>", "mat3x3<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x3<f32>", "mat4x4<f32>", "mat4x3<f32>", core::BinaryOp::kMultiply, {});
-
- CheckMutations("mat4x4<f32>", "vec4<f32>", "vec4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x4<f32>", "mat2x4<f32>", "mat2x4<f32>", core::BinaryOp::kMultiply, {});
- CheckMutations("mat4x4<f32>", "mat3x4<f32>", "mat3x4<f32>", core::BinaryOp::kMultiply, {});
-}
-
-TEST(ChangeBinaryOperatorTest, DivideAndModulo) {
- for (std::string type : {"i32", "vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor});
- }
- for (std::string type : {"u32", "vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- CheckMutations(
- type, type, type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor, core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight});
- }
- for (std::string type : {"f32", "vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- std::string scalar_type = "i32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- std::string scalar_type = "u32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- }
- for (std::string vector_type : {"vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- std::string scalar_type = "f32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kDivide,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kModulo});
- }
- for (std::string type : {"i32", "vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor});
- }
- for (std::string type : {"u32", "vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- CheckMutations(
- type, type, type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor, core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight});
- }
- for (std::string type : {"f32", "vec2<f32>", "vec3<f32>", "vec4<f32>"}) {
- CheckMutations(type, type, type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide});
- }
- for (std::string vector_type : {"vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- std::string scalar_type = "i32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide});
- }
- for (std::string vector_type : {"vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- std::string scalar_type = "u32";
- CheckMutations(vector_type, scalar_type, vector_type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide});
- CheckMutations(scalar_type, vector_type, vector_type, core::BinaryOp::kModulo,
- {core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide});
- }
-}
-
-TEST(ChangeBinaryOperatorTest, AndOrXor) {
- for (auto op : {core::BinaryOp::kAnd, core::BinaryOp::kOr, core::BinaryOp::kXor}) {
- std::unordered_set<core::BinaryOp> allowed_replacement_operators_signed{
- core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide, core::BinaryOp::kModulo, core::BinaryOp::kAnd,
- core::BinaryOp::kOr, core::BinaryOp::kXor};
- allowed_replacement_operators_signed.erase(op);
- for (std::string type : {"i32", "vec2<i32>", "vec3<i32>", "vec4<i32>"}) {
- CheckMutations(type, type, type, op, allowed_replacement_operators_signed);
- }
- std::unordered_set<core::BinaryOp> allowed_replacement_operators_unsigned{
- core::BinaryOp::kAdd, core::BinaryOp::kSubtract, core::BinaryOp::kMultiply,
- core::BinaryOp::kDivide, core::BinaryOp::kModulo, core::BinaryOp::kShiftLeft,
- core::BinaryOp::kShiftRight, core::BinaryOp::kAnd, core::BinaryOp::kOr,
- core::BinaryOp::kXor};
- allowed_replacement_operators_unsigned.erase(op);
- for (std::string type : {"u32", "vec2<u32>", "vec3<u32>", "vec4<u32>"}) {
- CheckMutations(type, type, type, op, allowed_replacement_operators_unsigned);
- }
- if (op != core::BinaryOp::kXor) {
- for (std::string type : {"bool", "vec2<bool>", "vec3<bool>", "vec4<bool>"}) {
- std::unordered_set<core::BinaryOp> allowed_replacement_operators_bool{
- core::BinaryOp::kAnd, core::BinaryOp::kOr, core::BinaryOp::kEqual,
- core::BinaryOp::kNotEqual};
- allowed_replacement_operators_bool.erase(op);
- if (type == "bool") {
- allowed_replacement_operators_bool.insert(core::BinaryOp::kLogicalAnd);
- allowed_replacement_operators_bool.insert(core::BinaryOp::kLogicalOr);
- }
- CheckMutations(type, type, type, op, allowed_replacement_operators_bool);
- }
- }
- }
-}
-
-TEST(ChangeBinaryOperatorTest, EqualNotEqual) {
- for (auto op : {core::BinaryOp::kEqual, core::BinaryOp::kNotEqual}) {
- for (std::string element_type : {"i32", "u32", "f32"}) {
- for (size_t element_count = 1; element_count <= 4; element_count++) {
- std::stringstream argument_type;
- std::stringstream result_type;
- if (element_count == 1) {
- argument_type << element_type;
- result_type << "bool";
- } else {
- argument_type << "vec" << element_count << "<" << element_type << ">";
- result_type << "vec" << element_count << "<bool>";
- }
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kLessThan, core::BinaryOp::kLessThanEqual,
- core::BinaryOp::kGreaterThan, core::BinaryOp::kGreaterThanEqual,
- core::BinaryOp::kEqual, core::BinaryOp::kNotEqual};
- allowed_replacement_operators.erase(op);
- CheckMutations(argument_type.str(), argument_type.str(), result_type.str(), op,
- allowed_replacement_operators);
- }
- }
- {
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kLogicalAnd, core::BinaryOp::kLogicalOr, core::BinaryOp::kAnd,
- core::BinaryOp::kOr, core::BinaryOp::kEqual, core::BinaryOp::kNotEqual};
- allowed_replacement_operators.erase(op);
- CheckMutations("bool", "bool", "bool", op, allowed_replacement_operators);
- }
- for (size_t element_count = 2; element_count <= 4; element_count++) {
- std::stringstream argument_and_result_type;
- argument_and_result_type << "vec" << element_count << "<bool>";
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kAnd, core::BinaryOp::kOr, core::BinaryOp::kEqual,
- core::BinaryOp::kNotEqual};
- allowed_replacement_operators.erase(op);
- CheckMutations(argument_and_result_type.str(), argument_and_result_type.str(),
- argument_and_result_type.str(), op, allowed_replacement_operators);
- }
- }
-}
-
-TEST(ChangeBinaryOperatorTest, LessThanLessThanEqualGreaterThanGreaterThanEqual) {
- for (auto op : {core::BinaryOp::kLessThan, core::BinaryOp::kLessThanEqual,
- core::BinaryOp::kGreaterThan, core::BinaryOp::kGreaterThanEqual}) {
- for (std::string element_type : {"i32", "u32", "f32"}) {
- for (size_t element_count = 1; element_count <= 4; element_count++) {
- std::stringstream argument_type;
- std::stringstream result_type;
- if (element_count == 1) {
- argument_type << element_type;
- result_type << "bool";
- } else {
- argument_type << "vec" << element_count << "<" << element_type << ">";
- result_type << "vec" << element_count << "<bool>";
- }
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kLessThan, core::BinaryOp::kLessThanEqual,
- core::BinaryOp::kGreaterThan, core::BinaryOp::kGreaterThanEqual,
- core::BinaryOp::kEqual, core::BinaryOp::kNotEqual};
- allowed_replacement_operators.erase(op);
- CheckMutations(argument_type.str(), argument_type.str(), result_type.str(), op,
- allowed_replacement_operators);
- }
- }
- }
-}
-
-TEST(ChangeBinaryOperatorTest, LogicalAndLogicalOr) {
- for (auto op : {core::BinaryOp::kLogicalAnd, core::BinaryOp::kLogicalOr}) {
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kLogicalAnd, core::BinaryOp::kLogicalOr, core::BinaryOp::kAnd,
- core::BinaryOp::kOr, core::BinaryOp::kEqual, core::BinaryOp::kNotEqual};
- allowed_replacement_operators.erase(op);
- CheckMutations("bool", "bool", "bool", op, allowed_replacement_operators);
- }
-}
-
-TEST(ChangeBinaryOperatorTest, ShiftLeftShiftRight) {
- for (auto op : {core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight}) {
- for (std::string lhs_element_type : {"i32", "u32"}) {
- for (size_t element_count = 1; element_count <= 4; element_count++) {
- std::stringstream lhs_and_result_type;
- std::stringstream rhs_type;
- if (element_count == 1) {
- lhs_and_result_type << lhs_element_type;
- rhs_type << "u32";
- } else {
- lhs_and_result_type << "vec" << element_count << "<" << lhs_element_type << ">";
- rhs_type << "vec" << element_count << "<u32>";
- }
- std::unordered_set<core::BinaryOp> allowed_replacement_operators{
- core::BinaryOp::kShiftLeft, core::BinaryOp::kShiftRight};
- allowed_replacement_operators.erase(op);
- if (lhs_element_type == "u32") {
- allowed_replacement_operators.insert(core::BinaryOp::kAdd);
- allowed_replacement_operators.insert(core::BinaryOp::kSubtract);
- allowed_replacement_operators.insert(core::BinaryOp::kMultiply);
- allowed_replacement_operators.insert(core::BinaryOp::kDivide);
- allowed_replacement_operators.insert(core::BinaryOp::kModulo);
- allowed_replacement_operators.insert(core::BinaryOp::kAnd);
- allowed_replacement_operators.insert(core::BinaryOp::kOr);
- allowed_replacement_operators.insert(core::BinaryOp::kXor);
- }
- CheckMutations(lhs_and_result_type.str(), rhs_type.str(), lhs_and_result_type.str(),
- op, allowed_replacement_operators);
- }
- }
- }
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc
deleted file mode 100644
index 55a9ab7..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h"
-
-#include <utility>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/core/type/reference.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationChangeUnaryOperator::MutationChangeUnaryOperator(
- protobufs::MutationChangeUnaryOperator message)
- : message_(std::move(message)) {}
-
-MutationChangeUnaryOperator::MutationChangeUnaryOperator(uint32_t unary_expr_id,
- core::UnaryOp new_operator) {
- message_.set_unary_expr_id(unary_expr_id);
- message_.set_new_operator(static_cast<uint32_t>(new_operator));
-}
-
-bool MutationChangeUnaryOperator::IsApplicable(const tint::Program& program,
- const NodeIdMap& node_id_map) const {
- const auto* unary_expr_node =
- tint::As<ast::UnaryOpExpression>(node_id_map.GetNode(message_.unary_expr_id()));
-
- if (!unary_expr_node) {
- // Either the id does not exist, or does not correspond to a unary
- // expression.
- return false;
- }
-
- auto new_unary_operator = static_cast<core::UnaryOp>(message_.new_operator());
-
- // Get the type of the unary expression.
- const auto* type = program.Sem().Get(unary_expr_node)->Type();
- const auto* basic_type =
- type->Is<core::type::Reference>() ? type->As<core::type::Reference>()->StoreType() : type;
-
- // Only signed integer or vector of signed integer has more than 1
- // unary operators to change between.
- if (!basic_type->is_signed_integer_scalar_or_vector()) {
- return false;
- }
-
- // The new unary operator must not be the same as the original one.
- if (new_unary_operator != ToggleOperator(unary_expr_node->op)) {
- return false;
- }
-
- return true;
-}
-
-void MutationChangeUnaryOperator::Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const {
- const auto* unary_expr_node =
- tint::As<ast::UnaryOpExpression>(node_id_map.GetNode(message_.unary_expr_id()));
-
- const ast::UnaryOpExpression* cloned_replacement;
- switch (static_cast<core::UnaryOp>(message_.new_operator())) {
- case core::UnaryOp::kComplement:
- cloned_replacement =
- clone_context.dst->Complement(clone_context.Clone(unary_expr_node->expr));
- break;
- case core::UnaryOp::kNegation:
- cloned_replacement =
- clone_context.dst->Negation(clone_context.Clone(unary_expr_node->expr));
- break;
- default:
- cloned_replacement = nullptr;
- assert(false && "Unreachable");
- }
- // Set things up so that the original unary expression will be replaced with
- // its clone, and update the id mapping.
- clone_context.Replace(unary_expr_node, cloned_replacement);
- new_node_id_map->Add(cloned_replacement, message_.unary_expr_id());
-}
-
-protobufs::Mutation MutationChangeUnaryOperator::ToMessage() const {
- protobufs::Mutation mutation;
- *mutation.mutable_change_unary_operator() = message_;
- return mutation;
-}
-
-core::UnaryOp MutationChangeUnaryOperator::ToggleOperator(const core::UnaryOp& original_op) {
- if (original_op == core::UnaryOp::kComplement) {
- return core::UnaryOp::kNegation;
- }
- assert(original_op == core::UnaryOp::kNegation && "Unexpected operator.");
- return core::UnaryOp::kComplement;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h
deleted file mode 100644
index 27c5cb4..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_UNARY_OPERATOR_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_UNARY_OPERATOR_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-#include "src/tint/lang/core/unary_op.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @see MutationChangeUnaryOperator::Apply
-class MutationChangeUnaryOperator : public Mutation {
- public:
- /// @brief Constructs an instance of this mutation from a protobuf message.
- /// @param message - protobuf message
- explicit MutationChangeUnaryOperator(protobufs::MutationChangeUnaryOperator message);
-
- /// @brief Constructor.
- /// @param unary_expr_id - the id of the `ast::UnaryOpExpression` instance
- /// to change its operator.
- /// @param new_operator - A new unary operator for the unary expression
- /// specified by `expression_id`.
- MutationChangeUnaryOperator(uint32_t unary_expr_id, core::UnaryOp new_operator);
-
- /// @copybrief Mutation::IsApplicable
- ///
- /// The mutation is applicable if and only if:
- /// - `expression_id` is an id of an `ast::UnaryOpExpression`, that references
- /// a valid unary expression.
- /// - `new_unary_op` is a valid unary operator of type `core::UnaryOp`
- /// to the target expression.
- ///
- /// @copydetails Mutation::IsApplicable
- bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const override;
-
- /// @copybrief Mutation::Apply
- ///
- /// Replaces the operator of an unary op expression with `expression_id`
- /// with a new unary operator specified by `new_unary_op'. The modified
- /// expression preserves the same type as the original expression.
- ///
- /// @copydetails Mutation::Apply
- void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const override;
-
- protobufs::Mutation ToMessage() const override;
-
- /// Toggles between the complement and negate unary operators.
- /// @param original_op - a complement or negation unary operator.
- /// @return the other operator.
- static core::UnaryOp ToggleOperator(const core::UnaryOp& original_op);
-
- private:
- protobufs::MutationChangeUnaryOperator message_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_CHANGE_UNARY_OPERATOR_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator_test.cc
deleted file mode 100644
index 74903ad..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator_test.cc
+++ /dev/null
@@ -1,312 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-#include "src/tint/lang/wgsl/ast/call_statement.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-TEST(ChangeUnaryOperatorTest, Operator_Not_Applicable) {
- std::string content = R"(
- fn main() {
- let a : f32 = 1.1;
- let b = vec2<i32>(1, -1);
- let c : u32 = 0u;
- let d : vec3<bool> = vec3<bool> (false, false, true);
-
- var neg_a = -a;
- var not_b = ~b;
- var not_c = ~c;
- var neg_d = !d;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- // Get variable from statements.
- const auto* neg_a_var = main_fn_statements[4]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(neg_a_var, nullptr);
-
- const auto* not_b_var = main_fn_statements[5]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(not_b_var, nullptr);
-
- const auto* not_c_var = main_fn_statements[6]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(not_c_var, nullptr);
-
- const auto* neg_d_var = main_fn_statements[7]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(neg_d_var, nullptr);
-
- // Get the expression from variable declaration.
- const auto* neg_a_expr = neg_a_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(neg_a_expr, nullptr);
-
- const auto* not_b_expr = not_b_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(not_b_expr, nullptr);
-
- const auto* not_c_expr = not_c_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(not_c_expr, nullptr);
-
- const auto* neg_d_expr = neg_d_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(neg_d_expr, nullptr);
-
- // The following mutations are not applicable.
- auto neg_a_id = node_id_map.GetId(neg_a_expr);
- // Only negation is allowed for float type. Cannot change
- // the operator of float types to any other.
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(neg_a_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(neg_a_id, core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(neg_a_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
-
- auto not_b_id = node_id_map.GetId(not_b_expr);
- // Only complement and negation is allowed for signed integer type.
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(not_b_id, core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
- // Cannot change to the same unary operator.
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(not_b_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
-
- auto not_c_id = node_id_map.GetId(not_c_expr);
- // Only complement is allowed for unsigned integer.Cannot change
- // // the operator of float types to any other.
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(not_c_id, core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(not_c_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(not_c_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
-
- auto neg_d_id = node_id_map.GetId(neg_d_expr);
- // Only logical negation (not) is allowed for bool type. Cannot change
- // the operator of float types to any other.
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(neg_d_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(neg_d_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_FALSE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(neg_d_id, core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(ChangeUnaryOperatorTest, Signed_Integer_Types_Applicable1) {
- std::string content = R"(
- fn main() {
- let a : i32 = 5;
- let comp_a = ~a;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- // Get variable from statements.
- const auto* comp_a_var = main_fn_statements[1]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(comp_a_var, nullptr);
-
- // Get the expression from variable declaration.
- const auto* comp_a_expr = comp_a_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(comp_a_expr, nullptr);
-
- // Assert mutation to be applicable and apply mutation.
- auto comp_a_id = node_id_map.GetId(comp_a_expr);
- ASSERT_TRUE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(comp_a_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- let a : i32 = 5;
- let comp_a = -(a);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(ChangeUnaryOperatorTest, Signed_Integer_Types_Applicable2) {
- std::string content = R"(
- fn main() {
- let b : vec3<i32> = vec3<i32>(1, 3, -1);
- var comp_b : vec3<i32> = ~b;
- })";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- // Get variable from statements.
- const auto* comp_b_var = main_fn_statements[1]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(comp_b_var, nullptr);
-
- // Get the expression from variable declaration.
- const auto* comp_b_expr = comp_b_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(comp_b_expr, nullptr);
-
- // Assert mutation to be applicable and apply mutation.
- auto comp_b_id = node_id_map.GetId(comp_b_expr);
- ASSERT_TRUE(MaybeApplyMutation(program,
- MutationChangeUnaryOperator(comp_b_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- let b : vec3<i32> = vec3<i32>(1, 3, -(1));
- var comp_b : vec3<i32> = -(b);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(ChangeUnaryOperatorTest, Signed_Integer_Types_Applicable3) {
- std::string content = R"(
- fn main() {
- var a = -5;
-
- var neg_a = -(a);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- // Get variable from statements.
- const auto* neg_a_var = main_fn_statements[1]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(neg_a_var, nullptr);
-
- // Get the expression from variable declaration.
- const auto* neg_a_expr = neg_a_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(neg_a_expr, nullptr);
-
- // Assert mutation to be applicable and apply mutation.
- auto neg_a_id = node_id_map.GetId(neg_a_expr);
- ASSERT_TRUE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(neg_a_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a = -(5);
- var neg_a = ~(a);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(ChangeUnaryOperatorTest, Signed_Integer_Types_Applicable4) {
- std::string content = R"(
- fn main() {
- var b : vec3<i32> = vec3<i32>(1, 3, -1);
- let neg_b : vec3<i32> = -b;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- // Get variable from statements.
- const auto* neg_b_var = main_fn_statements[1]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(neg_b_var, nullptr);
-
- // Get the expression from variable declaration.
- const auto* neg_b_expr = neg_b_var->initializer->As<ast::UnaryOpExpression>();
- ASSERT_NE(neg_b_expr, nullptr);
-
- // Assert mutation to be applicable and apply mutation.
- auto neg_b_id = node_id_map.GetId(neg_b_expr);
- ASSERT_TRUE(MaybeApplyMutation(
- program, MutationChangeUnaryOperator(neg_b_id, core::UnaryOp::kComplement), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var b : vec3<i32> = vec3<i32>(1, 3, -(1));
- let neg_b : vec3<i32> = ~(b);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc
deleted file mode 100644
index f03ed83..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h"
-
-#include <algorithm>
-#include <utility>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/wgsl/ast/block_statement.h"
-#include "src/tint/lang/wgsl/ast/for_loop_statement.h"
-#include "src/tint/lang/wgsl/ast/if_statement.h"
-#include "src/tint/lang/wgsl/ast/loop_statement.h"
-#include "src/tint/lang/wgsl/ast/variable_decl_statement.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/sem/for_loop_statement.h"
-#include "src/tint/lang/wgsl/sem/if_statement.h"
-#include "src/tint/lang/wgsl/sem/loop_statement.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationDeleteStatement::MutationDeleteStatement(protobufs::MutationDeleteStatement message)
- : message_(std::move(message)) {}
-
-MutationDeleteStatement::MutationDeleteStatement(uint32_t statement_id) {
- message_.set_statement_id(statement_id);
-}
-
-bool MutationDeleteStatement::IsApplicable(const tint::Program& program,
- const NodeIdMap& node_id_map) const {
- auto* statement_node = tint::As<ast::Statement>(node_id_map.GetNode(message_.statement_id()));
-
- if (!statement_node) {
- // The statement id is invalid or does not refer to a statement.
- return false;
- }
-
- const auto* statement_sem_node = tint::As<sem::Statement>(program.Sem().Get(statement_node));
-
- if (!statement_sem_node) {
- // Semantic information for the statement is not available. This
- // information is required in order to perform the deletion.
- return false;
- }
-
- // Check whether it is OK to delete this statement.
- if (!CanBeDeleted(*statement_node, program, JumpTracker(program))) {
- return false;
- }
-
- return true;
-}
-
-void MutationDeleteStatement::Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* /* unused */) const {
- const auto* statement_node =
- tint::As<ast::Statement>(node_id_map.GetNode(message_.statement_id()));
- const auto* statement_sem_node =
- tint::As<sem::Statement>(clone_context.src->Sem().Get(statement_node));
- const auto* sem_parent = statement_sem_node->Parent();
-
- if (tint::Is<sem::IfStatement>(sem_parent) &&
- tint::As<ast::IfStatement>(sem_parent->Declaration())->else_statement == statement_node) {
- // Remove the "else" part of an if statement.
- clone_context.Replace(statement_node, static_cast<const ast::Statement*>(nullptr));
- } else if (tint::Is<sem::ForLoopStatement>(sem_parent) &&
- tint::As<ast::ForLoopStatement>(sem_parent->Declaration())->initializer ==
- statement_node) {
- // Remove the initializer of a for loop.
- clone_context.Replace(statement_node, static_cast<const ast::Statement*>(nullptr));
- } else if (tint::Is<sem::ForLoopStatement>(sem_parent) &&
- tint::As<ast::ForLoopStatement>(sem_parent->Declaration())->continuing ==
- statement_node) {
- // Remove the "continuing" statement of a for loop.
- clone_context.Replace(statement_node, static_cast<const ast::Statement*>(nullptr));
- } else if (tint::Is<sem::LoopContinuingBlockStatement>(statement_sem_node)) {
- // Remove the "continuing" block of a loop.
- clone_context.Replace(statement_node, static_cast<const ast::Statement*>(nullptr));
- } else if (tint::Is<ast::CaseStatement>(statement_node)) {
- // Remove a case statement from its enclosing switch statement.
- const auto& case_statement_list =
- &sem_parent->Declaration()->As<ast::SwitchStatement>()->body;
- assert(std::find(case_statement_list->begin(), case_statement_list->end(),
- statement_node) != case_statement_list->end() &&
- "Statement not found.");
- clone_context.Remove(*case_statement_list, statement_node);
- } else if (tint::Is<ast::BlockStatement>(statement_node)) {
- // Remove a block statement from the block that encloses it. A special case is required for
- // this, since a sem::Block has itself as its associated sem::Block, so it is necessary to
- // look at the parent to get the enclosing block.
- const auto& statement_list =
- sem_parent->Declaration()->As<ast::BlockStatement>()->statements;
- assert(std::find(statement_list.begin(), statement_list.end(), statement_node) !=
- statement_list.end() &&
- "Statement not found.");
- clone_context.Remove(statement_list, statement_node);
- } else {
- // Remove a non-block statement from the block that encloses it.
- const auto& statement_list =
- statement_sem_node->Block()->Declaration()->As<ast::BlockStatement>()->statements;
- assert(std::find(statement_list.begin(), statement_list.end(), statement_node) !=
- statement_list.end() &&
- "Statement not found.");
- clone_context.Remove(statement_list, statement_node);
- }
-}
-
-protobufs::Mutation MutationDeleteStatement::ToMessage() const {
- protobufs::Mutation mutation;
- *mutation.mutable_delete_statement() = message_;
- return mutation;
-}
-
-bool MutationDeleteStatement::CanBeDeleted(const ast::Statement& statement_node,
- const Program& program,
- const JumpTracker& jump_tracker) {
- if (statement_node.Is<ast::VariableDeclStatement>()) {
- // This is conservative. It would be possible to delete variable declarations if they are
- // not used. Further analysis could allow that.
- return false;
- }
-
- if (jump_tracker.ContainsReturn(statement_node)) {
- // This is conservative. It would be possible to delete a return statement as long as there
- // is still a return on every control flow path.
- return false;
- }
-
- if (jump_tracker.ContainsBreakForInnermostLoop(statement_node)) {
- // This is conservative. Disallowing the removal of breaks ensures that loops cannot become
- // statically infinite. However, a loop might in practice have multiple breaks, some of
- // which can be removed.
- return false;
- }
-
- if (auto* case_statement = statement_node.As<ast::CaseStatement>()) {
- // It is not OK to delete the case statement which contains the default selector.
- if (case_statement->ContainsDefault()) {
- return false;
- }
- }
-
- auto* parent_sem = program.Sem().Get(&statement_node)->Parent();
- if (parent_sem == nullptr) {
- // Semantic information for the parent node is required.
- return false;
- }
-
- auto* parent_stmt = parent_sem->Declaration();
-
- // It does not make sense to delete the entire body of a loop or if statement.
- if (auto* for_loop = parent_stmt->As<ast::ForLoopStatement>()) {
- if (for_loop->body == &statement_node) {
- return false;
- }
- }
- if (auto* loop = parent_stmt->As<ast::LoopStatement>()) {
- if (loop->body == &statement_node) {
- return false;
- }
- }
- if (auto* while_loop = parent_stmt->As<ast::WhileStatement>()) {
- if (while_loop->body == &statement_node) {
- return false;
- }
- }
- if (auto* if_statement = parent_stmt->As<ast::IfStatement>()) {
- if (if_statement->body == &statement_node) {
- return false;
- }
- }
-
- return true;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h
deleted file mode 100644
index d658314..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_DELETE_STATEMENT_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_DELETE_STATEMENT_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/jump_tracker.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-#include "src/tint/lang/wgsl/ast/statement.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @see MutationDeleteStatement::Apply
-class MutationDeleteStatement : public Mutation {
- public:
- /// @brief Constructs an instance of this mutation from a protobuf message.
- /// @param message - protobuf message
- explicit MutationDeleteStatement(protobufs::MutationDeleteStatement message);
-
- /// @brief Constructor.
- /// @param statement_id - the id of the statement to delete.
- explicit MutationDeleteStatement(uint32_t statement_id);
-
- /// @copybrief Mutation::IsApplicable
- ///
- /// The mutation is applicable iff:
- /// - `statement_id` corresponds to a statement in the AST.
- /// - `statement_id` does not refer to a variable declaration, since the declared variables will
- /// be inaccessible if the statement is deleted.
- /// - `statement_id` is not a return statement, since removing return statements arbitrarily can
- /// make the program invalid.
- /// - `statement_id` is not a break statement, since removing break statements can lead to
- /// syntactically infinite loops.
- ///
- /// @copydetails Mutation::IsApplicable
- bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const override;
-
- /// @copybrief Mutation::Apply
- ///
- /// Delete the statement referenced by `statement_id`.
- ///
- /// @copydetails Mutation::Apply
- void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const override;
-
- protobufs::Mutation ToMessage() const override;
-
- /// Return whether the given statement is suitable for deletion.
- /// @param statement_node - the statement to be considered for deletion.
- /// @param program - the program containing the statement.
- /// @param jump_tracker - information about jump statements for the program.
- /// @return true if and only if it is OK to delete the statement.
- static bool CanBeDeleted(const ast::Statement& statement_node,
- const Program& program,
- const JumpTracker& jump_tracker);
-
- private:
- protobufs::MutationDeleteStatement message_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_DELETE_STATEMENT_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc
deleted file mode 100644
index 793e581..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc
+++ /dev/null
@@ -1,671 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.h"
-
-#include <functional>
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-#include "src/tint/lang/wgsl/ast/assignment_statement.h"
-#include "src/tint/lang/wgsl/ast/block_statement.h"
-#include "src/tint/lang/wgsl/ast/case_statement.h"
-#include "src/tint/lang/wgsl/ast/for_loop_statement.h"
-#include "src/tint/lang/wgsl/ast/if_statement.h"
-#include "src/tint/lang/wgsl/ast/switch_statement.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-void CheckStatementDeletionWorks(
- const std::string& original,
- const std::string& expected,
- const std::function<const ast::Statement*(const Program&)>& statement_finder) {
- Source::File original_file("original.wgsl", original);
- auto program = wgsl::reader::Parse(&original_file);
-
- Source::File expected_file("expected.wgsl", expected);
- auto expected_program = wgsl::reader::Parse(&expected_file);
-
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
- ASSERT_TRUE(expected_program.IsValid()) << expected_program.Diagnostics();
-
- NodeIdMap node_id_map(program);
- const auto* statement = statement_finder(program);
- ASSERT_NE(statement, nullptr);
- auto statement_id = node_id_map.GetId(statement);
- ASSERT_NE(statement_id, 0);
- ASSERT_TRUE(MaybeApplyMutation(program, MutationDeleteStatement(statement_id), node_id_map,
- program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
- wgsl::writer::Options options;
- auto transformed_result = wgsl::writer::Generate(program, options);
- auto expected_result = wgsl::writer::Generate(expected_program, options);
- ASSERT_TRUE(transformed_result) << transformed_result.Failure();
- ASSERT_TRUE(expected_result) << expected_result.Failure();
- ASSERT_EQ(expected_result->wgsl, transformed_result->wgsl);
-}
-
-void CheckStatementDeletionNotAllowed(
- const std::string& original,
- const std::function<const ast::Statement*(const Program&)>& statement_finder) {
- Source::File original_file("original.wgsl", original);
- auto program = wgsl::reader::Parse(&original_file);
-
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
- const auto* statement = statement_finder(program);
- ASSERT_NE(statement, nullptr);
- auto statement_id = node_id_map.GetId(statement);
- ASSERT_NE(statement_id, 0);
- ASSERT_FALSE(MaybeApplyMutation(program, MutationDeleteStatement(statement_id), node_id_map,
- program, &node_id_map, nullptr));
-}
-
-TEST(DeleteStatementTest, DeleteAssignStatement) {
- auto original = R"(
- fn main() {
- {
- var a : i32 = 5;
- a = 6;
- }
- })";
- auto expected = R"(fn main() {
- {
- var a : i32 = 5;
- }
-}
-)";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::BlockStatement>()
- ->statements[1]
- ->As<ast::AssignmentStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteForStatement) {
- auto original =
- R"(
- fn main() {
- for (var i : i32 = 0; i < 10; i++) {
- }
- }
- )";
- auto expected = "fn main() { }";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::ForLoopStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteIfStatement) {
- auto original =
- R"(
- fn main() {
- if (true) { } else { }
- }
- )";
- auto expected = "fn main() { }";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::IfStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteBlockStatement) {
- auto original = "fn main() { { } }";
- auto expected = "fn main() { }";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::BlockStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteSwitchStatement) {
- auto original = R"(
-fn main() {
- switch(1) {
- case 0, 1: {
- }
- case 2, default: {
- }
- }
-})";
- auto expected = R"(fn main() { })";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::SwitchStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteCaseStatement) {
- auto original = R"(
-fn main() {
- switch(1) {
- case 0, 1: {
- }
- case 2, default: {
- }
- }
-})";
- auto expected = R"(
-fn main() {
- switch(1) {
- case 2, default: {
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::SwitchStatement>()
- ->body[0]
- ->As<ast::CaseStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteElse) {
- auto original = R"(
-fn main() {
- if (true) {
- } else {
- }
-})";
- auto expected = R"(
-fn main() {
- if (true) {
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::IfStatement>()
- ->else_statement;
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteCall) {
- auto original = R"(
-fn main() {
- workgroupBarrier();
-})";
- auto expected = R"(
-fn main() {
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::CallStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteCompoundAssign) {
- auto original = R"(
-fn main() {
- var x : i32 = 0;
- x += 2;;
-})";
- auto expected = R"(
-fn main() {
- var x : i32 = 0;
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::CompoundAssignmentStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteLoop) {
- auto original = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continuing {
- x++;
- }
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32 = 0;
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[1]->As<ast::LoopStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteContinuingBlock) {
- auto original = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continuing {
- x++;
- }
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::LoopStatement>()
- ->continuing;
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteContinue) {
- auto original = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continue;
- continuing {
- x++;
- }
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continuing {
- x++;
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::LoopStatement>()
- ->body->statements[1]
- ->As<ast::ContinueStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteIncrement) {
- auto original = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continuing {
- x++;
- }
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32 = 0;
- loop {
- if (x > 100) {
- break;
- }
- continuing {
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::LoopStatement>()
- ->continuing->statements[0]
- ->As<ast::IncrementDecrementStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteForLoopInitializer) {
- auto original = R"(
-fn main() {
- var x : i32;
- for (x = 0; x < 100; x++) {
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32;
- for (; x < 100; x++) {
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::ForLoopStatement>()
- ->initializer->As<ast::AssignmentStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DeleteForLoopContinuing) {
- auto original = R"(
-fn main() {
- var x : i32;
- for (x = 0; x < 100; x++) {
- }
-})";
- auto expected = R"(
-fn main() {
- var x : i32;
- for (x = 0; x < 100;) {
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::ForLoopStatement>()
- ->continuing->As<ast::IncrementDecrementStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, AllowDeletionOfInnerLoopWithBreak) {
- auto original = R"(
-fn main() {
- loop {
- loop {
- break;
- }
- break;
- }
-})";
- auto expected = R"(
-fn main() {
- loop {
- break;
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::LoopStatement>()
- ->body->statements[0]
- ->As<ast::LoopStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, AllowDeletionOfInnerCaseWithBreak) {
- auto original = R"(
-fn main() {
- loop {
- switch(0) {
- case 1: {
- break;
- }
- default: {
- }
- }
- break;
- }
-})";
- auto expected = R"(
-fn main() {
- loop {
- switch(0) {
- default: {
- }
- }
- break;
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::LoopStatement>()
- ->body->statements[0]
- ->As<ast::SwitchStatement>()
- ->body[0];
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, AllowDeletionOfBreakFromSwitch) {
- auto original = R"(
-fn main() {
- switch(0) {
- case 1: {
- break;
- }
- default: {
- }
- }
-})";
- auto expected = R"(
-fn main() {
- switch(0) {
- case 1: {
- }
- default: {
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::SwitchStatement>()
- ->body[0]
- ->body->statements[0]
- ->As<ast::BreakStatement>();
- };
- CheckStatementDeletionWorks(original, expected, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotDeleteVariableDeclaration) {
- auto original = R"(
-fn main() {
- var x : i32;
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::VariableDeclStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotDeleteCaseDueToDefault) {
- auto original = R"(
-fn main() {
- switch(1) {
- case 2, default: {
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::SwitchStatement>()
- ->body[0]
- ->As<ast::CaseStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotMakeLoopInfinite1) {
- auto original = R"(
-fn main() {
- loop {
- break;
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::LoopStatement>()
- ->body->statements[0]
- ->As<ast::BreakStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotMakeLoopInfinite2) {
- auto original = R"(
-fn main() {
- loop {
- if (true) {
- break;
- }
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::LoopStatement>()
- ->body->statements[0]
- ->As<ast::IfStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveReturn) {
- auto original = R"(
-fn main() {
- return;
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::ReturnStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveStatementContainingReturn) {
- auto original = R"(
-fn foo() -> i32 {
- if (true) {
- return 1;
- } else {
- return 2;
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::IfStatement>();
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveForLoopBody) {
- auto original = R"(
-fn main() {
- for(var i : i32 = 0; i < 10; i++) {
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::ForLoopStatement>()->body;
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveWhileBody) {
- auto original = R"(
-fn main() {
- var i : i32 = 0;
- while(i < 10) {
- i++;
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[1]->As<ast::WhileStatement>()->body;
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveIfBody) {
- auto original = R"(
-fn main() {
- if(true) {
- }
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body->statements[0]->As<ast::IfStatement>()->body;
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-TEST(DeleteStatementTest, DoNotRemoveFunctionBody) {
- auto original = R"(
-fn main() {
-})";
- auto statement_finder = [](const Program& program) -> const ast::Statement* {
- return program.AST().Functions()[0]->body;
- };
- CheckStatementDeletionNotAllowed(original, statement_finder);
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc
deleted file mode 100644
index d236811..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h"
-
-#include <utility>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/util.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationReplaceIdentifier::MutationReplaceIdentifier(protobufs::MutationReplaceIdentifier message)
- : message_(std::move(message)) {}
-
-MutationReplaceIdentifier::MutationReplaceIdentifier(uint32_t use_id, uint32_t replacement_id) {
- message_.set_use_id(use_id);
- message_.set_replacement_id(replacement_id);
-}
-
-bool MutationReplaceIdentifier::IsApplicable(const tint::Program& program,
- const NodeIdMap& node_id_map) const {
- const auto* use_ast_node =
- tint::As<ast::IdentifierExpression>(node_id_map.GetNode(message_.use_id()));
- if (!use_ast_node) {
- // Either the `use_id` is invalid or the node is not an
- // `IdentifierExpression`.
- return false;
- }
-
- const auto* use_sem_node = tint::As<sem::VariableUser>(program.Sem().Get(use_ast_node));
- if (!use_sem_node) {
- // Either the semantic information is not present for a `use_node` or that
- // node is not a variable user.
- return false;
- }
-
- const auto* replacement_ast_node =
- tint::As<ast::Variable>(node_id_map.GetNode(message_.replacement_id()));
- if (!replacement_ast_node) {
- // Either the `replacement_id` is invalid or is not an id of a variable.
- return false;
- }
-
- const auto* replacement_sem_node = program.Sem().Get(replacement_ast_node);
- if (!replacement_sem_node) {
- return false;
- }
-
- if (replacement_sem_node == use_sem_node->Variable()) {
- return false;
- }
-
- auto in_scope = util::GetAllVarsInScope(
- program, use_sem_node->Stmt(),
- [replacement_sem_node](const sem::Variable* var) { return var == replacement_sem_node; });
- if (in_scope.empty()) {
- // The replacement variable is not in scope.
- return false;
- }
-
- return use_sem_node->Type() == replacement_sem_node->Type();
-}
-
-void MutationReplaceIdentifier::Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const {
- const auto* use_node = node_id_map.GetNode(message_.use_id());
- const auto* replacement_var =
- tint::As<ast::Variable>(node_id_map.GetNode(message_.replacement_id()));
-
- auto* cloned_replacement = clone_context.dst->Expr(
- clone_context.Clone(use_node->source), clone_context.Clone(replacement_var->name->symbol));
- clone_context.Replace(use_node, cloned_replacement);
- new_node_id_map->Add(cloned_replacement, message_.use_id());
-}
-
-protobufs::Mutation MutationReplaceIdentifier::ToMessage() const {
- protobufs::Mutation mutation;
- *mutation.mutable_replace_identifier() = message_;
- return mutation;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h b/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h
deleted file mode 100644
index 88b5c3e..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_REPLACE_IDENTIFIER_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_REPLACE_IDENTIFIER_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @see MutationReplaceIdentifier::Apply
-class MutationReplaceIdentifier : public Mutation {
- public:
- /// @brief Constructs an instance of this mutation from a protobuf message.
- /// @param message - protobuf message
- explicit MutationReplaceIdentifier(protobufs::MutationReplaceIdentifier message);
-
- /// @brief Constructor.
- /// @param use_id - the id of a variable user.
- /// @param replacement_id - the id of a variable to replace the `use_id`.
- MutationReplaceIdentifier(uint32_t use_id, uint32_t replacement_id);
-
- /// @copybrief Mutation::IsApplicable
- ///
- /// The mutation is applicable iff:
- /// - `use_id` is a valid id of an `ast::IdentifierExpression`, that
- /// references a variable.
- /// - `replacement_id` is a valid id of an `ast::Variable`.
- /// - The identifier expression doesn't reference the variable of a
- /// `replacement_id`.
- /// - The variable with `replacement_id` is in scope of an identifier
- /// expression with `use_id`.
- /// - The identifier expression and the variable have the same type.
- ///
- /// @copydetails Mutation::IsApplicable
- bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const override;
-
- /// @copybrief Mutation::Apply
- ///
- /// Replaces the use of an identifier expression with `use_id` with a newly
- /// created identifier expression, that references a variable with
- /// `replacement_id`. The newly created identifier expression will have the
- /// same id as the old one (i.e. `use_id`).
- ///
- /// @copydetails Mutation::Apply
- void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const override;
-
- protobufs::Mutation ToMessage() const override;
-
- private:
- protobufs::MutationReplaceIdentifier message_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_REPLACE_IDENTIFIER_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc
deleted file mode 100644
index bbe2449..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc
+++ /dev/null
@@ -1,663 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.h"
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/lang/wgsl/ast/call_statement.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-TEST(ReplaceIdentifierTest, NotApplicable_Simple) {
- std::string content = R"(
- fn main() {
- let a = 5;
- let c = 6;
- let b = a + 5;
-
- let d = vec2<i32>(1, 2);
- let e = d.x;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements;
-
- const auto* a_var = main_fn_stmts[0]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(a_var, nullptr);
-
- const auto* b_var = main_fn_stmts[2]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(b_var, nullptr);
-
- const auto* e_var = main_fn_stmts[4]->As<ast::VariableDeclStatement>()->variable;
- ASSERT_NE(e_var, nullptr);
-
- auto a_var_id = node_id_map.GetId(a_var);
- ASSERT_NE(a_var_id, 0);
-
- auto b_var_id = node_id_map.GetId(b_var);
- ASSERT_NE(b_var_id, 0);
-
- const auto* sum_expr = b_var->initializer->As<ast::BinaryExpression>();
- ASSERT_NE(sum_expr, nullptr);
-
- auto a_ident_id = node_id_map.GetId(sum_expr->lhs);
- ASSERT_NE(a_ident_id, 0);
-
- auto sum_expr_id = node_id_map.GetId(sum_expr);
- ASSERT_NE(sum_expr_id, 0);
-
- auto e_var_id = node_id_map.GetId(e_var);
- ASSERT_NE(e_var_id, 0);
-
- auto vec_member_access_id =
- node_id_map.GetId(e_var->initializer->As<ast::MemberAccessorExpression>()->member);
- ASSERT_NE(vec_member_access_id, 0);
-
- // use_id is invalid.
- EXPECT_FALSE(MutationReplaceIdentifier(0, a_var_id).IsApplicable(program, node_id_map));
-
- // use_id is not an identifier expression.
- EXPECT_FALSE(
- MutationReplaceIdentifier(sum_expr_id, a_var_id).IsApplicable(program, node_id_map));
-
- // use_id is an identifier but not a variable user.
- EXPECT_FALSE(MutationReplaceIdentifier(vec_member_access_id, a_var_id)
- .IsApplicable(program, node_id_map));
-
- // replacement_id is invalid.
- EXPECT_FALSE(MutationReplaceIdentifier(a_ident_id, 0).IsApplicable(program, node_id_map));
-
- // replacement_id is not a variable.
- EXPECT_FALSE(
- MutationReplaceIdentifier(a_ident_id, sum_expr_id).IsApplicable(program, node_id_map));
-
- // Can't replace a variable with itself.
- EXPECT_FALSE(
- MutationReplaceIdentifier(a_ident_id, a_var_id).IsApplicable(program, node_id_map));
-
- // Replacement is not in scope.
- EXPECT_FALSE(
- MutationReplaceIdentifier(a_ident_id, b_var_id).IsApplicable(program, node_id_map));
- EXPECT_FALSE(
- MutationReplaceIdentifier(a_ident_id, e_var_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, GlobalVarNotInScope) {
- // Can't use the global variable if it's not in scope.
- std::string shader = R"(
-var<private> a: i32;
-
-fn f() {
- a = 3;
-}
-
-var<private> b: i32;
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(
- program.AST().Functions()[0]->body->statements[0]->As<ast::AssignmentStatement>()->lhs);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
- ASSERT_NE(replacement_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable1) {
- // Can't replace `a` with `b` since the store type is wrong (the same storage
- // class though).
- std::string shader = R"(
-var<private> a: i32;
-var<private> b: u32;
-fn f() {
- *&a = 4;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable2) {
- // Can't replace `a` with `b` since the store type is wrong (the storage
- // class is different though).
- std::string shader = R"(
-var<private> a: i32;
-fn f() {
- var b: u32;
- *&a = 4;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable3) {
- // Can't replace `a` with `b` since the latter is not a reference (the store
- // type is the same, though).
- std::string shader = R"(
-var<private> a: i32;
-fn f() {
- let b = 45;
- *&a = 4;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable4) {
- // Can't replace `a` with `b` since the latter is not a reference (the store
- // type is the same, though).
- std::string shader = R"(
-var<private> a: i32;
-fn f(b: i32) {
- *&a = 4;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().Functions()[0]->params[0]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable5) {
- // Can't replace `a` with `b` since the latter has a wrong access mode
- // (`read` for uniform address space).
- std::string shader = R"(
-struct S {
- a: i32
-}
-
-var<private> a: S;
-@group(1) @binding(1) var<uniform> b: S;
-fn f() {
- *&a = S(4);
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable6) {
- // Can't replace `ptr_b` with `a` since the latter is not a pointer.
- std::string shader = R"(
-struct S {
- a: i32
-}
-
-var<private> a: S;
-@group(1) @binding(1) var<uniform> b: S;
-fn f() {
- let ptr_b = &b;
- *&a = *ptr_b;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::AssignmentStatement>()
- ->rhs->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable8) {
- // Can't replace `ptr_b` with `c` since the latter has a wrong access mode and
- // address space.
- std::string shader = R"(
-struct S {
- a: i32
-}
-
-var<private> a: S;
-@group(1) @binding(1) var<uniform> b: S;
-@group(1) @binding(2) var<storage, read_write> c: S;
-fn f() {
- let ptr_b = &b;
- *&a = *ptr_b;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[2]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::AssignmentStatement>()
- ->rhs->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable9) {
- // Can't replace `b` with `e` since the latter is not a reference.
- std::string shader = R"(
-struct S {
- a: i32
-}
-
-var<private> a: S;
-const e = 3;
-@group(1) @binding(1) var<uniform> b: S;
-fn f() {
- *&a = *&b;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::AssignmentStatement>()
- ->rhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable10) {
- // Can't replace `b` with `e` since the latter has a wrong access mode.
- std::string shader = R"(
-struct S {
- a: i32
-}
-
-var<private> a: S;
-@group(0) @binding(0) var<storage, read_write> e: S;
-@group(1) @binding(1) var<uniform> b: S;
-fn f() {
- *&a = *&b;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]);
- ASSERT_NE(replacement_id, 0);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::AssignmentStatement>()
- ->rhs->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, Applicable1) {
- // Can replace `a` with `b` (same address space).
- std::string shader = R"(
-fn f() {
- var b : vec2<u32>;
- var a = vec2<u32>(34u, 45u);
- (*&a)[1] = 3u;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[2]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::IndexAccessorExpression>()
- ->object->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable);
- ASSERT_NE(replacement_id, 0);
-
- ASSERT_TRUE(MaybeApplyMutation(program, MutationReplaceIdentifier(use_id, replacement_id),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn f() {
- var b : vec2<u32>;
- var a = vec2<u32>(34u, 45u);
- (*(&(b)))[1] = 3u;
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(ReplaceIdentifierTest, Applicable2) {
- // Can replace `ptr_a` with `b` - the function parameter.
- std::string shader = R"(
-fn f(b: ptr<function, vec2<u32>>) {
- var a = vec2<u32>(34u, 45u);
- let ptr_a = &a;
- (*ptr_a)[1] = 3u;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[2]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::IndexAccessorExpression>()
- ->object->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST().Functions()[0]->params[0]);
- ASSERT_NE(replacement_id, 0);
-
- ASSERT_TRUE(MaybeApplyMutation(program, MutationReplaceIdentifier(use_id, replacement_id),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn f(b : ptr<function, vec2<u32>>) {
- var a = vec2<u32>(34u, 45u);
- let ptr_a = &(a);
- (*(b))[1] = 3u;
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable12) {
- // Can't replace `a` with `b` (both are references with different storage
- // class).
- std::string shader = R"(
-var<private> b : vec2<u32>;
-fn f() {
- var a = vec2<u32>(34u, 45u);
- (*&a)[1] = 3u;
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::AssignmentStatement>()
- ->lhs->As<ast::IndexAccessorExpression>()
- ->object->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
- ASSERT_NE(replacement_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable13) {
- // Can't replace `a` with `b` (both are references with different storage
- // class).
- std::string shader = R"(
-var<private> b : vec2<u32>;
-fn f() {
- var a = vec2<u32>(34u, 45u);
- let c = (*&a)[1];
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[1]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::IndexAccessorExpression>()
- ->object->As<ast::UnaryOpExpression>()
- ->expr->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]);
- ASSERT_NE(replacement_id, 0);
-
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-TEST(ReplaceIdentifierTest, NotApplicable14) {
- // Can't replace `ptr_a` with `ptr_b` (both are pointers with different
- // address space).
- std::string shader = R"(
-var<private> b: vec2<u32>;
-fn f() {
- var a = vec2<u32>(34u, 45u);
- let ptr_a = &a;
- let ptr_b = &b;
- let c = (*ptr_a)[1];
-}
-)";
- Source::File file("test.wgsl", shader);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- auto use_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[3]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::IndexAccessorExpression>()
- ->object->As<ast::UnaryOpExpression>()
- ->expr);
- ASSERT_NE(use_id, 0);
-
- auto replacement_id = node_id_map.GetId(program.AST()
- .Functions()[0]
- ->body->statements[2]
- ->As<ast::VariableDeclStatement>()
- ->variable);
- ASSERT_NE(replacement_id, 0);
- ASSERT_FALSE(
- MutationReplaceIdentifier(use_id, replacement_id).IsApplicable(program, node_id_map));
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc
deleted file mode 100644
index 32f5759..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h"
-
-#include <utility>
-#include <vector>
-
-#include "src/tint/lang/core/type/abstract_float.h"
-#include "src/tint/lang/core/type/abstract_int.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/sem/call.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-MutationWrapUnaryOperator::MutationWrapUnaryOperator(protobufs::MutationWrapUnaryOperator message)
- : message_(std::move(message)) {}
-
-MutationWrapUnaryOperator::MutationWrapUnaryOperator(uint32_t expression_id,
- uint32_t fresh_id,
- core::UnaryOp unary_op_wrapper) {
- message_.set_expression_id(expression_id);
- message_.set_fresh_id(fresh_id);
- message_.set_unary_op_wrapper(static_cast<uint32_t>(unary_op_wrapper));
-}
-
-bool MutationWrapUnaryOperator::IsApplicable(const tint::Program& program,
- const NodeIdMap& node_id_map) const {
- // Check if id that will be assigned is fresh.
- if (!node_id_map.IdIsFreshAndValid(message_.fresh_id())) {
- return false;
- }
-
- const auto* expression_ast_node =
- tint::As<ast::Expression>(node_id_map.GetNode(message_.expression_id()));
-
- if (!expression_ast_node) {
- // Either the node is not present with the given id or
- // the node is not a valid expression type.
- return false;
- }
-
- const auto* expression_sem_node = program.Sem().GetVal(expression_ast_node);
-
- if (!expression_sem_node) {
- // Semantic information for the expression ast node is not present
- // or the semantic node is not a valid expression type node.
- return false;
- }
-
- core::UnaryOp unary_op_wrapper = static_cast<core::UnaryOp>(message_.unary_op_wrapper());
-
- std::vector<core::UnaryOp> valid_ops = GetValidUnaryWrapper(*expression_sem_node);
-
- // There is no available unary operator or |unary_op_wrapper| is a
- // type that is not allowed for the given expression.
- if (std::find(valid_ops.begin(), valid_ops.end(), unary_op_wrapper) == valid_ops.end()) {
- return false;
- }
-
- return true;
-}
-
-void MutationWrapUnaryOperator::Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const {
- auto* expression_node =
- tint::As<ast::Expression>(node_id_map.GetNode(message_.expression_id()));
-
- auto* replacement_expression_node = clone_context.dst->create<ast::UnaryOpExpression>(
- static_cast<core::UnaryOp>(message_.unary_op_wrapper()),
- clone_context.Clone(expression_node));
-
- clone_context.Replace(expression_node, replacement_expression_node);
-
- new_node_id_map->Add(replacement_expression_node, message_.fresh_id());
-}
-
-protobufs::Mutation MutationWrapUnaryOperator::ToMessage() const {
- protobufs::Mutation mutation;
- *mutation.mutable_wrap_unary_operator() = message_;
- return mutation;
-}
-
-std::vector<core::UnaryOp> MutationWrapUnaryOperator::GetValidUnaryWrapper(
- const sem::ValueExpression& expr) {
- if (auto* call_expr = expr.As<sem::Call>()) {
- if (auto* stmt = call_expr->Stmt()) {
- if (auto* call_stmt = stmt->Declaration()->As<ast::CallStatement>()) {
- if (call_stmt->expr == expr.Declaration()) {
- return {}; // A call statement must only wrap a call expression.
- }
- }
- }
- }
-
- const auto* expr_type = expr.Type();
- if (expr_type->is_bool_scalar_or_vector()) {
- return {core::UnaryOp::kNot};
- }
-
- if (expr_type->is_signed_integer_scalar_or_vector() ||
- expr_type->is_abstract_integer_scalar_or_vector()) {
- return {core::UnaryOp::kNegation, core::UnaryOp::kComplement};
- }
-
- if (expr_type->is_unsigned_integer_scalar_or_vector()) {
- return {core::UnaryOp::kComplement};
- }
-
- if (expr_type->is_float_scalar_or_vector() || expr_type->is_abstract_float_scalar_or_vector()) {
- return {core::UnaryOp::kNegation};
- }
-
- return {};
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h
deleted file mode 100644
index 3314d31..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_WRAP_UNARY_OPERATOR_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_WRAP_UNARY_OPERATOR_H_
-
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-
-#include "src/tint/lang/core/unary_op.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @see MutationWrapUnaryOperator::Apply
-class MutationWrapUnaryOperator : public Mutation {
- public:
- /// @brief Constructs an instance of this mutation from a protobuf message.
- /// @param message - protobuf message
- explicit MutationWrapUnaryOperator(protobufs::MutationWrapUnaryOperator message);
-
- /// @brief Constructor.
- /// @param expression_id - the id of an expression.
- /// @param fresh_id - a fresh id for the created expression node with
- /// unary operator wrapper.
- /// @param unary_op_wrapper - a `core::UnaryOp` instance.
- MutationWrapUnaryOperator(uint32_t expression_id,
- uint32_t fresh_id,
- core::UnaryOp unary_op_wrapper);
-
- /// @copybrief Mutation::IsApplicable
- ///
- /// The mutation is applicable iff:
- /// - `expression_id` must refer to a valid expression that can be wrapped
- /// with unary operator.
- /// - `fresh_id` must be fresh.
- /// - `unary_op_wrapper` is a unary expression that is valid based on the
- /// type of the given expression.
- ///
- /// @copydetails Mutation::IsApplicable
- bool IsApplicable(const tint::Program& program, const NodeIdMap& node_id_map) const override;
-
- /// @copybrief Mutation::Apply
- ///
- /// Wrap an expression in a unary operator that is valid based on
- /// the type of the expression.
- ///
- /// @copydetails Mutation::Apply
- void Apply(const NodeIdMap& node_id_map,
- tint::program::CloneContext& clone_context,
- NodeIdMap* new_node_id_map) const override;
-
- protobufs::Mutation ToMessage() const override;
-
- /// Return list of unary operator wrappers allowed for the given
- /// expression.
- /// @param expr - an `ast::Expression` instance from node id map.
- /// @return a list of unary operators.
- static std::vector<core::UnaryOp> GetValidUnaryWrapper(const sem::ValueExpression& expr);
-
- private:
- protobufs::MutationWrapUnaryOperator message_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATIONS_WRAP_UNARY_OPERATOR_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator_test.cc
deleted file mode 100644
index a97004d..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator_test.cc
+++ /dev/null
@@ -1,566 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-TEST(WrapUnaryOperatorTest, Applicable1) {
- std::string content = R"(
- fn main() {
- var a = 5;
- if (a < 5) {
- a = 6;
- }
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- auto expression_id =
- node_id_map.GetId(main_fn_statements[1]->As<ast::IfStatement>()->condition);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(MaybeApplyMutation(
- program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(), core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a = 5;
- if (!((a < 5))) {
- a = 6;
- }
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable2) {
- std::string content = R"(
- fn main() {
- let a = vec3<bool>(true, false, true);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(MaybeApplyMutation(
- program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(), core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- let a = !(vec3<bool>(true, false, true));
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable3) {
- std::string content = R"(
- fn main() {
- var a : u32;
- a = 6u;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[1]->As<ast::AssignmentStatement>()->rhs;
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kComplement),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a : u32;
- a = ~(6u);
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable4) {
- std::string content = R"(
- fn main() -> vec2<bool> {
- var a = (vec2<u32> (1u, 2u) == vec2<u32> (1u, 2u));
- return a;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::BinaryExpression>()
- ->lhs;
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kComplement),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() -> vec2<bool> {
- var a = (~(vec2<u32>(1u, 2u)) == vec2<u32>(1u, 2u));
- return a;
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable5) {
- std::string content = R"(
- fn main() {
- let a : f32 = -(1.0);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::UnaryOpExpression>()
- ->expr;
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- let a : f32 = -(-(1.0));
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable6) {
- std::string content = R"(
- fn main() {
- var a : vec4<f32> = vec4<f32>(-1.0, -1.0, -1.0, -1.0);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a : vec4<f32> = -(vec4<f32>(-(1.0), -(1.0), -(1.0), -(1.0)));
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable7) {
- std::string content = R"(
- fn main() {
- var a = 1;
- for(var i : i32 = 1; i < 5; i = i + 1) {
- a = a + 1;
- }
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[1]
- ->As<ast::ForLoopStatement>()
- ->initializer->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a = 1;
- for(var i : i32 = -(1); (i < 5); i = (i + 1)) {
- a = (a + 1);
- }
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, Applicable8) {
- std::string content = R"(
- fn main() {
- var a : vec4<i32> = vec4<i32>(1, 0, -1, 0);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- ASSERT_TRUE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kComplement),
- node_id_map, program, &node_id_map, nullptr));
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- wgsl::writer::Options options;
- auto result = wgsl::writer::Generate(program, options);
- ASSERT_TRUE(result) << result.Failure();
-
- std::string expected_shader = R"(fn main() {
- var a : vec4<i32> = ~(vec4<i32>(1, 0, -(1), 0));
-}
-)";
- ASSERT_EQ(expected_shader, result->wgsl);
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable1) {
- std::string content = R"(
- fn main() {
- let a = mat2x3<f32>(vec3<f32>(1.,0.,1.), vec3<f32>(0.,1.,0.));
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- // There is no unary operator that can be applied to matrix type.
- ASSERT_FALSE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable2) {
- std::string content = R"(
- fn main() {
- let a = 1;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- // Not cannot be applied to integer types.
- ASSERT_FALSE(MaybeApplyMutation(
- program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(), core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable3) {
- std::string content = R"(
- fn main() {
- let a = vec2<u32>(1u, 2u);
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- // Negation cannot be applied to unsigned integer scalar or vectors.
- ASSERT_FALSE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable4) {
- std::string content = R"(
- fn main() {
- let a = 1.5;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- // Cannot wrap float types with complement operator.
- ASSERT_FALSE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(expression_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kComplement),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable5) {
- std::string content = R"(
- fn main() {
- let a = 1.5;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* expr = main_fn_statements[0]
- ->As<ast::VariableDeclStatement>()
- ->variable->initializer->As<ast::Expression>();
-
- const auto expression_id = node_id_map.GetId(expr);
- ASSERT_NE(expression_id, 0);
-
- // Id for the replacement expression is not fresh.
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationWrapUnaryOperator(expression_id, expression_id, core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable6) {
- std::string content = R"(
- fn main() {
- let a = 1.5;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* statement = main_fn_statements[0]->As<ast::VariableDeclStatement>();
-
- const auto statement_id = node_id_map.GetId(statement);
- ASSERT_NE(statement_id, 0);
-
- // The id provided for the expression is not a valid expression type.
- ASSERT_FALSE(
- MaybeApplyMutation(program,
- MutationWrapUnaryOperator(statement_id, node_id_map.TakeFreshId(),
- core::UnaryOp::kNegation),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-TEST(WrapUnaryOperatorTest, NotApplicable_CallStmt) {
- std::string content = R"(
- fn main() {
- f();
- }
- fn f() -> bool {
- return false;
- }
- )";
- Source::File file("test.wgsl", content);
- auto program = wgsl::reader::Parse(&file);
- ASSERT_TRUE(program.IsValid()) << program.Diagnostics();
-
- NodeIdMap node_id_map(program);
-
- const auto& main_fn_statements = program.AST().Functions()[0]->body->statements;
-
- const auto* call_stmt = main_fn_statements[0]->As<ast::CallStatement>();
- ASSERT_NE(call_stmt, nullptr);
-
- const auto expr_id = node_id_map.GetId(call_stmt->expr);
- ASSERT_NE(expr_id, 0);
-
- // The id provided for the expression is not a valid expression type.
- ASSERT_FALSE(MaybeApplyMutation(
- program, MutationWrapUnaryOperator(expr_id, node_id_map.TakeFreshId(), core::UnaryOp::kNot),
- node_id_map, program, &node_id_map, nullptr));
-}
-
-} // namespace
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutator.cc
deleted file mode 100644
index 10be27c..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutator.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutator.h"
-
-#include <cassert>
-#include <memory>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_binary_operators.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/delete_statements.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/replace_identifiers.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-#include "src/tint/lang/wgsl/resolver/resolve.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-template <typename T, typename... Args>
-void MaybeAddFinder(bool enable_all_mutations,
- ProbabilityContext* probability_context,
- MutationFinderList* finders,
- Args&&... args) {
- if (enable_all_mutations || probability_context->RandomBool()) {
- finders->push_back(std::make_unique<T>(std::forward<Args>(args)...));
- }
-}
-
-MutationFinderList CreateMutationFinders(ProbabilityContext* probability_context,
- bool enable_all_mutations) {
- MutationFinderList result;
- do {
- MaybeAddFinder<MutationFinderChangeBinaryOperators>(enable_all_mutations,
- probability_context, &result);
- MaybeAddFinder<MutationFinderChangeUnaryOperators>(enable_all_mutations,
- probability_context, &result);
- MaybeAddFinder<MutationFinderDeleteStatements>(enable_all_mutations, probability_context,
- &result);
- MaybeAddFinder<MutationFinderReplaceIdentifiers>(enable_all_mutations, probability_context,
- &result);
- MaybeAddFinder<MutationFinderWrapUnaryOperators>(enable_all_mutations, probability_context,
- &result);
- } while (result.empty());
- return result;
-}
-
-} // namespace
-
-bool MaybeApplyMutation(const tint::Program& program,
- const Mutation& mutation,
- const NodeIdMap& node_id_map,
- tint::Program& out_program,
- NodeIdMap* out_node_id_map,
- protobufs::MutationSequence* mutation_sequence) {
- assert(out_node_id_map && "`out_node_id_map` may not be a nullptr");
-
- if (!mutation.IsApplicable(program, node_id_map)) {
- return false;
- }
-
- // The mutated `program` will be copied into the `mutated` program builder.
- tint::ProgramBuilder mutated;
- tint::program::CloneContext clone_context(&mutated, &program);
- NodeIdMap new_node_id_map;
- clone_context.ReplaceAll(
- [&node_id_map, &new_node_id_map, &clone_context](const ast::Node* node) {
- // Make sure all `tint::ast::` nodes' ids are preserved.
- auto* cloned = tint::As<ast::Node>(node->Clone(clone_context));
- new_node_id_map.Add(cloned, node_id_map.GetId(node));
- return cloned;
- });
-
- mutation.Apply(node_id_map, clone_context, &new_node_id_map);
- if (mutation_sequence) {
- *mutation_sequence->add_mutation() = mutation.ToMessage();
- }
-
- clone_context.Clone();
- out_program = tint::resolver::Resolve(mutated);
- *out_node_id_map = std::move(new_node_id_map);
- return true;
-}
-
-tint::Program Replay(tint::Program program, const protobufs::MutationSequence& mutation_sequence) {
- assert(program.IsValid() && "Initial program is invalid");
-
- NodeIdMap node_id_map(program);
- for (const auto& mutation_message : mutation_sequence.mutation()) {
- auto mutation = Mutation::FromMessage(mutation_message);
- auto status =
- MaybeApplyMutation(program, *mutation, node_id_map, program, &node_id_map, nullptr);
- (void)status; // `status` will be unused in release mode.
- assert(status && "`mutation` is inapplicable - it's most likely a bug");
- if (!program.IsValid()) {
- // `mutation` has a bug.
- break;
- }
- }
-
- return program;
-}
-
-tint::Program Mutate(tint::Program program,
- ProbabilityContext* probability_context,
- bool enable_all_mutations,
- uint32_t max_applied_mutations,
- protobufs::MutationSequence* mutation_sequence) {
- assert(max_applied_mutations != 0 && "Maximum number of mutations is invalid");
- assert(program.IsValid() && "Initial program is invalid");
-
- // The number of allowed failed attempts to apply mutations. If this number is
- // exceeded, the mutator is considered stuck and the mutation session is
- // stopped.
- const uint32_t kMaxFailureToApply = 10;
-
- auto finders = CreateMutationFinders(probability_context, enable_all_mutations);
- NodeIdMap node_id_map(program);
-
- // Total number of applied mutations during this call to `Mutate`.
- uint32_t applied_mutations = 0;
-
- // The number of consecutively failed attempts to apply mutations.
- uint32_t failure_to_apply = 0;
-
- // Apply mutations as long as the `program` is valid, the limit on the number
- // of mutations is not reached and the mutator is not stuck (i.e. unable to
- // apply any mutations for some time).
- while (program.IsValid() && applied_mutations < max_applied_mutations &&
- failure_to_apply < kMaxFailureToApply) {
- // Get all applicable mutations from some mutation finder.
- const auto& mutation_finder = finders[probability_context->GetRandomIndex(finders)];
- auto mutations = mutation_finder->FindMutations(program, &node_id_map, probability_context);
-
- const auto old_applied_mutations = applied_mutations;
- for (const auto& mutation : mutations) {
- if (!probability_context->ChoosePercentage(
- mutation_finder->GetChanceOfApplyingMutation(probability_context))) {
- // Skip this `mutation` probabilistically.
- continue;
- }
-
- if (!MaybeApplyMutation(program, *mutation, node_id_map, program, &node_id_map,
- mutation_sequence)) {
- // This `mutation` is inapplicable. This may happen if some of the
- // earlier mutations cancelled this one.
- continue;
- }
-
- applied_mutations++;
- if (!program.IsValid()) {
- // This `mutation` has a bug.
- return program;
- }
- }
-
- if (old_applied_mutations == applied_mutations) {
- // No mutation was applied. Increase the counter to prevent an infinite
- // loop.
- failure_to_apply++;
- } else {
- failure_to_apply = 0;
- }
- }
-
- return program;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutator.h b/src/tint/fuzzers/tint_ast_fuzzer/mutator.h
deleted file mode 100644
index c7e8dd2..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/mutator.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATOR_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATOR_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/mutation_finder.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.h"
-
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-/// @file
-
-/// @brief Tries to apply a `mutation` to the `program`.
-///
-/// If the `mutation` is inapplicable, this function will return `false` and
-/// `out_program`, `out_node_id_map` and `mutation_sequence` won't be modified.
-///
-/// The `mutation` is required to produce a valid program when the
-/// `Mutation::Apply` method is called. This guarantees that this function
-/// returns a valid program as well.
-///
-/// @param program - the initial program (must be valid).
-/// @param mutation - the mutation that will be applied.
-/// @param node_id_map - a map from `tint::ast::` nodes in the `program` to
-/// their unique ids.
-/// @param out_program - the resulting mutated program will be written through
-/// this pointer. It may *not* be a `nullptr`. It _may_ point to `program`,
-/// so that a program can be updated in place.
-/// @param out_node_id_map - will contain new ids for the AST nodes in the
-/// mutated program. It may *not* be a `nullptr`. It _may_ point to
-/// `node_id_map`, so that a map can be updated in place.
-/// @param mutation_sequence - the message about this mutation will be recorded
-/// here. It may be a `nullptr`, in which case it's ignored.
-/// @return `true` if the `mutation` was applied.
-/// @return `false` if the `mutation` is inapplicable.
-bool MaybeApplyMutation(const tint::Program& program,
- const Mutation& mutation,
- const NodeIdMap& node_id_map,
- tint::Program& out_program,
- NodeIdMap* out_node_id_map,
- protobufs::MutationSequence* mutation_sequence);
-
-/// @brief Applies mutations from `mutations_sequence` to the `program`.
-///
-/// All mutations in `mutation_sequence` must be applicable. Additionally, all
-/// mutations must produce a valid program when the `Mutation::Apply` method is
-/// called. This guarantees that this function returns a valid program as well.
-///
-/// @param program - the initial program - must be valid.
-/// @param mutation_sequence - a sequence of mutations.
-/// @return the mutated program.
-tint::Program Replay(tint::Program program, const protobufs::MutationSequence& mutation_sequence);
-
-/// @brief Applies up to `max_applied_mutations` mutations to the `program`.
-///
-/// All applied mutations must produce valid programs. This guarantees that the
-/// returned program is valid as well. The returned program may be identical to
-/// the initial `program` if no mutation was applied.
-///
-/// @param program - initial program - must be valid.
-/// @param probability_context - contains information about various
-/// probabilistic behaviour of the fuzzer.
-/// @param enable_all_mutations - if `false`, only mutations from a
-/// probabilistically selected set of mutation types are applied. If `true`,
-/// all mutation types are considered.
-/// @param max_applied_mutations - the maximum number of applied mutations. This
-/// may not be 0.
-/// @param mutation_sequence - applied mutations will be recorded into this
-/// protobuf message. This argument may be `nullptr`, in which case it's
-/// ignored.
-/// @return the mutated program.
-tint::Program Mutate(tint::Program program,
- ProbabilityContext* probability_context,
- bool enable_all_mutations,
- uint32_t max_applied_mutations,
- protobufs::MutationSequence* mutation_sequence);
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_MUTATOR_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.cc b/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.cc
deleted file mode 100644
index 3563f5c..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h"
-
-#include <cassert>
-
-namespace tint::fuzzers::ast_fuzzer {
-
-NodeIdMap::NodeIdMap() = default;
-
-NodeIdMap::NodeIdMap(const Program& program) : NodeIdMap() {
- for (const auto* node : program.ASTNodes().Objects()) {
- Add(node, TakeFreshId());
- }
-}
-
-NodeIdMap::IdType NodeIdMap::GetId(const ast::Node* node) const {
- auto it = node_to_id_.find(node);
- return it == node_to_id_.end() ? 0 : it->second;
-}
-
-const ast::Node* NodeIdMap::GetNode(IdType id) const {
- auto it = id_to_node_.find(id);
- return it == id_to_node_.end() ? nullptr : it->second;
-}
-
-void NodeIdMap::Add(const ast::Node* node, IdType id) {
- assert(!node_to_id_.count(node) && "The node already exists in the map");
- assert(IdIsFreshAndValid(id) && "Id already exists in the map or Id is zero");
- assert(node && "`node` can't be a nullptr");
-
- node_to_id_[node] = id;
- id_to_node_[id] = node;
-
- if (id >= fresh_id_) {
- fresh_id_ = id + 1;
- }
-}
-
-bool NodeIdMap::IdIsFreshAndValid(IdType id) const {
- return id && !id_to_node_.count(id);
-}
-
-NodeIdMap::IdType NodeIdMap::TakeFreshId() {
- assert(fresh_id_ != 0 && "`NodeIdMap` id has overflowed");
- return fresh_id_++;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h b/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h
deleted file mode 100644
index 3ca227b..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/node_id_map.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_NODE_ID_MAP_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_NODE_ID_MAP_H_
-
-#include <unordered_map>
-
-#include "src/tint/lang/wgsl/program/program.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// Contains a one-to-one mapping between the nodes in the AST of the program
-/// and their ids.
-///
-/// The motivation for having this mapping is:
-/// - To be able to uniquely identify a node in the AST. This will be used
-/// to record transformations in the protobuf messages.
-/// - When the AST is being modified, only the mapping for the modified nodes
-/// must be affected. That is, if some node is unchanged, it must have the
-/// same id defined in this class.
-///
-/// This class achieves these goals partially. Concretely, the only way to
-/// change the AST is by cloning it since all instances of `tint::ast::` classes
-/// are immutable. This will invalidate all the pointers to the AST nodes which
-/// are used in this class. To overcome this, a new instance of this class is
-/// created with all the cloned nodes and the old instance is discarded.
-class NodeIdMap {
- public:
- /// Type of the id used by this map.
- using IdType = uint32_t;
-
- /// Creates an empty map.
- NodeIdMap();
-
- /// @brief Initializes this instance with all the nodes in the `program`.
- /// @param program - must be valid.
- explicit NodeIdMap(const Program& program);
-
- /// @brief Returns a node for the given `id`.
- /// @param id - any value is accepted.
- /// @return a pointer to some node if `id` exists in this map.
- /// @return `nullptr` otherwise.
- const ast::Node* GetNode(IdType id) const;
-
- /// @brief Returns an id of the given `node`.
- /// @param node - can be a `nullptr`.
- /// @return not equal to 0 if `node` exists in this map.
- /// @return 0 otherwise.
- IdType GetId(const ast::Node* node) const;
-
- /// @brief Adds a mapping from `node` to `id` to this map.
- /// @param node - may not be a `nullptr` and can't be present in this map.
- /// @param id - may not be 0 and can't be present in this map.
- void Add(const ast::Node* node, IdType id);
-
- /// @brief Returns whether the id is fresh by checking if it exists in
- /// the id map and the id is not 0.
- /// @param id - an id that is used to check in the map.
- /// @return true the given id is fresh and valid (non-zero).
- /// @return false otherwise.
- bool IdIsFreshAndValid(IdType id) const;
-
- /// @brief Returns an id that is guaranteed to be unoccupied in this map.
- ///
- /// This will effectively increase the counter. This means that two
- /// consecutive calls to this method will return different ids.
- ///
- /// @return an unoccupied id.
- IdType TakeFreshId();
-
- private:
- IdType fresh_id_ = 1;
-
- std::unordered_map<const ast::Node*, IdType> node_to_id_;
- std::unordered_map<IdType, const ast::Node*> id_to_node_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_NODE_ID_MAP_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h b/src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h
deleted file mode 100644
index 04deb3a..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_OVERRIDE_CLI_PARAMS_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_OVERRIDE_CLI_PARAMS_H_
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// @brief Allows CLI parameters to be overridden.
-///
-/// This function allows fuzz targets to override particular CLI parameters,
-/// for example forcing a particular back-end to be targeted.
-///
-/// @param cli_params - the parsed CLI parameters to be updated.
-void OverrideCliParams(CliParams& cli_params);
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_OVERRIDE_CLI_PARAMS_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/probability_context.cc b/src/tint/fuzzers/tint_ast_fuzzer/probability_context.cc
deleted file mode 100644
index ab19c76..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/probability_context.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/probability_context.h"
-
-#include <cassert>
-
-namespace tint::fuzzers::ast_fuzzer {
-namespace {
-
-const std::pair<uint32_t, uint32_t> kChanceOfChangingBinaryOperators = {30, 90};
-const std::pair<uint32_t, uint32_t> kChanceOfChangingUnaryOperators = {30, 70};
-const std::pair<uint32_t, uint32_t> kChanceOfDeletingStatements = {30, 70};
-const std::pair<uint32_t, uint32_t> kChanceOfReplacingIdentifiers = {30, 70};
-const std::pair<uint32_t, uint32_t> kChanceOfWrappingUnaryOperators = {30, 70};
-
-} // namespace
-
-ProbabilityContext::ProbabilityContext(RandomGenerator* generator)
- : generator_(generator),
- chance_of_changing_binary_operators_(RandomFromRange(kChanceOfChangingBinaryOperators)),
- chance_of_changing_unary_operators_(RandomFromRange(kChanceOfChangingUnaryOperators)),
- chance_of_deleting_statements_(RandomFromRange(kChanceOfDeletingStatements)),
- chance_of_replacing_identifiers_(RandomFromRange(kChanceOfReplacingIdentifiers)),
- chance_of_wrapping_unary_operators_(RandomFromRange(kChanceOfWrappingUnaryOperators)) {
- assert(generator != nullptr && "generator must not be nullptr");
-}
-
-uint32_t ProbabilityContext::RandomFromRange(std::pair<uint32_t, uint32_t> range) {
- assert(range.first <= range.second && "Range must be non-decreasing");
- return generator_->GetUInt32(range.first,
- range.second + 1); // + 1 need since range is inclusive.
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/probability_context.h b/src/tint/fuzzers/tint_ast_fuzzer/probability_context.h
deleted file mode 100644
index 8f63caf..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/probability_context.h
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROBABILITY_CONTEXT_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROBABILITY_CONTEXT_H_
-
-#include <utility>
-#include <vector>
-
-#include "src/tint/fuzzers/random_generator.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-/// This class is intended to be used by the `MutationFinder`s to introduce some
-/// variance to the mutation process.
-class ProbabilityContext {
- public:
- /// Initializes this instance with a random number generator.
- /// @param generator - must not be a `nullptr`. Must remain in scope as long
- /// as this
- /// instance exists.
- explicit ProbabilityContext(RandomGenerator* generator);
-
- /// Get random bool with even odds
- /// @returns true 50% of the time and false %50 of time.
- bool RandomBool() { return generator_->GetBool(); }
-
- /// Get random bool with weighted odds
- /// @param percentage - likelihood of true being returned
- /// @returns true |percentage|% of the time, and false (100 - |percentage|)%
- /// of the time.
- bool ChoosePercentage(uint32_t percentage) { return generator_->GetWeightedBool(percentage); }
-
- /// Returns a random value in the range `[0; arr.size())`.
- /// @tparam T - type of the elements in the vector.
- /// @param arr - may not be empty.
- /// @return the random index in the `arr`.
- template <typename T>
- size_t GetRandomIndex(const std::vector<T>& arr) {
- return static_cast<size_t>(generator_->GetUInt64(arr.size()));
- }
-
- /// @return the probability of replacing some binary operator with another.
- uint32_t GetChanceOfChangingBinaryOperators() const {
- return chance_of_changing_binary_operators_;
- }
-
- /// @return the probability of changing operator for an unary expression.
- uint32_t GetChanceOfChangingUnaryOperators() const {
- return chance_of_changing_unary_operators_;
- }
-
- /// @return the probability of changing operator for a binary expression.
- uint32_t GetChanceOfDeletingStatements() const { return chance_of_deleting_statements_; }
-
- /// @return the probability of replacing some identifier with some other one.
- uint32_t GetChanceOfReplacingIdentifiers() const { return chance_of_replacing_identifiers_; }
-
- /// @return the probability of wrapping an expression in a unary operator.
- uint32_t GetChanceOfWrappingUnaryOperators() const {
- return chance_of_wrapping_unary_operators_;
- }
-
- private:
- /// @param range - a pair of integers `a` and `b` s.t. `a <= b`.
- /// @return an random number in the range `[a; b]`.
- uint32_t RandomFromRange(std::pair<uint32_t, uint32_t> range);
-
- RandomGenerator* generator_;
-
- uint32_t chance_of_changing_binary_operators_;
- uint32_t chance_of_changing_unary_operators_;
- uint32_t chance_of_deleting_statements_;
- uint32_t chance_of_replacing_identifiers_;
- uint32_t chance_of_wrapping_unary_operators_;
-};
-
-} // namespace tint::fuzzers::ast_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROBABILITY_CONTEXT_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.h b/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.h
deleted file mode 100644
index 9804ae1..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROTOBUFS_TINT_AST_FUZZER_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROTOBUFS_TINT_AST_FUZZER_H_
-
-// Compilation of the protobuf library and its autogenerated code can produce
-// warnings. Ignore them since we can't control them.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-parameter"
-#pragma clang diagnostic ignored "-Wreserved-id-macro"
-#pragma clang diagnostic ignored "-Wsign-conversion"
-#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
-#pragma clang diagnostic ignored "-Wextra-semi-stmt"
-#pragma clang diagnostic ignored "-Winconsistent-missing-destructor-override"
-#pragma clang diagnostic ignored "-Wweak-vtables"
-#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
-#pragma clang diagnostic ignored "-Wreserved-identifier"
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.pb.h"
-
-#pragma clang diagnostic pop
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_PROTOBUFS_TINT_AST_FUZZER_H_
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.proto b/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.proto
deleted file mode 100644
index 02e581c..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/protobufs/tint_ast_fuzzer.proto
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-syntax = "proto3";
-
-package tint.fuzzers.ast_fuzzer.protobufs;
-
-message Mutation {
- oneof mutation {
- MutationReplaceIdentifier replace_identifier = 1;
- MutationChangeBinaryOperator change_binary_operator = 2;
- MutationWrapUnaryOperator wrap_unary_operator = 3;
- MutationChangeUnaryOperator change_unary_operator = 4;
- MutationDeleteStatement delete_statement = 5;
- };
-}
-
-message MutationSequence {
- repeated Mutation mutation = 1;
-}
-
-message MutatorState {
- // Contains the state of the fuzzer.
-
- // The program that is being fuzzed. This can be either
- // the original program (if mutation sequence is available) or
- // the mutated version (if mutations are being recorded).
- string program = 1;
-
- // The sequence of mutations that was applied to the `program`.
- // This may not have any mutations if they are not being recorded.
- MutationSequence mutation_sequence = 2;
-}
-
-// Keep mutation messages in alphabetical order.
-
-message MutationChangeBinaryOperator {
- // This transformation replaces one binary operator with another.
-
- // The id of a binary expression in the AST.
- uint32 binary_expr_id = 1;
-
- // A BinaryOp representing the new binary operator.
- uint32 new_operator = 2;
-}
-
-message MutationChangeUnaryOperator {
- // This transformation replaces one unary operator with another.
-
- // The id of a unary expression in the AST.
- uint32 unary_expr_id = 1;
-
- // A UnaryOp representing the new unary operator.
- uint32 new_operator = 2;
-}
-
-message MutationDeleteStatement {
- // This transformation deletes a statement, as long as doing so does not
- // invalidate the program.
-
- // The id of a statement to be deleted.
- uint32 statement_id = 1;
-}
-
-message MutationReplaceIdentifier {
- // This transformation replaces a use of one variable with another.
-
- // The id of the use of a variable in the AST.
- uint32 use_id = 1;
-
- // The id of a definition of a variable to replace the use with.
- uint32 replacement_id = 2;
-}
-
-message MutationWrapUnaryOperator {
- // This transformation wraps an expression with a allowed unary
- // expression operator.
-
- // The id of the expression.
- uint32 expression_id = 1;
-
- // A fresh id for the created unary expression.
- uint32 fresh_id = 2;
-
- // The unary operator to wrap the expression with.
- uint32 unary_op_wrapper = 3;
-}
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_fuzzer.cc
deleted file mode 100644
index c6c1755..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_fuzzer.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-void OverrideCliParams(CliParams& /*unused*/) {
- // Leave the CLI parameters unchanged.
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_hlsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_hlsl_writer_fuzzer.cc
deleted file mode 100644
index ae80d25..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_hlsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kHlsl;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_msl_writer_fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_msl_writer_fuzzer.cc
deleted file mode 100644
index 455d025..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_msl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kMsl;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_spv_writer_fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_spv_writer_fuzzer.cc
deleted file mode 100644
index d265d4d..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_spv_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kSpv;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_wgsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_wgsl_writer_fuzzer.cc
deleted file mode 100644
index a9e7f7c..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/tint_ast_wgsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_ast_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_ast_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::ast_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kWgsl;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer
diff --git a/src/tint/fuzzers/tint_ast_fuzzer/util.h b/src/tint/fuzzers/tint_ast_fuzzer/util.h
deleted file mode 100644
index b4a6cc5..0000000
--- a/src/tint/fuzzers/tint_ast_fuzzer/util.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_AST_FUZZER_UTIL_H_
-#define SRC_TINT_FUZZERS_TINT_AST_FUZZER_UTIL_H_
-
-#include <vector>
-
-#include "src/tint/lang/wgsl/ast/module.h"
-#include "src/tint/lang/wgsl/ast/variable_decl_statement.h"
-#include "src/tint/lang/wgsl/program/program.h"
-#include "src/tint/lang/wgsl/sem/block_statement.h"
-#include "src/tint/lang/wgsl/sem/function.h"
-#include "src/tint/lang/wgsl/sem/statement.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-#include "src/tint/utils/rtti/castable.h"
-
-namespace tint::fuzzers::ast_fuzzer::util {
-/// @file
-
-/// @brief Returns all in-scope variables (including formal function parameters)
-/// related to statement `curr_stmt`.
-///
-/// These variables are additionally filtered by applying a predicate `pred`.
-///
-/// @tparam Pred - a predicate that accepts a `const sem::Variable*` and returns
-/// `bool`.
-/// @param program - the program to look for variables in.
-/// @param curr_stmt - the current statement. Everything below it is not in
-/// scope.
-/// @param pred - a predicate (e.g. a function pointer, functor, lambda etc) of
-/// type `Pred`.
-/// @return a vector of all variables that can be accessed from `curr_stmt`.
-template <typename Pred>
-std::vector<const sem::Variable*> GetAllVarsInScope(const tint::Program& program,
- const sem::Statement* curr_stmt,
- Pred&& pred) {
- std::vector<const sem::Variable*> result;
-
- // Walk up the hierarchy of blocks in which `curr_stmt` is contained.
- for (const auto* block = curr_stmt->Block(); block;
- block = tint::As<sem::BlockStatement>(block->Parent())) {
- for (const auto* stmt : block->Declaration()->statements) {
- if (stmt == curr_stmt->Declaration()) {
- // `curr_stmt` was found. This is only possible if `block is the
- // enclosing block of `curr_stmt` since the AST nodes are not shared.
- // Because of all this, skip the iteration of the inner loop since
- // the rest of the instructions in the `block` are not visible from the
- // `curr_stmt`.
- break;
- }
-
- if (const auto* var_node = tint::As<ast::VariableDeclStatement>(stmt)) {
- const auto* sem_var = program.Sem().Get(var_node->variable);
- if (pred(sem_var)) {
- result.push_back(sem_var);
- }
- }
- }
- }
-
- // Process function parameters.
- for (const auto* param : curr_stmt->Function()->Parameters()) {
- if (pred(param)) {
- result.push_back(param);
- }
- }
-
- // Global variables do not belong to any ast::BlockStatement.
- for (const auto* global_decl : program.AST().GlobalDeclarations()) {
- if (global_decl == curr_stmt->Function()->Declaration()) {
- // The same situation as in the previous loop. The current function has
- // been reached. If there are any variables declared below, they won't be
- // visible in this function. Thus, exit the loop.
- break;
- }
-
- if (const auto* global_var = tint::As<ast::Variable>(global_decl)) {
- const auto* sem_node = program.Sem().Get(global_var);
- if (pred(sem_node)) {
- result.push_back(sem_node);
- }
- }
- }
-
- return result;
-}
-
-} // namespace tint::fuzzers::ast_fuzzer::util
-
-#endif // SRC_TINT_FUZZERS_TINT_AST_FUZZER_UTIL_H_
diff --git a/src/tint/fuzzers/tint_binding_remapper_fuzzer.cc b/src/tint/fuzzers/tint_binding_remapper_fuzzer.cc
deleted file mode 100644
index 5ae730c..0000000
--- a/src/tint/fuzzers/tint_binding_remapper_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<ast::transform::BindingRemapper>();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_common_fuzzer.cc b/src/tint/fuzzers/tint_common_fuzzer.cc
deleted file mode 100644
index be3a673..0000000
--- a/src/tint/fuzzers/tint_common_fuzzer.cc
+++ /dev/null
@@ -1,405 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-
-#include <algorithm>
-#include <cassert>
-#include <cstring>
-#include <fstream>
-#include <iostream>
-#include <memory>
-#include <sstream>
-#include <string>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-#if TINT_BUILD_SPV_READER || TINT_BUILD_SPV_WRITER
-#include "spirv-tools/libspirv.hpp"
-#endif // TINT_BUILD_SPV_READER || TINT_BUILD_SPV_WRITER
-
-#include "src/tint/api/common/binding_point.h"
-#include "src/tint/lang/core/type/external_texture.h"
-#include "src/tint/lang/wgsl/ast/module.h"
-#include "src/tint/lang/wgsl/helpers/apply_substitute_overrides.h"
-#include "src/tint/lang/wgsl/helpers/flatten_bindings.h"
-#include "src/tint/lang/wgsl/program/program.h"
-#include "src/tint/lang/wgsl/sem/variable.h"
-#include "src/tint/utils/diagnostic/formatter.h"
-#include "src/tint/utils/math/hash.h"
-#include "src/tint/utils/text/styled_text.h"
-#include "src/tint/utils/text/styled_text_printer.h"
-#include "src/tint/utils/text/text_style.h"
-
-#if TINT_BUILD_SPV_WRITER
-#include "src/tint/lang/spirv/writer/helpers/ast_generate_bindings.h"
-#endif // TINT_BUILD_SPV_WRITER
-
-#if TINT_BUILD_MSL_WRITER
-#include "src/tint/lang/msl/writer/helpers/generate_bindings.h"
-#endif // TINT_BUILD_MSL_WRITER
-
-#if TINT_BUILD_HLSL_WRITER
-#include "src/tint/lang/hlsl/writer/helpers/generate_bindings.h"
-#endif // TINT_BUILD_MSL_WRITER
-
-namespace tint::fuzzers {
-
-namespace {
-
-// A macro is used to avoid FATAL_ERROR creating its own stack frame. This leads
-// to better de-duplication of bug reports, because ClusterFuzz only uses the
-// top few stack frames for de-duplication, and a FATAL_ERROR stack frame
-// provides no useful information.
-#define FATAL_ERROR(diags, msg_string) \
- do { \
- StyledText msg; \
- msg << (style::Error + style::Bold) << msg_string; \
- auto printer = tint::StyledTextPrinter::Create(stderr); \
- printer->Print(msg); \
- printer->Print(tint::diag::Formatter().Format(diags)); \
- __builtin_trap(); \
- } while (false)
-
-[[noreturn]] void TintInternalCompilerErrorReporter(const InternalCompilerError& err) {
- std::cerr << err.Error() << std::endl;
- __builtin_trap();
-}
-
-// Wrapping in a macro, so it can be a one-liner in the code, but not
-// introduce another level in the stack trace. This will help with de-duping
-// ClusterFuzz issues.
-#define CHECK_INSPECTOR(program, inspector) \
- do { \
- if ((inspector).has_error()) { \
- if (!enforce_validity) { \
- return; \
- } \
- FATAL_ERROR(program.Diagnostics(), "Inspector failed: " + (inspector).error()); \
- } \
- } while (false)
-
-// Wrapping in a macro to make code more readable and help with issue de-duping.
-#define VALIDITY_ERROR(diags, msg_string) \
- do { \
- if (!enforce_validity) { \
- return 0; \
- } \
- FATAL_ERROR(diags, msg_string); \
- } while (false)
-
-bool SPIRVToolsValidationCheck(const tint::Program& program, const std::vector<uint32_t>& spirv) {
- spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_1);
- const tint::diag::List& diags = program.Diagnostics();
- tools.SetMessageConsumer(
- [diags](spv_message_level_t, const char*, const spv_position_t& pos, const char* msg) {
- StyledText out;
- out << "Unexpected spirv-val error:\n"
- << (pos.line + 1) << ":" << (pos.column + 1) << ": " << msg;
-
- auto printer = tint::StyledTextPrinter::Create(stderr);
- printer->Print(out);
- printer->Print(tint::diag::Formatter().Format(diags));
- });
-
- return tools.Validate(spirv.data(), spirv.size(), spvtools::ValidatorOptions());
-}
-
-} // namespace
-
-void GenerateSpirvOptions(DataBuilder* b, spirv::writer::Options* options) {
- *options = b->build<spirv::writer::Options>();
-}
-
-void GenerateWgslOptions(DataBuilder* b, wgsl::writer::Options* options) {
- *options = b->build<wgsl::writer::Options>();
-}
-
-void GenerateHlslOptions(DataBuilder* b, hlsl::writer::Options* options) {
- *options = b->build<hlsl::writer::Options>();
-}
-
-void GenerateMslOptions(DataBuilder* b, msl::writer::Options* options) {
- *options = b->build<msl::writer::Options>();
-}
-
-CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
- : input_(input), output_(output) {}
-
-CommonFuzzer::~CommonFuzzer() = default;
-
-int CommonFuzzer::Run(const uint8_t* data, size_t size) {
- tint::Initialize();
- tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
-
- Program program;
-
-#if TINT_BUILD_SPV_READER
- std::vector<uint32_t> spirv_input(size / sizeof(uint32_t));
-
-#endif // TINT_BUILD_SPV_READER
-
-#if TINT_BUILD_WGSL_READER || TINT_BUILD_SPV_READER
- auto dump_input_data = [&](auto& content, const char* extension) {
- size_t hash = Hash(content);
- auto filename = "fuzzer_input_" + std::to_string(hash) + extension; //
- std::ofstream fout(filename, std::ios::binary);
- fout.write(reinterpret_cast<const char*>(data), static_cast<std::streamsize>(size));
- std::cout << "Dumped input data to " << filename << std::endl;
- };
-#endif
-
- switch (input_) {
- case InputFormat::kWGSL: {
-#if TINT_BUILD_WGSL_READER
- // Clear any existing diagnostics, as these will hold pointers to file_,
- // which we are about to release.
- diagnostics_ = {};
- std::string str(reinterpret_cast<const char*>(data), size);
- file_ = std::make_unique<Source::File>("test.wgsl", str);
- if (dump_input_) {
- dump_input_data(str, ".wgsl");
- }
- program = wgsl::reader::Parse(file_.get());
-#endif // TINT_BUILD_WGSL_READER
- break;
- }
-
- case InputFormat::kSpv: {
-#if TINT_BUILD_SPV_READER
- // `spirv_input` has been initialized with the capacity to store `size /
- // sizeof(uint32_t)` uint32_t values. If `size` is not a multiple of
- // sizeof(uint32_t) then not all of `data` can be copied into
- // `spirv_input`, and any trailing bytes are discarded.
- std::memcpy(spirv_input.data(), data, spirv_input.size() * sizeof(uint32_t));
- if (spirv_input.empty()) {
- return 0;
- }
- if (dump_input_) {
- dump_input_data(spirv_input, ".spv");
- }
- program = spirv::reader::Read(spirv_input);
-#endif // TINT_BUILD_SPV_READER
- break;
- }
- }
-
- if (!program.IsValid()) {
- diagnostics_ = program.Diagnostics();
- return 0;
- }
-
- // Helper that returns `true` if the program uses the given extension.
- auto uses_extension = [&program](tint::wgsl::Extension extension) {
- for (auto* enable : program.AST().Enables()) {
- if (enable->HasExtension(extension)) {
- return true;
- }
- }
- return false;
- };
-
-#if TINT_BUILD_SPV_READER
- if (input_ == InputFormat::kSpv && !SPIRVToolsValidationCheck(program, spirv_input)) {
- FATAL_ERROR(program.Diagnostics(),
- "Fuzzing detected invalid input spirv not being caught by Tint");
- }
-#endif // TINT_BUILD_SPV_READER
-
- RunInspector(program);
- diagnostics_ = program.Diagnostics();
-
- auto validate_program = [&](auto& out) {
- if (!out.IsValid()) {
- // Transforms can produce error messages for bad input.
- // Catch ICEs and errors from non transform systems.
- for (const auto& diag : out.Diagnostics()) {
- if (diag.severity > diag::Severity::Error ||
- diag.system != diag::System::Transform) {
- VALIDITY_ERROR(program.Diagnostics(),
- "Fuzzing detected valid input program being "
- "transformed into an invalid output program");
- }
- }
- return 0;
- }
-
- program = std::move(out);
- RunInspector(program);
- return 1;
- };
-
- if (transform_manager_) {
- ast::transform::DataMap outputs;
- auto out = transform_manager_->Run(program, *transform_inputs_, outputs);
- if (!validate_program(out)) { // Will move: program <- out on success
- return 0;
- }
- }
-
- // Run SubstituteOverride if required
- if (auto transformed = tint::wgsl::ApplySubstituteOverrides(program)) {
- program = std::move(*transformed);
- if (!program.IsValid()) {
- return 0;
- }
- }
-
- switch (output_) {
- case OutputFormat::kMSL:
-#if TINT_BUILD_MSL_WRITER
- options_msl_.bindings = tint::msl::writer::GenerateBindings(program);
-#endif // TINT_BUILD_MSL_WRITER
- break;
- case OutputFormat::kHLSL:
-#if TINT_BUILD_HLSL_WRITER
- options_hlsl_.bindings = tint::hlsl::writer::GenerateBindings(program);
-#endif // TINT_BUILD_HLSL_WRITER
- break;
- case OutputFormat::kSpv:
-#if TINT_BUILD_SPV_WRITER
- options_spirv_.bindings = tint::spirv::writer::GenerateBindings(program);
-#endif // TINT_BUILD_SPV_WRITER
- break;
- case OutputFormat::kWGSL:
- break;
- }
-
- switch (output_) {
- case OutputFormat::kWGSL: {
-#if TINT_BUILD_WGSL_WRITER
- (void)wgsl::writer::Generate(program, options_wgsl_);
-#endif // TINT_BUILD_WGSL_WRITER
- break;
- }
- case OutputFormat::kSpv: {
-#if TINT_BUILD_SPV_WRITER
- // Skip fuzzing the SPIR-V writer when the `clamp_frag_depth` option is used with a
- // module that already contains push constants.
- if (uses_extension(tint::wgsl::Extension::kChromiumExperimentalPushConstant) &&
- options_spirv_.clamp_frag_depth) {
- return 0;
- }
-
- auto result = spirv::writer::Generate(program, options_spirv_);
- if (result == Success) {
- generated_spirv_ = std::move(result->spirv);
-
- if (!SPIRVToolsValidationCheck(program, generated_spirv_)) {
- VALIDITY_ERROR(program.Diagnostics(),
- "Fuzzing detected invalid spirv being emitted by Tint");
- }
- }
-
-#endif // TINT_BUILD_SPV_WRITER
- break;
- }
- case OutputFormat::kHLSL: {
-#if TINT_BUILD_HLSL_WRITER
- (void)hlsl::writer::Generate(program, options_hlsl_);
-#endif // TINT_BUILD_HLSL_WRITER
- break;
- }
- case OutputFormat::kMSL: {
-#if TINT_BUILD_MSL_WRITER
- // Remap resource numbers to a flat namespace.
- // TODO(crbug.com/tint/1501): Do this via Options::BindingMap.
- if (auto flattened = tint::wgsl::FlattenBindings(program)) {
- program = std::move(*flattened);
- }
-
- (void)msl::writer::Generate(program, options_msl_);
-#endif // TINT_BUILD_MSL_WRITER
- break;
- }
- }
-
- return 0;
-}
-
-void CommonFuzzer::RunInspector(Program& program) {
- inspector::Inspector inspector(program);
- diagnostics_ = program.Diagnostics();
-
- if (!program.IsValid()) {
- // It's not safe to use the inspector on invalid programs.
- return;
- }
-
- auto entry_points = inspector.GetEntryPoints();
- CHECK_INSPECTOR(program, inspector);
-
- auto override_ids = inspector.GetOverrideDefaultValues();
- CHECK_INSPECTOR(program, inspector);
-
- auto override_name_to_id = inspector.GetNamedOverrideIds();
- CHECK_INSPECTOR(program, inspector);
-
- for (auto& ep : entry_points) {
- inspector.GetResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetUniformBufferResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetStorageBufferResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetReadOnlyStorageBufferResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetSamplerResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetComparisonSamplerResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetSampledTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetMultisampledTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetStorageTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetDepthTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetDepthMultisampledTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetExternalTextureResourceBindings(ep.name);
- CHECK_INSPECTOR(program, inspector);
-
- inspector.GetSamplerTextureUses(ep.name);
- CHECK_INSPECTOR(program, inspector);
- }
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_common_fuzzer.h b/src/tint/fuzzers/tint_common_fuzzer.h
deleted file mode 100644
index 9593fea..0000000
--- a/src/tint/fuzzers/tint_common_fuzzer.h
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_COMMON_FUZZER_H_
-#define SRC_TINT_FUZZERS_TINT_COMMON_FUZZER_H_
-
-#include <cassert>
-#include <cstring>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "include/tint/tint.h"
-
-#include "src/tint/fuzzers/data_builder.h"
-
-namespace tint::fuzzers {
-
-// TODO(crbug.com/tint/1356): Add using shader reflection to generate options
-// that are potentially valid for Generate*Options
-// functions.
-/// Generates random set of options for SPIRV generation
-void GenerateSpirvOptions(DataBuilder* b, spirv::writer::Options* options);
-
-/// Generates random set of options for WGSL generation
-void GenerateWgslOptions(DataBuilder* b, wgsl::writer::Options* options);
-
-/// Generates random set of options for HLSL generation
-void GenerateHlslOptions(DataBuilder* b, hlsl::writer::Options* options);
-
-/// Generates random set of options for MSL generation
-void GenerateMslOptions(DataBuilder* b, msl::writer::Options* options);
-
-/// Shader language the fuzzer is reading
-enum class InputFormat { kWGSL, kSpv };
-
-/// Shader language the fuzzer is emitting
-enum class OutputFormat { kWGSL, kSpv, kHLSL, kMSL };
-
-/// Generic runner for reading and emitting shaders using Tint, used by most
-/// fuzzers to share common code.
-class CommonFuzzer {
- public:
- /// Constructor
- /// @param input shader language being read
- /// @param output shader language being emitted
- CommonFuzzer(InputFormat input, OutputFormat output);
-
- /// Destructor
- ~CommonFuzzer();
-
- /// @param tm manager for transforms to run
- /// @param inputs data for transforms to run
- void SetTransformManager(ast::transform::Manager* tm, ast::transform::DataMap* inputs) {
- assert((!tm || inputs) && "DataMap must be !nullptr if Manager !nullptr");
- transform_manager_ = tm;
- transform_inputs_ = inputs;
- }
-
- /// @param enabled if the input shader for run should be outputted to the log
- void SetDumpInput(bool enabled) { dump_input_ = enabled; }
-
- /// @param enabled if the shader being valid after parsing is being enforced.
- /// If false, invalidation of the shader will cause an early exit, but not
- /// throw an error.
- /// If true invalidation will throw an error that is caught by libFuzzer and
- /// will generate a crash report.
- void SetEnforceValidity(bool enabled) { enforce_validity = enabled; }
-
- /// Convert given shader from input to output format.
- /// Will also apply provided transforms and run the inspector over the result.
- /// @param data buffer of data that will interpreted as a byte array or string
- /// depending on the shader input format.
- /// @param size number of elements in buffer
- /// @returns 0, this is what libFuzzer expects
- int Run(const uint8_t* data, size_t size);
-
- /// @returns diagnostic messages generated while Run() is executed.
- const tint::diag::List& Diagnostics() const { return diagnostics_; }
-
- /// @returns if there are any errors in the diagnostic messages
- bool HasErrors() const { return diagnostics_.ContainsErrors(); }
-
- /// @returns generated SPIR-V binary, if SPIR-V was emitted.
- const std::vector<uint32_t>& GetGeneratedSpirv() const { return generated_spirv_; }
-
- /// @returns generated WGSL string, if WGSL was emitted.
- const std::string& GetGeneratedWgsl() const { return generated_wgsl_; }
-
- /// @returns generated HLSL string, if HLSL was emitted.
- const std::string& GetGeneratedHlsl() const { return generated_hlsl_; }
-
- /// @returns generated MSL string, if HLSL was emitted.
- const std::string& GetGeneratedMsl() const { return generated_msl_; }
-
- /// @param options SPIR-V emission options
- void SetOptionsSpirv(const spirv::writer::Options& options) { options_spirv_ = options; }
-
- /// @param options WGSL emission options
- void SetOptionsWgsl(const wgsl::writer::Options& options) { options_wgsl_ = options; }
-
- /// @param options HLSL emission options
- void SetOptionsHlsl(const hlsl::writer::Options& options) { options_hlsl_ = options; }
-
- /// @param options MSL emission options
- void SetOptionsMsl(const msl::writer::Options& options) { options_msl_ = options; }
-
- private:
- InputFormat input_;
- OutputFormat output_;
- ast::transform::Manager* transform_manager_ = nullptr;
- ast::transform::DataMap* transform_inputs_ = nullptr;
- bool dump_input_ = false;
- tint::diag::List diagnostics_;
- bool enforce_validity = false;
-
- std::vector<uint32_t> generated_spirv_;
- std::string generated_wgsl_;
- std::string generated_hlsl_;
- std::string generated_msl_;
-
- spirv::writer::Options options_spirv_;
- wgsl::writer::Options options_wgsl_;
- hlsl::writer::Options options_hlsl_;
- msl::writer::Options options_msl_;
-
-#if TINT_BUILD_WGSL_READER
- /// The source file needs to live at least as long as #diagnostics_
- std::unique_ptr<Source::File> file_;
-#endif // TINT_BUILD_WGSL_READER
-
- /// Runs a series of reflection operations to exercise the Inspector API.
- void RunInspector(Program& program);
-};
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_TINT_COMMON_FUZZER_H_
diff --git a/src/tint/fuzzers/tint_concurrency_fuzzer.cc b/src/tint/fuzzers/tint_concurrency_fuzzer.cc
deleted file mode 100644
index 7c56d0b..0000000
--- a/src/tint/fuzzers/tint_concurrency_fuzzer.cc
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <fstream>
-#include <iostream>
-#include <string>
-#include <unordered_set>
-
-#include <thread>
-
-#include "src/tint/lang/glsl/writer/writer.h"
-#include "src/tint/lang/hlsl/writer/writer.h"
-#include "src/tint/lang/msl/writer/writer.h"
-#include "src/tint/lang/spirv/writer/writer.h"
-#include "src/tint/lang/wgsl/helpers/apply_substitute_overrides.h"
-#include "src/tint/lang/wgsl/helpers/flatten_bindings.h"
-#include "src/tint/lang/wgsl/inspector/inspector.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/sem/module.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-#include "src/tint/utils/math/hash.h"
-
-static constexpr size_t kNumThreads = 8;
-
-[[noreturn]] void TintInternalCompilerErrorReporter(const tint::InternalCompilerError& err) {
- std::cerr << err.Error() << std::endl;
- __builtin_trap();
-}
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
-
- std::string str(reinterpret_cast<const char*>(data), size);
- auto file = std::make_unique<tint::Source::File>("test.wgsl", str);
- auto program = tint::wgsl::reader::Parse(file.get());
- if (!program.IsValid()) {
- return 0;
- }
-
- if (program.Sem().Module()->Extensions().Contains(
- tint::wgsl::Extension::kChromiumExperimentalPixelLocal)) {
- return 0; // Not supported
- }
-
- if (auto transformed = tint::wgsl::ApplySubstituteOverrides(program)) {
- program = std::move(*transformed);
- if (!program.IsValid()) {
- return 0;
- }
- }
-
- tint::inspector::Inspector inspector(program);
- auto entry_points = inspector.GetEntryPoints();
- std::string entry_point = entry_points.empty() ? "" : entry_points.front().name;
-
- std::array<std::thread, kNumThreads> threads;
-
- for (size_t thread_idx = 0; thread_idx < kNumThreads; thread_idx++) {
- auto thread = std::thread([&program, thread_idx, entry_point] {
- enum class Writer {
-#if TINT_BUILD_GLSL_WRITER
- kGLSL,
-#endif
-#if TINT_BUILD_HLSL_WRITER
- kHLSL,
-#endif
-#if TINT_BUILD_MSL_WRITER
- kMSL,
-#endif
-#if TINT_BUILD_SPV_WRITER
- kSPIRV,
-#endif
-#if TINT_BUILD_WGSL_WRITER
- kWGSL,
-#endif
- kCount
- };
- switch (static_cast<Writer>(thread_idx % static_cast<size_t>(Writer::kCount))) {
-#if TINT_BUILD_WGSL_WRITER
- case Writer::kWGSL: {
- (void)tint::wgsl::writer::Generate(program, {});
- break;
- }
-#endif // TINT_BUILD_WGSL_WRITER
-
-#if TINT_BUILD_SPV_WRITER
- case Writer::kSPIRV: {
- (void)tint::spirv::writer::Generate(program, {});
- break;
- }
-#endif // TINT_BUILD_SPV_WRITER
-
-#if TINT_BUILD_HLSL_WRITER
- case Writer::kHLSL: {
- (void)tint::hlsl::writer::Generate(program, {});
- break;
- }
-#endif // TINT_BUILD_HLSL_WRITER
-
-#if TINT_BUILD_GLSL_WRITER
- case Writer::kGLSL: {
- (void)tint::glsl::writer::Generate(program, {}, entry_point);
- break;
- }
-#endif // TINT_BUILD_GLSL_WRITER
-
-#if TINT_BUILD_MSL_WRITER
- case Writer::kMSL: {
- // Remap resource numbers to a flat namespace.
- if (auto flattened = tint::wgsl::FlattenBindings(program)) {
- (void)tint::msl::writer::Generate(flattened.value(), {});
- }
- break;
- }
-#endif // TINT_BUILD_MSL_WRITER
-
- case Writer::kCount:
- break;
- }
- });
- threads[thread_idx] = std::move(thread);
- }
-
- for (auto& thread : threads) {
- thread.join();
- }
-
- return 0;
-}
diff --git a/src/tint/fuzzers/tint_first_index_offset_fuzzer.cc b/src/tint/fuzzers/tint_first_index_offset_fuzzer.cc
deleted file mode 100644
index 3feb71f..0000000
--- a/src/tint/fuzzers/tint_first_index_offset_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<ast::transform::FirstIndexOffset>();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_reader_writer_fuzzer.h b/src/tint/fuzzers/tint_reader_writer_fuzzer.h
deleted file mode 100644
index c449ed3..0000000
--- a/src/tint/fuzzers/tint_reader_writer_fuzzer.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_READER_WRITER_FUZZER_H_
-#define SRC_TINT_FUZZERS_TINT_READER_WRITER_FUZZER_H_
-
-#include <memory>
-
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-/// Wrapper around the common fuzzing class for tint_*_reader_*_writter fuzzers
-class ReaderWriterFuzzer : public CommonFuzzer {
- public:
- /// Constructor
- /// Pass through to the CommonFuzzer constructor
- /// @param input shader language being read
- /// @param output shader language being emitted
- ReaderWriterFuzzer(InputFormat input, OutputFormat output) : CommonFuzzer(input, output) {}
-
- /// Destructor
- ~ReaderWriterFuzzer() {}
-
- /// Pass through to the CommonFuzzer setter, but records if it has been
- /// invoked.
- /// @param tm manager for transforms to run
- /// @param inputs data for transforms to run
- void SetTransformManager(ast::transform::Manager* tm, ast::transform::DataMap* inputs) {
- tm_set_ = true;
- CommonFuzzer::SetTransformManager(tm, inputs);
- }
-
- /// Pass through to the CommonFuzzer implementation.
- /// @param data buffer of data that will interpreted as a byte array or string depending on the
- /// shader input format.
- /// @param size number of elements in buffer
- /// @returns 0, this is what libFuzzer expects
- int Run(const uint8_t* data, size_t size) {
- if (!tm_set_) {
- tb_ = std::make_unique<TransformBuilder>(data, size);
- SetTransformManager(tb_->manager(), tb_->data_map());
- }
-
- return CommonFuzzer::Run(data, size);
- }
-
- private:
- bool tm_set_ = false;
- std::unique_ptr<TransformBuilder> tb_;
-};
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_TINT_READER_WRITER_FUZZER_H_
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/BUILD.gn b/src/tint/fuzzers/tint_regex_fuzzer/BUILD.gn
deleted file mode 100644
index 4a66a81..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/BUILD.gn
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2021 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import("//build_overrides/build.gni")
-import("../../../../scripts/tint_overrides_with_defaults.gni")
-
-if (tint_has_fuzzers) {
- source_set("tint_regex_fuzzer") {
- public_configs = [
- "${tint_src_dir}:tint_config",
- "${tint_src_dir}:tint_common_config",
- ]
-
- deps = [ "${tint_src_dir}/fuzzers:tint_fuzzer_common_src" ]
-
- sources = [
- "cli.cc",
- "cli.h",
- "fuzzer.cc",
- "override_cli_params.h",
- "wgsl_mutator.cc",
- "wgsl_mutator.h",
- ]
- }
-}
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/CMakeLists.txt b/src/tint/fuzzers/tint_regex_fuzzer/CMakeLists.txt
deleted file mode 100644
index 337acdd..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/CMakeLists.txt
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright 2021 The Dawn & Tint Authors
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-function(add_tint_regex_fuzzer NAME)
- add_executable(${NAME} ${NAME}.cc ${REGEX_FUZZER_SOURCES})
- target_link_libraries(${NAME} PRIVATE libtint_regex_fuzzer tint_lang_hlsl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE libtint_regex_fuzzer tint_lang_msl_writer_helpers)
- target_link_libraries(${NAME} PRIVATE libtint_regex_fuzzer tint_lang_spirv_writer_helpers)
- tint_fuzzer_compile_options(${NAME})
- tint_spvtools_compile_options(${NAME})
- target_compile_definitions(${NAME} PRIVATE CUSTOM_MUTATOR)
- target_include_directories(${NAME} PRIVATE ${CMAKE_BINARY_DIR})
-endfunction()
-
-set(LIBTINT_REGEX_FUZZER_SOURCES
- ../mersenne_twister_engine.cc
- ../mersenne_twister_engine.h
- ../random_generator.cc
- ../random_generator.h
- ../random_generator_engine.cc
- ../random_generator_engine.h
- wgsl_mutator.cc
- wgsl_mutator.h)
-
-# Add static library target.
-add_library(libtint_regex_fuzzer STATIC ${LIBTINT_REGEX_FUZZER_SOURCES})
-tint_default_compile_options(libtint_regex_fuzzer)
-
-set(REGEX_FUZZER_SOURCES
- cli.cc
- cli.h
- fuzzer.cc
- override_cli_params.h
- ../tint_common_fuzzer.cc
- ../tint_common_fuzzer.h)
-
-set_source_files_properties(fuzzer.cc PROPERTIES COMPILE_FLAGS -Wno-missing-prototypes)
-
-# Add libfuzzer targets.
-# Targets back-ends according to command line arguments.
-add_tint_regex_fuzzer(tint_regex_fuzzer)
-# Targets back-ends individually.
-add_tint_regex_fuzzer(tint_regex_hlsl_writer_fuzzer)
-add_tint_regex_fuzzer(tint_regex_msl_writer_fuzzer)
-add_tint_regex_fuzzer(tint_regex_spv_writer_fuzzer)
-add_tint_regex_fuzzer(tint_regex_wgsl_writer_fuzzer)
-
-# Add tests.
-if (${TINT_BUILD_TESTS})
- set(TEST_SOURCES
- regex_fuzzer_tests.cc)
-
- add_executable(tint_regex_fuzzer_unittests ${TEST_SOURCES})
-
- target_include_directories(
- tint_regex_fuzzer_unittests PRIVATE ${gmock_SOURCE_DIR}/include)
- target_link_libraries(tint_regex_fuzzer_unittests gmock_main libtint_regex_fuzzer)
- tint_default_compile_options(tint_regex_fuzzer_unittests)
- target_compile_options(tint_regex_fuzzer_unittests PRIVATE
- -Wno-global-constructors
- -Wno-weak-vtables
- -Wno-covered-switch-default)
-
- target_include_directories(tint_regex_fuzzer_unittests PRIVATE ${CMAKE_BINARY_DIR})
-
- add_test(NAME tint_regex_fuzzer_unittests COMMAND tint_regex_fuzzer_unittests)
-endif ()
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/cli.cc b/src/tint/fuzzers/tint_regex_fuzzer/cli.cc
deleted file mode 100644
index 73ea77c..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/cli.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-
-#include <cstring>
-#include <iostream>
-#include <limits>
-#include <sstream>
-#include <string>
-#include <utility>
-
-namespace tint::fuzzers::regex_fuzzer {
-namespace {
-
-const char* const kHelpMessage = R"(
-This is a fuzzer for the Tint compiler that works by mutating a WGSL shader.
-
-Below is a list of all supported parameters for this fuzzer. You may want to
-run it with -help=1 to check out libfuzzer parameters.
-
- -tint_fuzzing_target=
- Specifies the shading language to target during fuzzing.
- This must be one or a combination of `wgsl`, `spv`, `hlsl`,
- `msl` (without `) separated by commas. By default it's
- `wgsl,msl,hlsl,spv`.
-
- -tint_help
- Show this message. Note that there is also a -help=1
- parameter that will display libfuzzer's help message.
-)";
-
-bool HasPrefix(const char* str, const char* prefix) {
- return strncmp(str, prefix, strlen(prefix)) == 0;
-}
-
-[[noreturn]] void InvalidParam(const char* param) {
- std::cout << "Invalid value for " << param << std::endl;
- std::cout << kHelpMessage << std::endl;
- exit(1);
-}
-
-bool ParseFuzzingTarget(const char* value, FuzzingTarget* out) {
- if (!strcmp(value, "wgsl")) {
- *out = FuzzingTarget::kWgsl;
- } else if (!strcmp(value, "spv")) {
- *out = FuzzingTarget::kSpv;
- } else if (!strcmp(value, "msl")) {
- *out = FuzzingTarget::kMsl;
- } else if (!strcmp(value, "hlsl")) {
- *out = FuzzingTarget::kHlsl;
- } else {
- return false;
- }
- return true;
-}
-
-} // namespace
-
-CliParams ParseCliParams(int* argc, char** argv) {
- CliParams cli_params;
- auto help = false;
-
- for (int i = *argc - 1; i > 0; --i) {
- auto param = argv[i];
- auto recognized_parameter = true;
-
- if (HasPrefix(param, "-tint_fuzzing_target=")) {
- auto result = FuzzingTarget::kNone;
-
- std::stringstream ss(param + sizeof("-tint_fuzzing_target=") - 1);
- for (std::string value; std::getline(ss, value, ',');) {
- auto tmp = FuzzingTarget::kNone;
- if (!ParseFuzzingTarget(value.c_str(), &tmp)) {
- InvalidParam(param);
- }
- result = result | tmp;
- }
-
- if (result == FuzzingTarget::kNone) {
- InvalidParam(param);
- }
-
- cli_params.fuzzing_target = result;
- } else if (!strcmp(param, "-tint_help")) {
- help = true;
- } else {
- recognized_parameter = false;
- }
-
- if (recognized_parameter) {
- // Remove the recognized parameter from the list of all parameters by
- // swapping it with the last one. This will suppress warnings in the
- // libFuzzer about unrecognized parameters. By default, libFuzzer thinks
- // that all user-defined parameters start with two dashes. However, we are
- // forced to use a single one to make the fuzzer compatible with the
- // ClusterFuzz.
- std::swap(argv[i], argv[*argc - 1]);
- *argc -= 1;
- }
- }
-
- if (help) {
- std::cout << kHelpMessage << std::endl;
- exit(0);
- }
-
- return cli_params;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/cli.h b/src/tint/fuzzers/tint_regex_fuzzer/cli.h
deleted file mode 100644
index f802646..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/cli.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_CLI_H_
-#define SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_CLI_H_
-
-#include <cstdint>
-
-namespace tint::fuzzers::regex_fuzzer {
-
-/// The backend this fuzzer will test.
-enum class FuzzingTarget {
- kNone = 0,
- kHlsl = 1 << 0,
- kMsl = 1 << 1,
- kSpv = 1 << 2,
- kWgsl = 1 << 3,
- kAll = kHlsl | kMsl | kSpv | kWgsl
-};
-
-inline FuzzingTarget operator|(FuzzingTarget a, FuzzingTarget b) {
- return static_cast<FuzzingTarget>(static_cast<int>(a) | static_cast<int>(b));
-}
-
-inline FuzzingTarget operator&(FuzzingTarget a, FuzzingTarget b) {
- return static_cast<FuzzingTarget>(static_cast<int>(a) & static_cast<int>(b));
-}
-
-/// CLI parameters accepted by the fuzzer. Type -tint_help in the CLI to see the
-/// help message
-struct CliParams {
- /// Compiler backends we want to fuzz.
- FuzzingTarget fuzzing_target = FuzzingTarget::kAll;
-};
-
-/// @brief Parses CLI parameters.
-///
-/// This function will exit the process with non-zero return code if some
-/// parameters are invalid. This function will remove recognized parameters from
-/// `argv` and adjust `argc` accordingly.
-///
-/// @param argc - the total number of parameters.
-/// @param argv - array of all CLI parameters.
-/// @return parsed parameters.
-CliParams ParseCliParams(int* argc, char** argv);
-
-} // namespace tint::fuzzers::regex_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_CLI_H_
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/fuzzer.cc
deleted file mode 100644
index a039cbf..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/fuzzer.cc
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-#include <cstddef>
-#include <cstdint>
-
-#include "src/tint/fuzzers/random_generator.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h"
-#include "src/tint/fuzzers/transform_builder.h"
-#include "src/tint/lang/wgsl/reader/reader.h"
-#include "src/tint/lang/wgsl/writer/writer.h"
-#include "testing/libfuzzer/libfuzzer_exports.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-namespace {
-
-CliParams cli_params{};
-
-enum class MutationKind {
- kSwapIntervals,
- kDeleteInterval,
- kDuplicateInterval,
- kReplaceIdentifier,
- kReplaceLiteral,
- kInsertReturnStatement,
- kReplaceOperator,
- kInsertBreakOrContinue,
- kReplaceFunctionCallWithBuiltin,
- kAddSwizzle,
- kNumMutationKinds
-};
-
-extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
- // Parse CLI parameters. `ParseCliParams` will call `exit` if some parameter
- // is invalid.
- cli_params = ParseCliParams(argc, *argv);
- // For some fuzz targets it is desirable to force the values of certain CLI
- // parameters after parsing.
- OverrideCliParams(cli_params);
- return 0;
-}
-
-extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data,
- size_t size,
- size_t max_size,
- unsigned seed) {
- std::string wgsl_code(data, data + size);
- const std::vector<std::string> delimiters{";"};
- RandomGenerator generator(seed);
-
- std::string delimiter =
- delimiters[generator.GetUInt32(static_cast<uint32_t>(delimiters.size()))];
-
- MutationKind mutation_kind = static_cast<MutationKind>(
- generator.GetUInt32(static_cast<uint32_t>(MutationKind::kNumMutationKinds)));
-
- WgslMutator mutator(generator);
- switch (mutation_kind) {
- case MutationKind::kSwapIntervals:
- if (!mutator.SwapRandomIntervals(delimiter, wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kDeleteInterval:
- if (!mutator.DeleteRandomInterval(delimiter, wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kDuplicateInterval:
- if (!mutator.DuplicateRandomInterval(delimiter, wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kReplaceIdentifier:
- if (!mutator.ReplaceRandomIdentifier(wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kReplaceLiteral:
- if (!mutator.ReplaceRandomIntLiteral(wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kInsertReturnStatement:
- if (!mutator.InsertReturnStatement(wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kReplaceOperator:
- if (!mutator.ReplaceRandomOperator(wgsl_code)) {
- return 0;
- }
- break;
-
- case MutationKind::kInsertBreakOrContinue:
- if (!mutator.InsertBreakOrContinue(wgsl_code)) {
- return 0;
- }
- break;
- case MutationKind::kReplaceFunctionCallWithBuiltin:
- if (!mutator.ReplaceFunctionCallWithBuiltin(wgsl_code)) {
- return 0;
- }
- break;
- case MutationKind::kAddSwizzle:
- if (!mutator.AddSwizzle(wgsl_code)) {
- return 0;
- }
- break;
- default:
- assert(false && "Unreachable");
- return 0;
- }
-
- if (wgsl_code.size() > max_size) {
- return 0;
- }
-
- memcpy(data, wgsl_code.c_str(), wgsl_code.size());
- return wgsl_code.size();
-}
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size == 0) {
- return 0;
- }
-
- struct Target {
- FuzzingTarget fuzzing_target;
- OutputFormat output_format;
- const char* name;
- };
-
- Target targets[] = {{FuzzingTarget::kWgsl, OutputFormat::kWGSL, "WGSL"},
- {FuzzingTarget::kHlsl, OutputFormat::kHLSL, "HLSL"},
- {FuzzingTarget::kMsl, OutputFormat::kMSL, "MSL"},
- {FuzzingTarget::kSpv, OutputFormat::kSpv, "SPV"}};
-
- for (auto target : targets) {
- if ((target.fuzzing_target & cli_params.fuzzing_target) != target.fuzzing_target) {
- continue;
- }
-
- TransformBuilder tb(data, size);
- tb.AddTransform<tint::ast::transform::Robustness>();
-
- CommonFuzzer fuzzer(InputFormat::kWGSL, target.output_format);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
-
- fuzzer.Run(data, size);
- }
-
- return 0;
-}
-
-} // namespace
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h b/src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h
deleted file mode 100644
index d788889..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_OVERRIDE_CLI_PARAMS_H_
-#define SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_OVERRIDE_CLI_PARAMS_H_
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-/// @brief Allows CLI parameters to be overridden.
-///
-/// This function allows fuzz targets to override particular CLI parameters,
-/// for example forcing a particular back-end to be targeted.
-///
-/// @param cli_params - the parsed CLI parameters to be updated.
-void OverrideCliParams(CliParams& cli_params);
-
-} // namespace tint::fuzzers::regex_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_OVERRIDE_CLI_PARAMS_H_
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/regex_fuzzer_tests.cc b/src/tint/fuzzers/tint_regex_fuzzer/regex_fuzzer_tests.cc
deleted file mode 100644
index 3146d9c..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/regex_fuzzer_tests.cc
+++ /dev/null
@@ -1,690 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <optional>
-#include <string>
-
-#include "gtest/gtest.h"
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-namespace {
-
-class WgslMutatorTest : public WgslMutator {
- public:
- explicit WgslMutatorTest(RandomGenerator& generator) : WgslMutator(generator) {}
-
- using WgslMutator::DeleteInterval;
- using WgslMutator::DuplicateInterval;
- using WgslMutator::FindClosingBracket;
- using WgslMutator::FindOperatorOccurrence;
- using WgslMutator::GetFunctionBodyPositions;
- using WgslMutator::GetFunctionCallIdentifiers;
- using WgslMutator::GetIdentifiers;
- using WgslMutator::GetIntLiterals;
- using WgslMutator::GetLoopBodyPositions;
- using WgslMutator::GetSwizzles;
- using WgslMutator::GetVectorInitializers;
- using WgslMutator::ReplaceRegion;
- using WgslMutator::SwapIntervals;
-};
-
-// Swaps two non-consecutive regions in the edge
-TEST(SwapRegionsTest, SwapIntervalsEdgeNonConsecutive) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;";
- std::string all_regions = R1 + R2 + R3;
-
- // this call should swap R1 with R3.
- mutator.SwapIntervals(0, R1.length(), R1.length() + R2.length(), R3.length(), all_regions);
-
- ASSERT_EQ(R3 + R2 + R1, all_regions);
-}
-
-// Swaps two non-consecutive regions not in the edge
-TEST(SwapRegionsTest, SwapIntervalsNonConsecutiveNonEdge) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // this call should swap R2 with R4.
- mutator.SwapIntervals(R1.length(), R2.length(), R1.length() + R2.length() + R3.length(),
- R4.length(), all_regions);
-
- ASSERT_EQ(R1 + R4 + R3 + R2 + R5, all_regions);
-}
-
-// Swaps two consecutive regions not in the edge (sorrounded by other
-// regions)
-TEST(SwapRegionsTest, SwapIntervalsConsecutiveEdge) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4;
-
- // this call should swap R2 with R3.
- mutator.SwapIntervals(R1.length(), R2.length(), R1.length() + R2.length(), R3.length(),
- all_regions);
-
- ASSERT_EQ(R1 + R3 + R2 + R4, all_regions);
-}
-
-// Swaps two consecutive regions not in the edge (not sorrounded by other
-// regions)
-TEST(SwapRegionsTest, SwapIntervalsConsecutiveNonEdge) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // this call should swap R4 with R5.
- mutator.SwapIntervals(R1.length() + R2.length() + R3.length(), R4.length(),
- R1.length() + R2.length() + R3.length() + R4.length(), R5.length(),
- all_regions);
-
- ASSERT_EQ(R1 + R2 + R3 + R5 + R4, all_regions);
-}
-
-// Deletes the first region.
-TEST(DeleteRegionTest, DeleteFirstRegion) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should delete R1.
- mutator.DeleteInterval(0, R1.length(), all_regions);
-
- ASSERT_EQ(";" + R2 + R3 + R4 + R5, all_regions);
-}
-
-// Deletes the last region.
-TEST(DeleteRegionTest, DeleteLastRegion) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should delete R5.
- mutator.DeleteInterval(R1.length() + R2.length() + R3.length() + R4.length(), R5.length(),
- all_regions);
-
- ASSERT_EQ(R1 + R2 + R3 + R4 + ";", all_regions);
-}
-
-// Deletes the middle region.
-TEST(DeleteRegionTest, DeleteMiddleRegion) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should delete R3.
- mutator.DeleteInterval(R1.length() + R2.length(), R3.length(), all_regions);
-
- ASSERT_EQ(R1 + R2 + ";" + R4 + R5, all_regions);
-}
-
-TEST(InsertRegionTest, InsertRegionTest1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should insert R2 after R4.
- mutator.DuplicateInterval(R1.length(), R2.length(),
- R1.length() + R2.length() + R3.length() + R4.length() - 1,
- all_regions);
-
- ASSERT_EQ(R1 + R2 + R3 + R4 + R2.substr(1, R2.size() - 1) + R5, all_regions);
-}
-
-TEST(InsertRegionTest, InsertRegionTest2) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
-
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should insert R3 after R1.
- mutator.DuplicateInterval(R1.length() + R2.length(), R3.length(), R1.length() - 1, all_regions);
-
- ASSERT_EQ(R1 + R3.substr(1, R3.length() - 1) + R2 + R3 + R4 + R5, all_regions);
-}
-
-TEST(InsertRegionTest, InsertRegionTest3) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = ";region1;", R2 = ";regionregion2;", R3 = ";regionregionregion3;",
- R4 = ";regionregionregionregion4;", R5 = ";regionregionregionregionregion5;";
-
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // This call should insert R2 after R5.
- mutator.DuplicateInterval(R1.length(), R2.length(), all_regions.length() - 1, all_regions);
-
- ASSERT_EQ(R1 + R2 + R3 + R4 + R5 + R2.substr(1, R2.length() - 1), all_regions);
-}
-
-TEST(ReplaceIdentifierTest, ReplaceIdentifierTest1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = "|region1|", R2 = "; region2;", R3 = "---------region3---------",
- R4 = "++region4++", R5 = "***region5***";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // Replaces R3 with R1.
- mutator.ReplaceRegion(0, R1.length(), R1.length() + R2.length(), R3.length(), all_regions);
-
- ASSERT_EQ(R1 + R2 + R1 + R4 + R5, all_regions);
-}
-
-TEST(ReplaceIdentifierTest, ReplaceIdentifierTest2) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string R1 = "|region1|", R2 = "; region2;", R3 = "---------region3---------",
- R4 = "++region4++", R5 = "***region5***";
- std::string all_regions = R1 + R2 + R3 + R4 + R5;
-
- // Replaces R5 with R3.
- mutator.ReplaceRegion(R1.length() + R2.length(), R3.length(),
- R1.length() + R2.length() + R3.length() + R4.length(), R5.length(),
- all_regions);
-
- ASSERT_EQ(R1 + R2 + R3 + R4 + R3, all_regions);
-}
-
-TEST(GetIdentifierTest, GetIdentifierTest1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();"
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {"
- var<private> foo: f32 = 0.0;
- clamp_0acf8f();
- })";
-
- std::vector<std::pair<size_t, size_t>> identifiers_pos = mutator.GetIdentifiers(wgsl_code);
- std::vector<std::pair<size_t, size_t>> ground_truth = {
- {3, 12}, {32, 3}, {49, 5}, {126, 11}, {144, 7}, {152, 8}, {183, 12},
- {262, 13}, {288, 12}, {328, 14}, {355, 12}, {385, 7}, {394, 3}, {418, 12}};
- ASSERT_EQ(ground_truth, identifiers_pos);
-}
-
-TEST(TestGetLiteralsValues, TestGetLiteralsValues1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();
- var foo_1: i32 = 3;
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;)";
-
- std::vector<std::pair<size_t, size_t>> literals_pos = mutator.GetIntLiterals(wgsl_code);
-
- std::vector<std::string> ground_truth = {"3", "10", "5", "7", "-20"};
-
- std::vector<std::string> result;
-
- for (auto pos : literals_pos) {
- result.push_back(wgsl_code.substr(pos.first, pos.second));
- }
-
- ASSERT_EQ(ground_truth, result);
-}
-
-TEST(InsertReturnTest, FindClosingBrace) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- if(false){
-
- } else{
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();
- var foo_1: i32 = 3;
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;
- )";
- size_t opening_bracket_pos = 18;
- size_t closing_bracket_pos =
- mutator.FindClosingBracket(opening_bracket_pos, wgsl_code, '{', '}');
-
- // The -1 is needed since the function body starts after the left bracket.
- std::string function_body =
- wgsl_code.substr(opening_bracket_pos + 1, closing_bracket_pos - opening_bracket_pos - 1);
- std::string expected =
- R"(
- if(false){
-
- } else{
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- )";
- ASSERT_EQ(expected, function_body);
-}
-
-TEST(InsertReturnTest, FindClosingBraceFailing) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- // This comment } causes the test to fail.
- "if(false){
-
- } else{
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();
- var foo_1: i32 = 3;
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;)";
- size_t opening_bracket_pos = 18;
- size_t closing_bracket_pos =
- mutator.FindClosingBracket(opening_bracket_pos, wgsl_code, '{', '}');
-
- // The -1 is needed since the function body starts after the left bracket.
- std::string function_body =
- wgsl_code.substr(opening_bracket_pos + 1, closing_bracket_pos - opening_bracket_pos - 1);
- std::string expected =
- R"(// This comment } causes the test to fail.
- "if(false){
-
- } else{
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- })";
- ASSERT_NE(expected, function_body);
-}
-
-TEST(TestInsertReturn, TestFunctionPositions1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();
- var foo_1: i32 = 3;
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- fn vert_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();
- var foo_1: i32 = 3;
- return vec4<f32>();
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;)";
-
- std::vector<std::pair<size_t, bool>> function_positions =
- mutator.GetFunctionBodyPositions(wgsl_code);
- std::vector<std::pair<size_t, bool>> expected_positions = {
- {18, false}, {180, true}, {323, false}, {423, false}, {586, true}};
- ASSERT_EQ(expected_positions, function_positions);
-}
-
-TEST(TestInsertReturn, TestFunctionPositions2) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn some_loop_body() {
-}
-
-fn f() {
- var j : i32; i = (i + 1)) {
- some_loop_body(); ((i < 5) && (j < 10));
- for(var i : i32 = 0;
- j = (i * 30);
- }
-}
-)";
-
- std::vector<std::pair<size_t, bool>> function_positions =
- mutator.GetFunctionBodyPositions(wgsl_code);
- std::vector<std::pair<size_t, bool>> expected_positions = {{20, false}, {32, false}};
- ASSERT_EQ(expected_positions, function_positions);
-}
-
-TEST(TestInsertReturn, TestMissingSemicolon) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>())
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f()
- var foo_1: i32 = 3
- return vec4<f32>()
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- fn vert_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f()
- var foo_1: i32 = 3
- return vec4<f32>()
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;)";
-
- mutator.InsertReturnStatement(wgsl_code);
-
- // No semicolons found in the function's body, so wgsl_code
- // should remain unchanged.
- std::string expected_wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>())
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f()
- var foo_1: i32 = 3
- return vec4<f32>()
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f();
- }
- fn vert_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f()
- var foo_1: i32 = 3
- return vec4<f32>()
- }
- foo_1 = 5 + 7;
- var foo_3 : i32 = -20;)";
- ASSERT_EQ(expected_wgsl_code, wgsl_code);
-}
-
-TEST(TestReplaceOperator, TestIdentifyOperators) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string code =
- R"(
-x += 2;
-y = a + b;
-z = -a;
-x *= b / c;
-t = t && t | t || t;
-b = b > c ^ c <= d;
-a >>= b;
-b <<= a;
-a = a << 2;
-b = b >> 3;
-c = a % 3;
-d %= e;
-)";
- // These are the operator occurrences that will be observed by going through the file character
- // by character. This includes, for example, identifying the ">" operator if search starts after
- // the first character of ">>".
- std::vector<std::pair<uint32_t, uint32_t>> operator_occurrences = {
- {3, 2}, {4, 1}, {11, 1}, {15, 1}, {22, 1}, {24, 1}, {30, 2}, {31, 1},
- {35, 1}, {42, 1}, {46, 2}, {47, 1}, {51, 1}, {55, 2}, {56, 1}, {63, 1},
- {67, 1}, {71, 1}, {75, 2}, {76, 1}, {83, 3}, {84, 2}, {85, 1}, {92, 3},
- {93, 2}, {94, 1}, {101, 1}, {105, 2}, {106, 1}, {113, 1}, {117, 2}, {118, 1},
- {125, 1}, {129, 1}, {136, 2}, {137, 1}, {3, 2}};
- uint32_t operator_occurrence_index = 0;
- for (size_t i = 0; i < code.length(); i++) {
- // Move on to the next operator occurrence if the current index into the code string exceeds
- // the index associated with that operator occurrence. Exception: stay with the last
- // operator occurrence if search has already passed the last operator in the file.
- if (i < code.length() - 2 && i > operator_occurrences[operator_occurrence_index].first) {
- operator_occurrence_index =
- (operator_occurrence_index + 1) % operator_occurrences.size();
- }
- ASSERT_EQ(operator_occurrences[operator_occurrence_index],
- mutator.FindOperatorOccurrence(code, static_cast<uint32_t>(i)).value());
- }
-}
-
-TEST(TestReplaceOperator, TestFindOperatorOccurrenceOnSmallStrings) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- ASSERT_FALSE(mutator.FindOperatorOccurrence("", 0).has_value());
- ASSERT_FALSE(mutator.FindOperatorOccurrence(" ", 0).has_value());
- ASSERT_FALSE(mutator.FindOperatorOccurrence(" ", 0).has_value());
-}
-
-TEST(TestInsertBreakOrContinue, TestLoopPositions1) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code = " loop { } loop { } loop { }";
- std::vector<size_t> loop_positions = mutator.GetLoopBodyPositions(wgsl_code);
- std::vector<size_t> expected_positions = {6, 15, 24};
- ASSERT_EQ(expected_positions, loop_positions);
-}
-
-TEST(TestInsertBreakOrContinue, TestLoopPositions2) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code = R"( loop { } loop
-{ } loop { })";
- std::vector<size_t> loop_positions = mutator.GetLoopBodyPositions(wgsl_code);
- std::vector<size_t> expected_positions = {6, 15, 24};
- ASSERT_EQ(expected_positions, loop_positions);
-}
-
-TEST(TestInsertBreakOrContinue, TestLoopPositions3) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- // This WGSL-like code is not valid, but it suffices to test regex-based matching (which is
- // intended to work well on semi-valid code).
- std::string wgsl_code =
- R"(fn compute_main() {
- loop {
- var twice: i32 = 2 * i;
- i++;
- if i == 5 { break; }
- loop
- {
- var twice: i32 = 2 * i;
- i++;
- while (i < 100) { i++; }
- if i == 5 { break; }
- }
- }
- for (a = 0; a < 100; a++) {
- if (a > 50) {
- break;
- }
- while (i < 100) { i++; }
- }
-})";
-
- std::vector<size_t> loop_positions = mutator.GetLoopBodyPositions(wgsl_code);
- std::vector<size_t> expected_positions = {27, 108, 173, 249, 310};
- ASSERT_EQ(expected_positions, loop_positions);
-}
-
-TEST(TestInsertBreakOrContinue, TestLoopPositions4) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string wgsl_code =
- R"(fn clamp_0acf8f() {
- var res: vec2<f32> = clamp(vec2<f32>(), vec2<f32>(), vec2<f32>());
- }
- @vertex
- fn vertex_main() -> @builtin(position) vec4<f32> {
- clamp_0acf8f();"
- return vec4<f32>();
- }
- @fragment
- fn fragment_main() {
- clamp_0acf8f();
- }
- @compute @workgroup_size(1)
- fn compute_main() {"
- var<private> foo: f32 = 0.0;
- clamp_0acf8f ();
- })";
-
- std::vector<size_t> loop_positions = mutator.GetLoopBodyPositions(wgsl_code);
- ASSERT_TRUE(loop_positions.empty());
-}
-
-TEST(TestReplaceFunctionCallWithBuiltin, FindFunctionCalls) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string function_body = R"({
- var<private> foo: f32 = 0.0;
- var foo_2: i32 = 10;
- clamp_0acf8f ();
- _0acf8f();
- f
-();
- j = (i * 30);
- })";
- std::vector<std::pair<size_t, size_t>> call_identifiers =
- mutator.GetFunctionCallIdentifiers(function_body);
- std::vector<std::pair<size_t, size_t>> ground_truth{{82, 12}, {110, 7}, {131, 1}};
- ASSERT_EQ(ground_truth, call_identifiers);
-}
-
-TEST(TestAddSwizzle, FindSwizzles) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string code = R"(x
-v.xxyy.wz.x;
-u.rgba.rrg.b)";
- std::vector<std::pair<size_t, size_t>> swizzles = mutator.GetSwizzles(code);
- std::vector<std::pair<size_t, size_t>> ground_truth{{3, 5}, {8, 3}, {11, 2},
- {16, 5}, {21, 4}, {25, 2}};
- ASSERT_EQ(ground_truth, swizzles);
-}
-
-TEST(TestAddSwizzle, FindVectorInitializers) {
- RandomGenerator generator(0);
- WgslMutatorTest mutator(generator);
- std::string code = R"(
-vec4<f32>(vec2<f32>(1, 2), vec2<f32>(3))
-
-vec2<i32>(1, abs(abs(2)))
-)";
- std::vector<std::pair<size_t, size_t>> swizzles = mutator.GetVectorInitializers(code);
- std::vector<std::pair<size_t, size_t>> ground_truth{{1, 40}, {11, 15}, {28, 12}, {43, 25}};
- ASSERT_EQ(ground_truth, swizzles);
-}
-
-} // namespace
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_fuzzer.cc
deleted file mode 100644
index 38cc32e..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_fuzzer.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-void OverrideCliParams(CliParams& /*unused*/) {
- // Leave the CLI parameters unchanged.
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_hlsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_hlsl_writer_fuzzer.cc
deleted file mode 100644
index 2e6af74..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_hlsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kHlsl;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_msl_writer_fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_msl_writer_fuzzer.cc
deleted file mode 100644
index 9313d90..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_msl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kMsl;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_spv_writer_fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_spv_writer_fuzzer.cc
deleted file mode 100644
index e41aad8..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_spv_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kSpv;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_wgsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_wgsl_writer_fuzzer.cc
deleted file mode 100644
index 9a38484..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/tint_regex_wgsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/cli.h"
-#include "src/tint/fuzzers/tint_regex_fuzzer/override_cli_params.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-void OverrideCliParams(CliParams& cli_params) {
- assert(cli_params.fuzzing_target == FuzzingTarget::kAll &&
- "The fuzzing target should not have been set by a CLI parameter: it "
- "should have its default value.");
- cli_params.fuzzing_target = FuzzingTarget::kWgsl;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc b/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc
deleted file mode 100644
index 4ca17bd..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc
+++ /dev/null
@@ -1,804 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h"
-
-#include <cassert>
-#include <cstring>
-#include <map>
-#include <regex>
-#include <string>
-#include <unordered_set>
-#include <utility>
-#include <vector>
-
-#include "src/tint/fuzzers/random_generator.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-WgslMutator::WgslMutator(RandomGenerator& generator) : generator_(generator) {}
-
-std::vector<size_t> WgslMutator::FindDelimiterIndices(const std::string& delimiter,
- const std::string& wgsl_code) {
- std::vector<size_t> result;
- for (size_t pos = wgsl_code.find(delimiter, 0); pos != std::string::npos;
- pos = wgsl_code.find(delimiter, pos + 1)) {
- result.push_back(pos);
- }
-
- return result;
-}
-
-std::unordered_set<std::string> WgslMutator::GetCommonKeywords() {
- return {"array", "bool", "break", "compute", "continue", "f32", "fn", "fragment",
- "i32", "if", "for", "let", "location", "loop", "ptr", "return",
- "struct", "u32", "var", "vec2", "vec3", "vec4", "vertex", "while"};
-}
-
-std::vector<std::pair<size_t, size_t>> WgslMutator::GetIdentifiers(const std::string& wgsl_code) {
- std::vector<std::pair<size_t, size_t>> result;
-
- // To reduce the rate that invalid programs are produced, common keywords will be excluded from
- // the identifiers that are returned.
- std::unordered_set<std::string> common_keywords = GetCommonKeywords();
-
- // This regular expression works by looking for a character that
- // is not part of an identifier followed by a WGSL identifier, followed
- // by a character which cannot be part of a WGSL identifer. The regex
- // for the WGSL identifier is obtained from:
- // https://www.w3.org/TR/WGSL/#identifiers.
- std::regex identifier_regex("[_a-zA-Z][0-9a-zA-Z_]*");
-
- auto identifiers_begin =
- std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), identifier_regex);
- auto identifiers_end = std::sregex_iterator();
-
- for (std::sregex_iterator i = identifiers_begin; i != identifiers_end; ++i) {
- if (common_keywords.count(i->str()) > 0) {
- // This is a common keyword, so skip it.
- continue;
- }
- result.push_back(
- {static_cast<size_t>(i->prefix().second - wgsl_code.cbegin()), i->str().size()});
- }
- return result;
-}
-
-std::vector<std::pair<size_t, size_t>> WgslMutator::GetFunctionCallIdentifiers(
- const std::string& wgsl_code) {
- std::vector<std::pair<size_t, size_t>> result;
-
- std::regex call_regex("([_a-zA-Z][0-9a-zA-Z_]*)[ \\n]*\\(");
-
- auto identifiers_begin = std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), call_regex);
- auto identifiers_end = std::sregex_iterator();
-
- for (std::sregex_iterator i = identifiers_begin; i != identifiers_end; ++i) {
- auto submatch = (*i)[1];
- result.push_back(
- {static_cast<size_t>(submatch.first - wgsl_code.cbegin()), submatch.str().size()});
- }
- return result;
-}
-
-std::vector<std::pair<size_t, size_t>> WgslMutator::GetIntLiterals(const std::string& s) {
- std::vector<std::pair<size_t, size_t>> result;
-
- // Looks for integer literals in decimal or hexadecimal form.
- // Regex obtained here: https://www.w3.org/TR/WGSL/#literals
- std::regex int_literal_regex("-?0x[0-9a-fA-F]+ | 0 | -?[1-9][0-9]*");
- std::regex uint_literal_regex("0x[0-9a-fA-F]+u | 0u | [1-9][0-9]*u");
- std::smatch match;
-
- std::string::const_iterator search_start(s.cbegin());
- std::string prefix = "";
-
- while (regex_search(search_start, s.cend(), match, int_literal_regex) ||
- regex_search(search_start, s.cend(), match, uint_literal_regex)) {
- prefix += match.prefix();
- result.push_back(std::make_pair(prefix.size() + 1, match.str(0).size() - 1));
- prefix += match.str(0);
- search_start = match.suffix().first;
- }
- return result;
-}
-
-size_t WgslMutator::FindClosingBracket(size_t opening_bracket_pos,
- const std::string& wgsl_code,
- char opening_bracket_character,
- char closing_bracket_character) {
- size_t open_bracket_count = 1;
- size_t pos = opening_bracket_pos + 1;
- while (open_bracket_count >= 1 && pos < wgsl_code.size()) {
- if (wgsl_code[pos] == opening_bracket_character) {
- ++open_bracket_count;
- } else if (wgsl_code[pos] == closing_bracket_character) {
- --open_bracket_count;
- }
- ++pos;
- }
- return (pos == wgsl_code.size() && open_bracket_count >= 1) ? 0 : pos - 1;
-}
-
-std::vector<std::pair<size_t, bool>> WgslMutator::GetFunctionBodyPositions(
- const std::string& wgsl_code) {
- // Finds all the functions with a non-void return value.
- std::regex function_regex("fn[^a-zA-Z_0-9][^\\{]*\\{");
- std::vector<std::pair<size_t, bool>> result;
-
- auto functions_begin = std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), function_regex);
- auto functions_end = std::sregex_iterator();
-
- for (std::sregex_iterator i = functions_begin; i != functions_end; ++i) {
- bool returns_value = i->str().find("->") != std::string::npos;
- result.push_back(
- {static_cast<size_t>(i->suffix().first - wgsl_code.cbegin() - 1), returns_value});
- }
- return result;
-}
-
-std::vector<size_t> WgslMutator::GetLoopBodyPositions(const std::string& wgsl_code) {
- // Finds all loops.
- std::regex loop_regex("[^a-zA-Z_0-9](for|while|loop)[^\\{]*\\{");
- std::vector<size_t> result;
-
- auto loops_begin = std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), loop_regex);
- auto loops_end = std::sregex_iterator();
-
- for (std::sregex_iterator i = loops_begin; i != loops_end; ++i) {
- result.push_back(static_cast<size_t>(i->suffix().first - wgsl_code.cbegin() - 1));
- }
- return result;
-}
-
-bool WgslMutator::InsertReturnStatement(std::string& wgsl_code) {
- std::vector<std::pair<size_t, bool>> function_body_positions =
- GetFunctionBodyPositions(wgsl_code);
-
- // No function was found in wgsl_code.
- if (function_body_positions.empty()) {
- return false;
- }
-
- // Pick a random function
- auto function = generator_.GetRandomElement(function_body_positions);
-
- // Find the corresponding closing bracket for the function, and find a semi-colon within the
- // function body.
- size_t left_bracket_pos = function.first;
-
- size_t right_bracket_pos = FindClosingBracket(left_bracket_pos, wgsl_code, '{', '}');
-
- if (right_bracket_pos == 0) {
- return false;
- }
-
- std::vector<size_t> semicolon_positions;
- for (size_t pos = wgsl_code.find(";", left_bracket_pos + 1); pos < right_bracket_pos;
- pos = wgsl_code.find(";", pos + 1)) {
- semicolon_positions.push_back(pos);
- }
-
- if (semicolon_positions.empty()) {
- return false;
- }
-
- std::string return_statement = "return";
- if (function.second) {
- // The function returns a value. Get all identifiers and integer literals to use as
- // potential return values.
- std::vector<std::pair<size_t, size_t>> identifiers = GetIdentifiers(wgsl_code);
- auto return_values = identifiers;
- std::vector<std::pair<size_t, size_t>> int_literals = GetIntLiterals(wgsl_code);
- return_values.insert(return_values.end(), int_literals.begin(), int_literals.end());
- std::pair<size_t, size_t> return_value = generator_.GetRandomElement(return_values);
- return_statement += " " + wgsl_code.substr(return_value.first, return_value.second);
- }
- return_statement += ";";
-
- // Insert the return statement immediately after the semicolon.
- wgsl_code.insert(generator_.GetRandomElement(semicolon_positions) + 1, return_statement);
- return true;
-}
-
-bool WgslMutator::InsertBreakOrContinue(std::string& wgsl_code) {
- std::vector<size_t> loop_body_positions = GetLoopBodyPositions(wgsl_code);
-
- // No loop was found in wgsl_code.
- if (loop_body_positions.empty()) {
- return false;
- }
-
- // Pick a random loop's opening bracket, find the corresponding closing
- // bracket, and find a semi-colon within the loop body.
- size_t left_bracket_pos = generator_.GetRandomElement(loop_body_positions);
-
- size_t right_bracket_pos = FindClosingBracket(left_bracket_pos, wgsl_code, '{', '}');
-
- if (right_bracket_pos == 0) {
- return false;
- }
-
- std::vector<size_t> semicolon_positions;
- for (size_t pos = wgsl_code.find(";", left_bracket_pos + 1); pos < right_bracket_pos;
- pos = wgsl_code.find(";", pos + 1)) {
- semicolon_positions.push_back(pos);
- }
-
- if (semicolon_positions.empty()) {
- return false;
- }
-
- size_t semicolon_position = generator_.GetRandomElement(semicolon_positions);
-
- // Insert a break or continue immediately after the semicolon.
- wgsl_code.insert(semicolon_position + 1, generator_.GetBool() ? "break;" : "continue;");
- return true;
-}
-
-void WgslMutator::SwapIntervals(size_t idx1,
- size_t reg1_len,
- size_t idx2,
- size_t reg2_len,
- std::string& wgsl_code) {
- std::string region_1 = wgsl_code.substr(idx1 + 1, reg1_len - 1);
-
- std::string region_2 = wgsl_code.substr(idx2 + 1, reg2_len - 1);
-
- // The second transformation is done first as it doesn't affect idx2.
- wgsl_code.replace(idx2 + 1, region_2.size(), region_1);
-
- wgsl_code.replace(idx1 + 1, region_1.size(), region_2);
-}
-
-void WgslMutator::DeleteInterval(size_t idx1, size_t reg_len, std::string& wgsl_code) {
- wgsl_code.erase(idx1 + 1, reg_len - 1);
-}
-
-void WgslMutator::DuplicateInterval(size_t idx1,
- size_t reg1_len,
- size_t idx2,
- std::string& wgsl_code) {
- std::string region = wgsl_code.substr(idx1 + 1, reg1_len - 1);
- wgsl_code.insert(idx2 + 1, region);
-}
-
-void WgslMutator::ReplaceRegion(size_t idx1,
- size_t id1_len,
- size_t idx2,
- size_t id2_len,
- std::string& wgsl_code) {
- std::string region_1 = wgsl_code.substr(idx1, id1_len);
- std::string region_2 = wgsl_code.substr(idx2, id2_len);
- wgsl_code.replace(idx2, region_2.size(), region_1);
-}
-
-void WgslMutator::ReplaceInterval(size_t start_index,
- size_t length,
- std::string replacement_text,
- std::string& wgsl_code) {
- std::string region_1 = wgsl_code.substr(start_index, length);
- wgsl_code.replace(start_index, length, replacement_text);
-}
-
-bool WgslMutator::SwapRandomIntervals(const std::string& delimiter, std::string& wgsl_code) {
- std::vector<size_t> delimiter_positions = FindDelimiterIndices(delimiter, wgsl_code);
-
- // Need to have at least 3 indices.
- if (delimiter_positions.size() < 3) {
- return false;
- }
-
- // Choose indices:
- // interval_1_start < interval_1_end <= interval_2_start < interval_2_end
- uint32_t interval_1_start =
- generator_.GetUInt32(static_cast<uint32_t>(delimiter_positions.size()) - 2u);
- uint32_t interval_1_end = generator_.GetUInt32(
- interval_1_start + 1u, static_cast<uint32_t>(delimiter_positions.size()) - 1u);
- uint32_t interval_2_start = generator_.GetUInt32(
- interval_1_end, static_cast<uint32_t>(delimiter_positions.size()) - 1u);
- uint32_t interval_2_end = generator_.GetUInt32(
- interval_2_start + 1u, static_cast<uint32_t>(delimiter_positions.size()));
-
- SwapIntervals(delimiter_positions[interval_1_start],
- delimiter_positions[interval_1_end] - delimiter_positions[interval_1_start],
- delimiter_positions[interval_2_start],
- delimiter_positions[interval_2_end] - delimiter_positions[interval_2_start],
- wgsl_code);
-
- return true;
-}
-
-bool WgslMutator::DeleteRandomInterval(const std::string& delimiter, std::string& wgsl_code) {
- std::vector<size_t> delimiter_positions = FindDelimiterIndices(delimiter, wgsl_code);
-
- // Need to have at least 2 indices.
- if (delimiter_positions.size() < 2) {
- return false;
- }
-
- uint32_t interval_start =
- generator_.GetUInt32(static_cast<uint32_t>(delimiter_positions.size()) - 1u);
- uint32_t interval_end = generator_.GetUInt32(interval_start + 1u,
- static_cast<uint32_t>(delimiter_positions.size()));
-
- DeleteInterval(delimiter_positions[interval_start],
- delimiter_positions[interval_end] - delimiter_positions[interval_start],
- wgsl_code);
-
- return true;
-}
-
-bool WgslMutator::DuplicateRandomInterval(const std::string& delimiter, std::string& wgsl_code) {
- std::vector<size_t> delimiter_positions = FindDelimiterIndices(delimiter, wgsl_code);
-
- // Need to have at least 2 indices
- if (delimiter_positions.size() < 2) {
- return false;
- }
-
- uint32_t interval_start =
- generator_.GetUInt32(static_cast<uint32_t>(delimiter_positions.size()) - 1u);
- uint32_t interval_end = generator_.GetUInt32(interval_start + 1u,
- static_cast<uint32_t>(delimiter_positions.size()));
- uint32_t duplication_point =
- generator_.GetUInt32(static_cast<uint32_t>(delimiter_positions.size()));
-
- DuplicateInterval(delimiter_positions[interval_start],
- delimiter_positions[interval_end] - delimiter_positions[interval_start],
- delimiter_positions[duplication_point], wgsl_code);
-
- return true;
-}
-
-bool WgslMutator::ReplaceRandomIdentifier(std::string& wgsl_code) {
- std::vector<std::pair<size_t, size_t>> identifiers = GetIdentifiers(wgsl_code);
-
- // Need at least 2 identifiers
- if (identifiers.size() < 2) {
- return false;
- }
-
- uint32_t id1_index = generator_.GetUInt32(static_cast<uint32_t>(identifiers.size()));
- uint32_t id2_index = generator_.GetUInt32(static_cast<uint32_t>(identifiers.size()));
-
- // The two identifiers must be different
- while (id1_index == id2_index) {
- id2_index = generator_.GetUInt32(static_cast<uint32_t>(identifiers.size()));
- }
-
- ReplaceRegion(identifiers[id1_index].first, identifiers[id1_index].second,
- identifiers[id2_index].first, identifiers[id2_index].second, wgsl_code);
-
- return true;
-}
-
-bool WgslMutator::ReplaceRandomIntLiteral(std::string& wgsl_code) {
- std::vector<std::pair<size_t, size_t>> literals = GetIntLiterals(wgsl_code);
-
- // Need at least one integer literal
- if (literals.size() < 1) {
- return false;
- }
-
- uint32_t literal_index = generator_.GetUInt32(static_cast<uint32_t>(literals.size()));
-
- // INT_MAX = 2147483647, INT_MIN = -2147483648
- std::vector<std::string> boundary_values = {"2147483647", "-2147483648", "1",
- "-1", "0", "4294967295"};
-
- uint32_t boundary_index = generator_.GetUInt32(static_cast<uint32_t>(boundary_values.size()));
-
- ReplaceInterval(literals[literal_index].first, literals[literal_index].second,
- boundary_values[boundary_index], wgsl_code);
-
- return true;
-}
-
-std::string WgslMutator::ChooseRandomReplacementForOperator(const std::string& existing_operator) {
- // Operators are partitioned into three classes: assignment, expression and increment. The regex
- // mutator will swap operators in the same class. The hypothesis is that this should exercise a
- // number of type-safe swaps (e.g. changing += to *=), as well as some badly-typed yet
- // interesting swaps (e.g. changing + to ^ when the operators are matrices), while avoiding
- // making totally nonsensical replacements (such as changing ++ too /).
- std::vector<std::string> assignment_operators{
- "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="};
- std::vector<std::string> expression_operators{"+", "-", "*", "/", "%", "&&", "||",
- "&", "|", "^", "<<", ">>", "<", ">",
- "<=", ">=", "!", "==", "!=", "~"};
- std::vector<std::string> increment_operators{"++", "--"};
- for (auto operators : {assignment_operators, expression_operators, increment_operators}) {
- auto it = std::find(operators.begin(), operators.end(), existing_operator);
- if (it != operators.end()) {
- // The operator falls into this category, so select another operator from the category.
- operators.erase(it);
- return generator_.GetRandomElement(operators);
- }
- }
- assert(false && "Unknown operator");
- return "";
-}
-
-bool WgslMutator::ReplaceRandomOperator(std::string& wgsl_code) {
- // Choose an index into the code at random.
- const uint32_t start_index = generator_.GetUInt32(static_cast<uint32_t>(wgsl_code.size()));
- // Find the first operator occurrence from the chosen point, wrapping back to the start of the
- // file if needed.
- auto maybe_operator_occurrence = FindOperatorOccurrence(wgsl_code, start_index);
- if (!maybe_operator_occurrence.has_value()) {
- // It is unlikely that there will be *no* operators in the file, but if this is the case
- // then this mutation cannot be applied.
- return false;
- }
- std::string existing_operator =
- wgsl_code.substr(maybe_operator_occurrence->first, maybe_operator_occurrence->second);
- // Replace the identified operator with a randomly-chosen alternative.
- wgsl_code.replace(maybe_operator_occurrence->first, maybe_operator_occurrence->second,
- ChooseRandomReplacementForOperator(existing_operator));
- return true;
-}
-
-std::optional<std::pair<uint32_t, uint32_t>> WgslMutator::FindOperatorOccurrence(
- const std::string& wgsl_code,
- uint32_t start_index) {
- // Loops through the characters of the code in a wrap-around fashion, looking for the first
- // encountered token that is a WGSL operator.
-
- for (size_t i = 0; i < wgsl_code.size(); i++) {
- uint32_t current_index = static_cast<uint32_t>((start_index + i) % wgsl_code.size());
-
- // To cater for multi-character operator tokens, get the three consecutive characters from
- // the code string starting at the current index. Use null characters to account for the
- // case where search has reached the end of the code string.
- char first_character = wgsl_code[current_index];
- char second_character =
- current_index + 1 == wgsl_code.size() ? '\0' : wgsl_code[current_index + 1];
- char third_character =
- current_index + 2 >= wgsl_code.size() ? '\0' : wgsl_code[current_index + 2];
-
- // This uses the extracted characters to match for the various WGSL operators.
- switch (first_character) {
- case '!':
- case '^':
- case '*':
- case '/':
- case '%':
- case '=':
- // The above cases are all stand-alone operators, and if followed by '=' are also
- // operators.
- switch (second_character) {
- case '=':
- return {{current_index, 2}};
- default:
- return {{current_index, 1}};
- }
- case '|':
- case '&':
- case '+':
- case '-':
- // The above cases are all stand-alone operators, and if repeated or followed by '='
- // are also operators.
- if (second_character == first_character || second_character == '=') {
- return {{current_index, 2}};
- }
- return {{current_index, 1}};
- case '<':
- case '>':
- // The following caters for '<', '<=', '<<', '<<=', '>', '>=', '>>' and '>>='.
- if (second_character == '=') {
- return {{current_index, 2}};
- }
- if (second_character == first_character) {
- if (third_character == '=') {
- return {{current_index, 3}};
- }
- return {{current_index, 2}};
- }
- return {{current_index, 1}};
- case '~':
- return {{current_index, 1}};
- default:
- break;
- }
- }
- // No operator was found, so empty is returned.
- return {};
-}
-
-bool WgslMutator::ReplaceFunctionCallWithBuiltin(std::string& wgsl_code) {
- std::vector<std::pair<size_t, bool>> function_body_positions =
- GetFunctionBodyPositions(wgsl_code);
-
- // No function was found in wgsl_code.
- if (function_body_positions.empty()) {
- return false;
- }
-
- // Pick a random function
- auto function = generator_.GetRandomElement(function_body_positions);
-
- // Find the corresponding closing bracket for the function.
- size_t left_bracket_pos = function.first;
-
- size_t right_bracket_pos = FindClosingBracket(left_bracket_pos, wgsl_code, '{', '}');
-
- if (right_bracket_pos == 0) {
- return false;
- }
-
- std::string function_body(
- wgsl_code.substr(left_bracket_pos, right_bracket_pos - left_bracket_pos));
-
- std::vector<std::pair<size_t, size_t>> function_call_identifiers =
- GetFunctionCallIdentifiers(function_body);
- if (function_call_identifiers.empty()) {
- return false;
- }
- auto function_call_identifier = generator_.GetRandomElement(function_call_identifiers);
-
- std::vector<std::string> builtin_functions{"all",
- "any",
- "select",
- "arrayLength",
- "abs",
- "acos",
- "acosh",
- "asin",
- "asinh",
- "atan",
- "atanh",
- "atan2",
- "ceil",
- "clamp",
- "cos",
- "cosh",
- "cross",
- "degrees",
- "distance",
- "exp",
- "exp2",
- "faceForward",
- "floor",
- "fma",
- "fract",
- "frexp",
- "inverseSqrt",
- "ldexp",
- "length",
- "log",
- "log2",
- "max",
- "min",
- "mix",
- "modf",
- "normalize",
- "pow",
- "quantizeToF16",
- "radians",
- "reflect",
- "refract",
- "round",
- "saturate",
- "sign",
- "sin",
- "sinh",
- "smoothstep",
- "sqrt",
- "step",
- "tan",
- "tanh",
- "trunc",
- "abs",
- "clamp",
- "countLeadingZeros",
- "countOneBits",
- "countTrailingZeros",
- "extractBits",
- "firstLeadingBit",
- "firstTrailingBit",
- "insertBits",
- "max",
- "min",
- "reverseBits",
- "determinant",
- "transpose",
- "dot",
- "dpdx",
- "dpdxCoarse",
- "dpdxFine",
- "dpdy",
- "dpdyCoarse",
- "dpdyFine",
- "fwidth",
- "fwidthCoarse",
- "fwidthFine",
- "textureDimensions",
- "textureGather",
- "textureGatherCompare",
- "textureLoad",
- "textureNumLayers",
- "textureNumLevels",
- "textureNumSamples",
- "textureSample",
- "textureSampleBias",
- "textureSampleCompare",
- "textureSampleCompareLevel",
- "textureSampleGrad",
- "textureSampleLevel",
- "textureStore",
- "atomicLoad",
- "atomicStore",
- "atomicAdd",
- "atomicSub",
- "atomicMax",
- "atomicMin",
- "atomicAnd",
- "atomicOr",
- "atomicXor",
- "pack4x8snorm",
- "pack4x8unorm",
- "pack2x16snorm",
- "pack2x16unorm",
- "pack2x16float",
- "unpack4x8snorm",
- "unpack4x8unorm",
- "unpack2x16snorm",
- "unpack2x16unorm",
- "unpack2x16float",
- "storageBarrier",
- "workgroupUniformLoad",
- "workgroupBarrier"};
- wgsl_code.replace(left_bracket_pos + function_call_identifier.first,
- function_call_identifier.second,
- generator_.GetRandomElement(builtin_functions));
- return true;
-}
-
-bool WgslMutator::AddSwizzle(std::string& wgsl_code) {
- std::vector<std::pair<size_t, bool>> function_body_positions =
- GetFunctionBodyPositions(wgsl_code);
-
- // No function was found in wgsl_code.
- if (function_body_positions.empty()) {
- return false;
- }
-
- // Pick a random function
- auto function = generator_.GetRandomElement(function_body_positions);
-
- // Find the corresponding closing bracket for the function.
- size_t left_bracket_pos = function.first;
- size_t right_bracket_pos = FindClosingBracket(left_bracket_pos, wgsl_code, '{', '}');
-
- if (right_bracket_pos == 0) {
- return false;
- }
-
- std::string function_body(
- wgsl_code.substr(left_bracket_pos, right_bracket_pos - left_bracket_pos));
-
- // It makes sense to try applying swizzles to:
- // - identifiers, because they might be vectors
- auto identifiers = GetIdentifiers(function_body);
- // - existing swizzles, e.g. to turn v.xy into v.xy.xx
- auto swizzles = GetSwizzles(function_body);
- // - vector initializers, e.g. to turn vec3<f32>(...) into vec3<f32>(...).yyz
- auto vector_initializers = GetVectorInitializers(function_body);
-
- // Create a combined vector of all the possibilities for swizzling, so that they can be sampled
- // from as a whole.
- std::vector<std::pair<size_t, size_t>> combined;
- combined.insert(combined.end(), identifiers.begin(), identifiers.end());
- combined.insert(combined.end(), swizzles.begin(), swizzles.end());
- combined.insert(combined.end(), vector_initializers.begin(), vector_initializers.end());
-
- if (combined.empty()) {
- // No opportunities for swizzling: give up.
- return false;
- }
-
- // Randomly create a swizzle operation. This is done without checking the potential length of
- // the target vector. For identifiers this isn't possible without proper context. For existing
- // swizzles and vector initializers it would be possible to check the length, but it is anyway
- // good to stress-test swizzle validation code paths.
- std::string swizzle = ".";
- {
- // Choose a swizzle length between 1 and 4, inclusive.
- uint32_t swizzle_length = generator_.GetUInt32(1, 5);
- // Decide whether to use xyzw or rgba as convenience names.
- bool use_xyzw = generator_.GetBool();
- // Randomly choose a convenience name for each component of the swizzle.
- for (uint32_t i = 0; i < swizzle_length; i++) {
- switch (generator_.GetUInt32(4)) {
- case 0:
- swizzle += use_xyzw ? "x" : "r";
- break;
- case 1:
- swizzle += use_xyzw ? "y" : "g";
- break;
- case 2:
- swizzle += use_xyzw ? "z" : "b";
- break;
- case 3:
- swizzle += use_xyzw ? "w" : "a";
- break;
- default:
- assert(false && "Unreachable");
- break;
- }
- }
- }
- // Choose a random opportunity for swizzling and add the swizzle right after it.
- auto target = generator_.GetRandomElement(combined);
- wgsl_code.insert(left_bracket_pos + target.first + target.second, swizzle);
- return true;
-}
-
-std::vector<std::pair<size_t, size_t>> WgslMutator::GetSwizzles(const std::string& wgsl_code) {
- std::regex swizzle_regex("\\.(([xyzw]+)|([rgba]+))");
- std::vector<std::pair<size_t, size_t>> result;
-
- auto swizzles_begin = std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), swizzle_regex);
- auto swizles_end = std::sregex_iterator();
-
- for (std::sregex_iterator i = swizzles_begin; i != swizles_end; ++i) {
- result.push_back(
- {static_cast<size_t>(i->prefix().second - wgsl_code.cbegin()), i->str().size()});
- }
- return result;
-}
-
-std::vector<std::pair<size_t, size_t>> WgslMutator::GetVectorInitializers(
- const std::string& wgsl_code) {
- // This regex recognises the prefixes of vector initializers, which have the form:
- // "vecn<type>(", with possible whitespace between tokens.
- std::regex vector_initializer_prefix_regex("vec\\d[ \\n]*<[ \\n]*[a-z0-9_]+[ \\n]*>[^\\(]*\\(");
- std::vector<std::pair<size_t, size_t>> result;
-
- auto vector_initializer_prefixes_begin =
- std::sregex_iterator(wgsl_code.begin(), wgsl_code.end(), vector_initializer_prefix_regex);
- auto vector_initializer_prefixes_end = std::sregex_iterator();
-
- // Look through all of the vector initializer prefixes and see whether each one appears to
- // correspond to a complete vector construction.
- for (std::sregex_iterator i = vector_initializer_prefixes_begin;
- i != vector_initializer_prefixes_end; ++i) {
- // A prefix is deemed to correspond to a complete vector construction if it is possible to
- // find a corresponding closing bracket for the "(" at the end of the prefix.
- size_t closing_bracket = FindClosingBracket(
- static_cast<size_t>(i->suffix().first - wgsl_code.cbegin()), wgsl_code, '(', ')');
- if (closing_bracket != 0) {
- // A closing bracket was found, so record the start and size of the entire vector
- // initializer.
- size_t start = static_cast<size_t>(i->prefix().second - wgsl_code.cbegin());
- result.push_back({start, closing_bracket - start + 1});
- }
- }
- return result;
-}
-
-} // namespace tint::fuzzers::regex_fuzzer
diff --git a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h b/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h
deleted file mode 100644
index 6dfef68..0000000
--- a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.h
+++ /dev/null
@@ -1,273 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_WGSL_MUTATOR_H_
-#define SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_WGSL_MUTATOR_H_
-
-#include <optional>
-#include <string>
-#include <unordered_set>
-#include <utility>
-#include <vector>
-
-#include "src/tint/fuzzers/random_generator.h"
-
-namespace tint::fuzzers::regex_fuzzer {
-
-/// Class encapsulating code for regex-based mutation of WGSL shaders.
-class WgslMutator {
- public:
- /// Constructor
- /// @param generator - pseudo-random generator to use in mutator
- explicit WgslMutator(RandomGenerator& generator);
-
- /// A function that, given WGSL-like string and a delimiter,
- /// generates another WGSL-like string by picking two random regions
- /// enclosed by the delimiter and swapping them.
- /// @param delimiter - the delimiter that will be used to find enclosed regions.
- /// @param wgsl_code - the initial string (WGSL code) that will be mutated.
- /// @return true if a swap happened or false otherwise.
- bool SwapRandomIntervals(const std::string& delimiter, std::string& wgsl_code);
-
- /// A function that, given a WGSL-like string and a delimiter,
- /// generates another WGSL-like string by deleting a random
- /// region enclosed by the delimiter.
- /// @param delimiter - the delimiter that will be used to find enclosed regions.
- /// @param wgsl_code - the initial string (WGSL code) that will be mutated.
- /// @return true if a deletion happened or false otherwise.
- bool DeleteRandomInterval(const std::string& delimiter, std::string& wgsl_code);
-
- /// A function that, given a WGSL-like string and a delimiter,
- /// generates another WGSL-like string by duplicating a random
- /// region enclosed by the delimiter.
- /// @param delimiter - the delimiter that will be used to find enclosed regions.
- /// @param wgsl_code - the initial string (WGSL code) that will be mutated.
- /// @return true if a duplication happened or false otherwise.
- bool DuplicateRandomInterval(const std::string& delimiter, std::string& wgsl_code);
-
- /// Replaces a randomly-chosen identifier in wgsl_code.
- /// @param wgsl_code - WGSL-like string where the replacement will occur.
- /// @return true if a replacement happened or false otherwise.
- bool ReplaceRandomIdentifier(std::string& wgsl_code);
-
- /// Replaces the value of a randomly-chosen integer with one of
- /// the values in the set {INT_MAX, INT_MIN, 0, -1}.
- /// @param wgsl_code - WGSL-like string where the replacement will occur.
- /// @return true if a replacement happened or false otherwise.
- bool ReplaceRandomIntLiteral(std::string& wgsl_code);
-
- /// Inserts a return statement in a randomly chosen function of a
- /// WGSL-like string. The return value is a randomly-chosen identifier
- /// or literal in the string.
- /// @param wgsl_code - WGSL-like string that will be mutated.
- /// @return true if the mutation was succesful or false otherwise.
- bool InsertReturnStatement(std::string& wgsl_code);
-
- /// Inserts a break or continue statement in a randomly chosen loop of a WGSL-like string.
- /// @param wgsl_code - WGSL-like string that will be mutated.
- /// @return true if the mutation was succesful or false otherwise.
- bool InsertBreakOrContinue(std::string& wgsl_code);
-
- /// A function that, given WGSL-like string, generates a new WGSL-like string by replacing one
- /// randomly-chosen operator in the original string with another operator.
- /// @param wgsl_code - the initial WGSL-like string that will be mutated.
- /// @return true if an operator replacement happened or false otherwise.
- bool ReplaceRandomOperator(std::string& wgsl_code);
-
- /// Given a WGSL-like string, replaces a random identifier that appears to be a function call
- /// with the name of a built-in function. This will often lead to an invalid module, as the
- /// mutation does not aim to check whether the original and replacement function have the same
- /// number or types of arguments.
- /// @param wgsl_code - the initial WGSL-like string that will be mutated.
- /// @return true if a function call replacement happened or false otherwise.
- bool ReplaceFunctionCallWithBuiltin(std::string& wgsl_code);
-
- /// Given a WGSL-like string, adds a swizzle operation to either (a) an identifier, (b) a vector
- /// initializer, or (c) an existing swizzle.
- /// @param wgsl_code - the initial WGSL-like string that will be mutated.
- /// @return true if a swizzle operation is added or false otherwise.
- bool AddSwizzle(std::string& wgsl_code);
-
- protected:
- /// Given index idx1 it delets the region of length interval_len
- /// starting at index idx1;
- /// @param idx1 - starting index of the first region.
- /// @param reg_len - terminating index of the second region.
- /// @param wgsl_code - the string where the swap will occur.
- void DeleteInterval(size_t idx1, size_t reg_len, std::string& wgsl_code);
-
- /// Given 2 indices, idx1, idx2, it inserts the region of length
- /// reg1_len starting at idx1 after idx2.
- /// @param idx1 - starting index of region.
- /// @param reg1_len - length of the region.
- /// @param idx2 - the position where the region will be inserted.
- /// @param wgsl_code - the string where the swap will occur.
- void DuplicateInterval(size_t idx1, size_t reg1_len, size_t idx2, std::string& wgsl_code);
-
- /// Finds a possible closing bracket corresponding to the opening
- /// bracket at position opening_bracket_pos.
- /// @param opening_bracket_pos - the position of the opening bracket.
- /// @param wgsl_code - the WGSL-like string where the closing bracket.
- /// @param opening_bracket_character - the opening bracket character, e.g. (, {, <, or [
- /// @param closing_bracket_character - the closing bracket character, e.g. ), }, >, or ]
- /// @return the position of the closing bracket or 0 if there is no closing
- /// bracket.
- size_t FindClosingBracket(size_t opening_bracket_pos,
- const std::string& wgsl_code,
- char opening_bracket_character,
- char closing_bracket_character);
-
- /// Returns the starting position of the bodies of the functions identified by an appropriate
- /// function, together with a boolean indicating whether the function returns a value or not.
- /// @param wgsl_code - the WGSL-like string where the functions will be
- /// searched.
- /// @return a vector of pairs, where each pair provides the starting position of the function
- /// body, and the value true if and only if the function returns a value.
- std::vector<std::pair<size_t, bool>> GetFunctionBodyPositions(const std::string& wgsl_code);
-
- /// Returns the starting position of the bodies of the loops identified by an appropriate
- /// regular expressions.
- /// @param wgsl_code - the WGSL-like string in which loops will be searched for.
- /// @return a vector with the starting position of the loop bodies in wgsl_code.
- std::vector<size_t> GetLoopBodyPositions(const std::string& wgsl_code);
-
- /// A function that finds all the identifiers in a WGSL-like string.
- /// @param wgsl_code - the WGSL-like string where the identifiers will be found.
- /// @return a vector with the positions and the length of all the
- /// identifiers in wgsl_code.
- std::vector<std::pair<size_t, size_t>> GetIdentifiers(const std::string& wgsl_code);
-
- /// A function that finds the identifiers in a WGSL-like string that appear to be used as
- /// function names in function call expressions.
- /// @param wgsl_code - the WGSL-like string where the identifiers will be found.
- /// @return a vector with the positions and the length of all the
- /// identifiers in wgsl_code.
- std::vector<std::pair<size_t, size_t>> GetFunctionCallIdentifiers(const std::string& wgsl_code);
-
- /// A function that returns returns the starting position
- /// and the length of all the integer literals in a WGSL-like string.
- /// @param wgsl_code - the WGSL-like string where the int literals
- /// will be found.
- /// @return a vector with the starting positions and the length
- /// of all the integer literals.
- std::vector<std::pair<size_t, size_t>> GetIntLiterals(const std::string& wgsl_code);
-
- /// Replaces a region of a WGSL-like string of length id2_len starting
- /// at position idx2 with a region of length id1_len starting at
- /// position idx1.
- /// @param idx1 - starting position of the first region.
- /// @param id1_len - length of the first region.
- /// @param idx2 - starting position of the second region.
- /// @param id2_len - length of the second region.
- /// @param wgsl_code - the string where the replacement will occur.
- void ReplaceRegion(size_t idx1,
- size_t id1_len,
- size_t idx2,
- size_t id2_len,
- std::string& wgsl_code);
-
- /// Given 4 indices, idx1, idx2, idx3 and idx4 it swaps the regions
- /// in the interval (idx1, idx2] with the region in the interval (idx3, idx4]
- /// in wgsl_text.
- /// @param idx1 - starting index of the first region.
- /// @param reg1_len - length of the first region.
- /// @param idx2 - starting index of the second region.
- /// @param reg2_len - length of the second region.
- /// @param wgsl_code - the string where the swap will occur.
- void SwapIntervals(size_t idx1,
- size_t reg1_len,
- size_t idx2,
- size_t reg2_len,
- std::string& wgsl_code);
-
- /// Finds the next occurrence of an operator in a WGSL-like string from a given starting
- /// position, wrapping around to the start of the string if no operator is found before reaching
- /// the end, and returning empty of no operator is found at all. There is no guarantee that the
- /// result will correspond to a WGSL operator token, e.g. the identified characters could be
- /// part of a comment, or e.g. the file might contain >>=, in which case the operator
- /// >= will be identified should it happen that the starting index corresponds to the second >
- /// character of this operator. Given that the regex mutator does not aim to guarantee
- /// well-formed programs, these issues are acceptable.
- /// @param wgsl_code - the WGSL-like string in which operator occurrences will be found.
- /// @param start_index - the index at which search should start
- /// @return empty if no operator is found, otherwise a pair comprising the index at which the
- /// operator starts and the character length of the operator.
- std::optional<std::pair<uint32_t, uint32_t>> FindOperatorOccurrence(
- const std::string& wgsl_code,
- uint32_t start_index);
-
- /// Finds all the swizzle operations in a WGSL-like string.
- /// @param wgsl_code - the WGSL-like string where the swizzles will be found.
- /// @return a vector with the positions and lengths of all the swizzles in wgsl_code.
- std::vector<std::pair<size_t, size_t>> GetSwizzles(const std::string& wgsl_code);
-
- /// Finds all the vector initializers in a WGSL-like string.
- /// @param wgsl_code - the WGSL-like string where the vector initializers will be found.
- /// @return a vector with the positions and lengths of all the vector initializers in wgsl_code.
- std::vector<std::pair<size_t, size_t>> GetVectorInitializers(const std::string& wgsl_code);
-
- private:
- /// A function that given a delimiter, returns a vector that contains
- /// all the positions of the delimiter in the WGSL code.
- /// @param delimiter - the delimiter of the enclosed region.
- /// @param wgsl_code - the initial string (WGSL code) that will be mutated.
- /// @return a vector with the positions of the delimiter in the WGSL code.
- std::vector<size_t> FindDelimiterIndices(const std::string& delimiter,
- const std::string& wgsl_code);
-
- /// Replaces an interval of length `length` starting at start_index
- /// with the `replacement_text`.
- /// @param start_index - starting position of the interval to be replaced.
- /// @param length - length of the interval to be replaced.
- /// @param replacement_text - the interval that will be used as a replacement.
- /// @param wgsl_code - the WGSL-like string where the replacement will occur.
- void ReplaceInterval(size_t start_index,
- size_t length,
- std::string replacement_text,
- std::string& wgsl_code);
-
- /// Given a string representing a WGSL operator, randomly returns a different WGSL operator in
- /// the same category as the original, where the three categories are assignment operators (such
- /// as = and +=), expression operators (such as + and ^) and increment operators (++ and --).
- /// @param existing_operator - the characters comprising some WGSL operator
- /// @return another WGSL operator falling into the same category.
- std::string ChooseRandomReplacementForOperator(const std::string& existing_operator);
-
- /// Yields a fixed set of commonly-used WGSL keywords. The regex fuzzer relies heavily on
- /// recognizing possible identifiers via regular expressions. There is a high chance that
- /// keywords will be recognized as identifiers, which will leads to invalid code. It is valuable
- /// for this to occur to some extent (to stress test validation), but it is useful to be able to
- /// exclude the most common keywords so that invalidity does not occur too often.
- /// @return a set of commonly-used WGSL keywords.
- static std::unordered_set<std::string> GetCommonKeywords();
-
- RandomGenerator& generator_;
-};
-
-} // namespace tint::fuzzers::regex_fuzzer
-
-#endif // SRC_TINT_FUZZERS_TINT_REGEX_FUZZER_WGSL_MUTATOR_H_
diff --git a/src/tint/fuzzers/tint_renamer_fuzzer.cc b/src/tint/fuzzers/tint_renamer_fuzzer.cc
deleted file mode 100644
index 0d2f83c..0000000
--- a/src/tint/fuzzers/tint_renamer_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<ast::transform::Renamer>();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_robustness_fuzzer.cc b/src/tint/fuzzers/tint_robustness_fuzzer.cc
deleted file mode 100644
index 2bad239..0000000
--- a/src/tint/fuzzers/tint_robustness_fuzzer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-#include "src/tint/lang/wgsl/ast/transform/robustness.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<tint::ast::transform::Robustness>();
-
- tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_single_entry_point_fuzzer.cc b/src/tint/fuzzers/tint_single_entry_point_fuzzer.cc
deleted file mode 100644
index 88e2136..0000000
--- a/src/tint/fuzzers/tint_single_entry_point_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<ast::transform::SingleEntryPoint>();
-
- fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_spv_reader_fuzzer.cc b/src/tint/fuzzers/tint_spv_reader_fuzzer.cc
deleted file mode 100644
index 3e58cf9..0000000
--- a/src/tint/fuzzers/tint_spv_reader_fuzzer.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2020 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <vector>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kNone);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_spv_reader_hlsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_spv_reader_hlsl_writer_fuzzer.cc
deleted file mode 100644
index 43a1cec..0000000
--- a/src/tint/fuzzers/tint_spv_reader_hlsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <vector>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kHLSL);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_spv_reader_msl_writer_fuzzer.cc b/src/tint/fuzzers/tint_spv_reader_msl_writer_fuzzer.cc
deleted file mode 100644
index 87170b5..0000000
--- a/src/tint/fuzzers/tint_spv_reader_msl_writer_fuzzer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <vector>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- DataBuilder db(data, size);
- msl::writer::Options options;
- GenerateMslOptions(&db, &options);
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kMSL);
- fuzzer.SetOptionsMsl(options);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_spv_reader_spv_writer_fuzzer.cc b/src/tint/fuzzers/tint_spv_reader_spv_writer_fuzzer.cc
deleted file mode 100644
index 5824814..0000000
--- a/src/tint/fuzzers/tint_spv_reader_spv_writer_fuzzer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <vector>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- DataBuilder db(data, size);
- spirv::writer::Options options;
- GenerateSpirvOptions(&db, &options);
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kSpv);
- fuzzer.SetOptionsSpirv(options);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_spv_reader_wgsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_spv_reader_wgsl_writer_fuzzer.cc
deleted file mode 100644
index c619a19..0000000
--- a/src/tint/fuzzers/tint_spv_reader_wgsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <vector>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kWGSL);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_vertex_pulling_fuzzer.cc b/src/tint/fuzzers/tint_vertex_pulling_fuzzer.cc
deleted file mode 100644
index 37a47e7..0000000
--- a/src/tint/fuzzers/tint_vertex_pulling_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-#include "src/tint/fuzzers/transform_builder.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- TransformBuilder tb(data, size);
- tb.AddTransform<ast::transform::VertexPulling>();
-
- tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
- fuzzer.SetTransformManager(tb.manager(), tb.data_map());
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_wgsl_reader_fuzzer.cc b/src/tint/fuzzers/tint_wgsl_reader_fuzzer.cc
deleted file mode 100644
index 24bed2e..0000000
--- a/src/tint/fuzzers/tint_wgsl_reader_fuzzer.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2020 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_common_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kNone);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_wgsl_reader_hlsl_writer_fuzzer.cc b/src/tint/fuzzers/tint_wgsl_reader_hlsl_writer_fuzzer.cc
deleted file mode 100644
index 122aa8a..0000000
--- a/src/tint/fuzzers/tint_wgsl_reader_hlsl_writer_fuzzer.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_wgsl_reader_msl_writer_fuzzer.cc b/src/tint/fuzzers/tint_wgsl_reader_msl_writer_fuzzer.cc
deleted file mode 100644
index 55570fe..0000000
--- a/src/tint/fuzzers/tint_wgsl_reader_msl_writer_fuzzer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- DataBuilder db(data, size);
- msl::writer::Options options;
- GenerateMslOptions(&db, &options);
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
- fuzzer.SetOptionsMsl(options);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/tint_wgsl_reader_spv_writer_fuzzer.cc b/src/tint/fuzzers/tint_wgsl_reader_spv_writer_fuzzer.cc
deleted file mode 100644
index e77bbb1..0000000
--- a/src/tint/fuzzers/tint_wgsl_reader_spv_writer_fuzzer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <string>
-
-#include "src/tint/fuzzers/fuzzer_init.h"
-#include "src/tint/fuzzers/tint_reader_writer_fuzzer.h"
-
-namespace tint::fuzzers {
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- DataBuilder db(data, size);
- spirv::writer::Options options;
- GenerateSpirvOptions(&db, &options);
- tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
- fuzzer.SetOptionsSpirv(options);
- fuzzer.SetDumpInput(GetCliParams().dump_input);
- fuzzer.SetEnforceValidity(GetCliParams().enforce_validity);
-
- return fuzzer.Run(data, size);
-}
-
-} // namespace tint::fuzzers
diff --git a/src/tint/fuzzers/transform_builder.h b/src/tint/fuzzers/transform_builder.h
deleted file mode 100644
index 41dd8a8..0000000
--- a/src/tint/fuzzers/transform_builder.h
+++ /dev/null
@@ -1,233 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_FUZZERS_TRANSFORM_BUILDER_H_
-#define SRC_TINT_FUZZERS_TRANSFORM_BUILDER_H_
-
-#include <string>
-#include <vector>
-
-#include "include/tint/tint.h"
-
-#include "src/tint/fuzzers/data_builder.h"
-#include "src/tint/fuzzers/shuffle_transform.h"
-#include "src/tint/lang/wgsl/ast/transform/binding_remapper.h"
-#include "src/tint/lang/wgsl/ast/transform/robustness.h"
-
-namespace tint::fuzzers {
-
-/// Fuzzer utility class to build inputs for transforms and setup the transform
-/// manager.
-class TransformBuilder {
- public:
- /// @brief Initializes the internal builder using a seed value
- /// @param seed - seed value passed to engine
- explicit TransformBuilder(uint64_t seed) : builder_(seed) {}
-
- /// @brief Initializes the internal builder using seed data
- /// @param data - data fuzzer to calculate seed from
- /// @param size - size of data buffer
- explicit TransformBuilder(const uint8_t* data, size_t size) : builder_(data, size) {
- assert(data != nullptr && "|data| must be !nullptr");
- }
-
- ~TransformBuilder() = default;
-
- /// @returns manager for transforms
- ast::transform::Manager* manager() { return &manager_; }
-
- /// @returns data for transforms
- ast::transform::DataMap* data_map() { return &data_map_; }
-
- /// Adds a transform and needed data to |manager_| and |data_map_|.
- /// @tparam T - A class that inherits from ast::transform::Transform and has an
- /// explicit specialization in AddTransformImpl.
- template <typename T>
- void AddTransform() {
- static_assert(std::is_base_of<ast::transform::Transform, T>::value,
- "T is not a ast::transform::Transform");
- AddTransformImpl<T>::impl(this);
- }
-
- /// Helper that invokes Add*Transform for all of the platform independent
- /// passes.
- void AddPlatformIndependentPasses() {
- AddTransform<ast::transform::FirstIndexOffset>();
- AddTransform<ast::transform::BindingRemapper>();
- AddTransform<ast::transform::Renamer>();
- AddTransform<ast::transform::SingleEntryPoint>();
- AddTransform<ast::transform::VertexPulling>();
- }
-
- private:
- DataBuilder builder_;
- ast::transform::Manager manager_;
- ast::transform::DataMap data_map_;
-
- DataBuilder* builder() { return &builder_; }
-
- /// Implementation of AddTransform, specialized for each transform that is
- /// implemented. Default implementation intentionally deleted to cause compile
- /// error if unimplemented type passed in.
- /// @tparam T - A fuzzer transform
- template <typename T>
- struct AddTransformImpl;
-};
-
-/// Implementation of AddTransform for ShuffleTransform
-template <>
-struct TransformBuilder::AddTransformImpl<ShuffleTransform> {
- /// Add instance of ShuffleTransform to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) {
- tb->manager()->Add<ShuffleTransform>(tb->builder_.build<size_t>());
- }
-};
-
-/// Implementation of AddTransform for ast::transform::Robustness
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::Robustness> {
- /// Add instance of ast::transform::Robustness to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) { tb->manager()->Add<ast::transform::Robustness>(); }
-};
-
-/// Implementation of AddTransform for ast::transform::FirstIndexOffset
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::FirstIndexOffset> {
- /// Add instance of ast::transform::FirstIndexOffset to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) {
- struct Config {
- uint32_t group;
- uint32_t binding;
- };
-
- Config config = tb->builder()->build<Config>();
-
- tb->data_map()->Add<tint::ast::transform::FirstIndexOffset::BindingPoint>(config.binding,
- config.group);
- tb->manager()->Add<ast::transform::FirstIndexOffset>();
- }
-};
-
-/// Implementation of AddTransform for ast::transform::BindingRemapper
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::BindingRemapper> {
- /// Add instance of ast::transform::BindingRemapper to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) {
- struct Config {
- uint8_t old_group;
- uint8_t old_binding;
- uint8_t new_group;
- uint8_t new_binding;
- core::Access new_access;
- };
-
- std::vector<Config> configs = tb->builder()->vector<Config>();
- ast::transform::BindingRemapper::BindingPoints binding_points;
- ast::transform::BindingRemapper::AccessControls accesses;
- for (const auto& config : configs) {
- binding_points[{config.old_binding, config.old_group}] = {config.new_binding,
- config.new_group};
- accesses[{config.old_binding, config.old_group}] = config.new_access;
- }
-
- tb->data_map()->Add<ast::transform::BindingRemapper::Remappings>(
- binding_points, accesses, tb->builder()->build<bool>());
- tb->manager()->Add<ast::transform::BindingRemapper>();
- }
-};
-
-/// Implementation of AddTransform for ast::transform::Renamer
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::Renamer> {
- /// Add instance of ast::transform::Renamer to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) { tb->manager()->Add<ast::transform::Renamer>(); }
-};
-
-/// Implementation of AddTransform for ast::transform::SingleEntryPoint
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::SingleEntryPoint> {
- /// Add instance of ast::transform::SingleEntryPoint to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) {
- auto input = tb->builder()->build<std::string>();
- ast::transform::SingleEntryPoint::Config cfg(input);
-
- tb->data_map()->Add<ast::transform::SingleEntryPoint::Config>(cfg);
- tb->manager()->Add<ast::transform::SingleEntryPoint>();
- }
-};
-
-/// Implementation of AddTransform for ast::transform::VertexPulling
-template <>
-struct TransformBuilder::AddTransformImpl<ast::transform::VertexPulling> {
- /// Add instance of ast::transform::VertexPulling to TransformBuilder
- /// @param tb - TransformBuilder to add transform to
- static void impl(TransformBuilder* tb) {
- ast::transform::VertexPulling::Config cfg;
- cfg.vertex_state = tb->builder()->vector<ast::transform::VertexBufferLayoutDescriptor>(
- GenerateVertexBufferLayoutDescriptor);
- cfg.pulling_group = tb->builder()->build<uint32_t>();
-
- tb->data_map()->Add<ast::transform::VertexPulling::Config>(cfg);
- tb->manager()->Add<ast::transform::VertexPulling>();
- }
-
- private:
- /// Generate an instance of ast::transform::VertexAttributeDescriptor
- /// @param b - DataBuilder to use
- static ast::transform::VertexAttributeDescriptor GenerateVertexAttributeDescriptor(
- DataBuilder* b) {
- ast::transform::VertexAttributeDescriptor desc{};
- desc.format = b->enum_class<ast::transform::VertexFormat>(
- static_cast<uint8_t>(ast::transform::VertexFormat::kUnorm10_10_10_2) + 1);
- desc.offset = b->build<uint32_t>();
- desc.shader_location = b->build<uint32_t>();
- return desc;
- }
-
- /// Generate an instance of VertexBufferLayoutDescriptor
- /// @param b - DataBuilder to use
- static ast::transform::VertexBufferLayoutDescriptor GenerateVertexBufferLayoutDescriptor(
- DataBuilder* b) {
- ast::transform::VertexBufferLayoutDescriptor desc;
- desc.array_stride = b->build<uint32_t>();
- desc.step_mode = b->enum_class<ast::transform::VertexStepMode>(
- static_cast<uint8_t>(ast::transform::VertexStepMode::kInstance) + 1);
- desc.attributes =
- b->vector<ast::transform::VertexAttributeDescriptor>(GenerateVertexAttributeDescriptor);
- return desc;
- }
-};
-
-} // namespace tint::fuzzers
-
-#endif // SRC_TINT_FUZZERS_TRANSFORM_BUILDER_H_