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>
This commit is contained in:
Ben Clayton 2021-06-18 21:15:25 +00:00
parent c3dc300fcb
commit 9efc4fcc89
1 changed files with 7 additions and 0 deletions

View File

@ -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";