[tint][fuzz][ast] Add DirectVariableAccess fuzzer
Bug: tint:2223
Change-Id: Ice21aeb3f1858ce159041260af4b134e44deb6f8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/185629
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.cmake b/src/tint/lang/wgsl/ast/transform/BUILD.cmake
index 75fb8d4..0efd0de 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.cmake
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.cmake
@@ -256,6 +256,7 @@
lang/wgsl/ast/transform/canonicalize_entry_point_io_fuzz.cc
lang/wgsl/ast/transform/clamp_frag_depth_fuzz.cc
lang/wgsl/ast/transform/demote_to_helper_fuzz.cc
+ lang/wgsl/ast/transform/direct_variable_access_fuzz.cc
lang/wgsl/ast/transform/zero_init_workgroup_memory_fuzz.cc
)
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.gn b/src/tint/lang/wgsl/ast/transform/BUILD.gn
index 11f0c2a..3519a52 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.gn
@@ -246,6 +246,7 @@
"canonicalize_entry_point_io_fuzz.cc",
"clamp_frag_depth_fuzz.cc",
"demote_to_helper_fuzz.cc",
+ "direct_variable_access_fuzz.cc",
"zero_init_workgroup_memory_fuzz.cc",
]
deps = [
diff --git a/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc b/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc
index d92bfb0..44fc79b 100644
--- a/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc
+++ b/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc
@@ -1203,6 +1203,7 @@
}
};
+DirectVariableAccess::Config::Config() = default;
DirectVariableAccess::Config::Config(const Options& opt) : options(opt) {}
DirectVariableAccess::Config::~Config() = default;
diff --git a/src/tint/lang/wgsl/ast/transform/direct_variable_access.h b/src/tint/lang/wgsl/ast/transform/direct_variable_access.h
index d1bb9fe..16af90d 100644
--- a/src/tint/lang/wgsl/ast/transform/direct_variable_access.h
+++ b/src/tint/lang/wgsl/ast/transform/direct_variable_access.h
@@ -29,6 +29,7 @@
#define SRC_TINT_LANG_WGSL_AST_TRANSFORM_DIRECT_VARIABLE_ACCESS_H_
#include "src/tint/lang/wgsl/ast/transform/transform.h"
+#include "src/tint/utils/reflection/reflection.h"
namespace tint::ast::transform {
@@ -57,19 +58,29 @@
bool transform_private = false;
/// If true, then 'function' sub-object pointer arguments will be transformed.
bool transform_function = false;
+
+ /// Reflection for this struct
+ TINT_REFLECT(Options, transform_private, transform_function);
};
/// Config is consumed by the DirectVariableAccess transform.
/// Config specifies the behavior of the transform.
struct Config final : public Castable<Config, Data> {
/// Constructor
+ Config();
+
+ /// Constructor
/// @param options behavior of the transform
explicit Config(const Options& options);
+
/// Destructor
~Config() override;
/// The transform behavior options
- const Options options;
+ Options options;
+
+ /// Reflection for this struct
+ TINT_REFLECT(Config, options);
};
/// @copydoc Transform::Apply
diff --git a/src/tint/lang/wgsl/ast/transform/direct_variable_access_fuzz.cc b/src/tint/lang/wgsl/ast/transform/direct_variable_access_fuzz.cc
new file mode 100644
index 0000000..5123798
--- /dev/null
+++ b/src/tint/lang/wgsl/ast/transform/direct_variable_access_fuzz.cc
@@ -0,0 +1,51 @@
+// Copyright 2024 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/cmd/fuzz/wgsl/fuzz.h"
+#include "src/tint/lang/wgsl/ast/transform/direct_variable_access.h"
+
+namespace tint::ast::transform {
+namespace {
+
+void DirectVariableAccessFuzzer(const Program& program,
+ const DirectVariableAccess::Config& config) {
+ DataMap inputs;
+ inputs.Add<DirectVariableAccess::Config>(std::move(config));
+
+ DataMap outputs;
+ if (auto result = DirectVariableAccess{}.Apply(program, inputs, outputs)) {
+ if (!result->IsValid()) {
+ TINT_ICE() << "DirectVariableAccess returned invalid program:\n"
+ << result->Diagnostics();
+ }
+ }
+}
+
+} // namespace
+} // namespace tint::ast::transform
+
+TINT_WGSL_PROGRAM_FUZZER(tint::ast::transform::DirectVariableAccessFuzzer);