From 9efc4fcc897291b9a663d545ca7fcb3b12bea3b9 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 18 Jun 2021 21:15:25 +0000 Subject: [PATCH] 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 Reviewed-by: James Price --- src/ast/module.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ast/module.cc b/src/ast/module.cc index 12c8ebaf6e..4aeb996d58 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -89,6 +89,13 @@ Module* Module::Clone(CloneContext* ctx) const { 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";