[ir] Do not automatically add cloned functions
Leave it up to the caller to decide when to add the function.
Fixes a crash in DirectVariableAccess where we were adding new
functions while iterating over the function list.
Change-Id: I4236803bf481cd6180b7242ffb54cd4436650045
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/153860
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/ir/function.cc b/src/tint/lang/core/ir/function.cc
index 57309c0..4eebbbc 100644
--- a/src/tint/lang/core/ir/function.cc
+++ b/src/tint/lang/core/ir/function.cc
@@ -46,7 +46,6 @@
block_->CloneInto(ctx, new_func->block_);
ctx.ir.SetName(new_func, ctx.ir.NameOf(this).Name());
- ctx.ir.functions.Push(new_func);
return new_func;
}
diff --git a/src/tint/lang/core/ir/function_test.cc b/src/tint/lang/core/ir/function_test.cc
index 6739793..b2b58d3 100644
--- a/src/tint/lang/core/ir/function_test.cc
+++ b/src/tint/lang/core/ir/function_test.cc
@@ -111,7 +111,8 @@
EXPECT_EQ(new_param1, new_f->Params()[0]);
EXPECT_EQ(new_param2, new_f->Params()[1]);
- EXPECT_EQ(new_f, mod.functions.Back());
+ // Cloned functions are not automatically added to the module.
+ EXPECT_EQ(mod.functions.Length(), 1u);
}
TEST_F(IR_FunctionTest, CloneWithExits) {