[tint][fuzz][ast] Add Renamer fuzzer

Bug: tint:2223
Change-Id: I74d5266dc7a6334fda00694a64743f0f358177d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/186048
Commit-Queue: Ben Clayton <bclayton@google.com>
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 e12f32b..62c3a3e 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.cmake
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.cmake
@@ -269,6 +269,7 @@
   lang/wgsl/ast/transform/remove_continue_in_switch_fuzz.cc
   lang/wgsl/ast/transform/remove_phonies_fuzz.cc
   lang/wgsl/ast/transform/remove_unreachable_statements_fuzz.cc
+  lang/wgsl/ast/transform/renamer_fuzz.cc
   lang/wgsl/ast/transform/single_entry_point_fuzz.cc
   lang/wgsl/ast/transform/std140_fuzz.cc
   lang/wgsl/ast/transform/unshadow_fuzz.cc
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.gn b/src/tint/lang/wgsl/ast/transform/BUILD.gn
index 2a5d618..3db4a21 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.gn
@@ -259,6 +259,7 @@
       "remove_continue_in_switch_fuzz.cc",
       "remove_phonies_fuzz.cc",
       "remove_unreachable_statements_fuzz.cc",
+      "renamer_fuzz.cc",
       "single_entry_point_fuzz.cc",
       "std140_fuzz.cc",
       "unshadow_fuzz.cc",
diff --git a/src/tint/lang/wgsl/ast/transform/renamer.cc b/src/tint/lang/wgsl/ast/transform/renamer.cc
index 423df11..25485b2 100644
--- a/src/tint/lang/wgsl/ast/transform/renamer.cc
+++ b/src/tint/lang/wgsl/ast/transform/renamer.cc
@@ -1264,6 +1264,7 @@
 Renamer::Data::Data(const Data&) = default;
 Renamer::Data::~Data() = default;
 
+Renamer::Config::Config() = default;
 Renamer::Config::Config(Target t, bool pu) : target(t), preserve_unicode(pu) {}
 Renamer::Config::Config(Target t, bool pu, Remappings&& remappings)
     : target(t), preserve_unicode(pu), requested_names(std::move(remappings)) {}
diff --git a/src/tint/lang/wgsl/ast/transform/renamer.h b/src/tint/lang/wgsl/ast/transform/renamer.h
index 3a390c3..ac5e2d4 100644
--- a/src/tint/lang/wgsl/ast/transform/renamer.h
+++ b/src/tint/lang/wgsl/ast/transform/renamer.h
@@ -32,6 +32,7 @@
 #include <unordered_map>
 
 #include "src/tint/lang/wgsl/ast/transform/transform.h"
+#include "src/tint/utils/reflection/reflection.h"
 
 namespace tint::ast::transform {
 
@@ -74,6 +75,9 @@
     /// If omitted, then the renamer will use Target::kAll.
     struct Config final : public Castable<Config, transform::Data> {
         /// Constructor
+        Config();
+
+        /// Constructor
         /// @param tgt the targets to rename
         /// @param keep_unicode if false, symbols with non-ascii code-points are
         /// renamed
@@ -92,13 +96,16 @@
         ~Config() override;
 
         /// The targets to rename
-        Target const target = Target::kAll;
+        Target target = Target::kAll;
 
         /// If false, symbols with non-ascii code-points are renamed.
         bool preserve_unicode = false;
 
         /// Requested renaming rules
-        const Remappings requested_names = {};
+        Remappings requested_names = {};
+
+        /// Reflection for this class
+        TINT_REFLECT(Config, target, preserve_unicode, requested_names);
     };
 
     /// Constructor using a the configuration provided in the input Data
@@ -115,4 +122,11 @@
 
 }  // namespace tint::ast::transform
 
+namespace tint {
+
+/// Reflection for Target
+TINT_REFLECT_ENUM_RANGE(tint::ast::transform::Renamer::Target, kAll, kMslKeywords);
+
+}  // namespace tint
+
 #endif  // SRC_TINT_LANG_WGSL_AST_TRANSFORM_RENAMER_H_
diff --git a/src/tint/lang/wgsl/ast/transform/renamer_fuzz.cc b/src/tint/lang/wgsl/ast/transform/renamer_fuzz.cc
new file mode 100644
index 0000000..9986efd
--- /dev/null
+++ b/src/tint/lang/wgsl/ast/transform/renamer_fuzz.cc
@@ -0,0 +1,48 @@
+// 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/module.h"
+#include "src/tint/lang/wgsl/ast/transform/renamer.h"
+
+namespace tint::ast::transform {
+
+void RenamerFuzzer(const Program& program, const Renamer::Config& config) {
+    DataMap inputs;
+    inputs.Add<Renamer::Config>(config);
+
+    DataMap outputs;
+    if (auto result = Renamer{}.Apply(program, DataMap{}, outputs)) {
+        // Note: We're not ensuring that the returned program is valid, as the renaming is likely to
+        // cause resolver failures. Just ensure that the transform doesn't crash or upset
+        // sanitizers.
+    }
+}
+
+}  // namespace tint::ast::transform
+
+TINT_WGSL_PROGRAM_FUZZER(tint::ast::transform::RenamerFuzzer);