summaryrefslogtreecommitdiff
path: root/src/passes/MemoryPacking.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-10-20 10:46:58 -0700
committerGitHub <noreply@github.com>2020-10-20 10:46:58 -0700
commitc0c3812dfde2b8086b2fdd603e0d70705ec8a1e4 (patch)
tree6d8c1c943daffdb4155f7f22527f65e172a6ac67 /src/passes/MemoryPacking.cpp
parent3732f36ce062c3ee60413e4c19667f256b9297f8 (diff)
downloadbinaryen-c0c3812dfde2b8086b2fdd603e0d70705ec8a1e4.tar.gz
binaryen-c0c3812dfde2b8086b2fdd603e0d70705ec8a1e4.tar.bz2
binaryen-c0c3812dfde2b8086b2fdd603e0d70705ec8a1e4.zip
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
Diffstat (limited to 'src/passes/MemoryPacking.cpp')
-rw-r--r--src/passes/MemoryPacking.cpp7
1 files changed, 3 insertions, 4 deletions
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)),