From c0c3812dfde2b8086b2fdd603e0d70705ec8a1e4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 20 Oct 2020 10:46:58 -0700 Subject: Avoid name collisions in MemoryPacking (#3265) Such a collision can happen if we run the pass twice, and somehow it finds more to optimize. To make this easy, add a general utility for getting a unique name based on a root + a numeric suffix to avoid collisions. Fixes the second testcase in #3225 --- src/passes/MemoryPacking.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/passes/MemoryPacking.cpp') diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index 6003274e8..d4d75e6d6 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -30,6 +30,7 @@ #include "ir/manipulation.h" #include "ir/module-utils.h" +#include "ir/names.h" #include "ir/utils.h" #include "pass.h" #include "support/space.h" @@ -90,8 +91,6 @@ makeGtShiftedMemorySize(Builder& builder, Module& module, MemoryInit* curr) { } // anonymous namespace struct MemoryPacking : public Pass { - size_t dropStateGlobalCount = 0; - // FIXME: Chrome has a bug decoding section indices that prevents it from // using more than 63. Just use WebLimitations::MaxDataSegments once this is // fixed. See https://bugs.chromium.org/p/v8/issues/detail?id=10151. @@ -559,8 +558,8 @@ void MemoryPacking::createReplacements(Module* module, if (dropStateGlobal != Name()) { return dropStateGlobal; } - dropStateGlobal = Name(std::string("__mem_segment_drop_state_") + - std::to_string(dropStateGlobalCount++)); + dropStateGlobal = + Names::getValidGlobalName(*module, "__mem_segment_drop_state"); module->addGlobal(builder.makeGlobal(dropStateGlobal, Type::i32, builder.makeConst(int32_t(0)), -- cgit v1.2.3