ast: Fix double type decl bug

If during clone, we register a type, function or global declaration, we could end up with the declaration held twice by the AST Module.

AST nodes must only be referenced once.

Change-Id: I5c517699ea80422800639088b97a50ba9ac27b70
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55245
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/ast/module.cc b/src/ast/module.cc
index 12c8eba..4aeb996 100644
--- a/src/ast/module.cc
+++ b/src/ast/module.cc
@@ -89,6 +89,13 @@
 
 void Module::Copy(CloneContext* ctx, const Module* src) {
   ctx->Clone(global_declarations_, src->global_declarations_);
+
+  // During the clone, declarations may have been placed into the module.
+  // Clear everything out, as we're about to re-bin the declarations.
+  type_decls_.clear();
+  functions_.clear();
+  global_variables_.clear();
+
   for (auto* decl : global_declarations_) {
     if (!decl) {
       TINT_ICE(ctx->dst->Diagnostics()) << "src global declaration was nullptr";