summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp11
-rw-r--r--test/duplicated_names.wasmbin64 -> 0 bytes
-rw-r--r--test/duplicated_names.wasm.fromBinary13
-rw-r--r--test/duplicated_names_collision.wasm.fromBinary13
-rw-r--r--test/lit/binary/duplicated_names_collision.test21
-rw-r--r--test/lit/binary/duplicated_names_collision.test.wasm (renamed from test/duplicated_names_collision.wasm)bin66 -> 66 bytes
-rw-r--r--test/lit/binary/duplicated_names_collision_underscore.test21
-rw-r--r--test/lit/binary/duplicated_names_collision_underscore.test.wasmbin0 -> 66 bytes
-rw-r--r--test/lit/binary/name-overlap.test5
9 files changed, 48 insertions, 36 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0a65fbadb..3cb3b08da 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -19,6 +19,7 @@
#include "ir/eh-utils.h"
#include "ir/module-utils.h"
+#include "ir/names.h"
#include "ir/table-utils.h"
#include "ir/type-updating.h"
#include "support/bits.h"
@@ -3551,14 +3552,8 @@ private:
std::unordered_set<Name> usedNames;
Name deduplicate(Name base) {
- // TODO: Consider using Names::getValidNameGivenExisting but that does give
- // longer names, and it is very noticeable in this location, so
- // perhaps optimize that first.
- Name name = base;
- // De-duplicate names by appending .1, .2, etc.
- for (int i = 1; !usedNames.insert(name).second; ++i) {
- name = std::string(base.str) + std::string(".") + std::to_string(i);
- }
+ auto name = Names::getValidNameGivenExisting(base, usedNames);
+ usedNames.insert(name);
return name;
}
};
diff --git a/test/duplicated_names.wasm b/test/duplicated_names.wasm
deleted file mode 100644
index 33dfb229f..000000000
--- a/test/duplicated_names.wasm
+++ /dev/null
Binary files differ
diff --git a/test/duplicated_names.wasm.fromBinary b/test/duplicated_names.wasm.fromBinary
deleted file mode 100644
index 753ef8ada..000000000
--- a/test/duplicated_names.wasm.fromBinary
+++ /dev/null
@@ -1,13 +0,0 @@
-(module
- (type $0 (func (result i32)))
- (func $foo (result i32)
- (i32.const 0)
- )
- (func $foo.1 (result i32)
- (i32.const 1)
- )
- (func $foo.2 (result i32)
- (i32.const 2)
- )
-)
-
diff --git a/test/duplicated_names_collision.wasm.fromBinary b/test/duplicated_names_collision.wasm.fromBinary
deleted file mode 100644
index 87cb42abf..000000000
--- a/test/duplicated_names_collision.wasm.fromBinary
+++ /dev/null
@@ -1,13 +0,0 @@
-(module
- (type $0 (func (result i32)))
- (func $foo (result i32)
- (i32.const 0)
- )
- (func $foo.1 (result i32)
- (i32.const 1)
- )
- (func $foo.1.1 (result i32)
- (i32.const 2)
- )
-)
-
diff --git a/test/lit/binary/duplicated_names_collision.test b/test/lit/binary/duplicated_names_collision.test
new file mode 100644
index 000000000..ce0df6ca5
--- /dev/null
+++ b/test/lit/binary/duplicated_names_collision.test
@@ -0,0 +1,21 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+;; RUN: wasm-opt %s.wasm -S -o - | filecheck %s
+
+;; Test handling of duplicated names where the name in the binary format
+;; overlaps with the suffix we add to deduplicate. The binary here uses a '.'
+;; in one of the names, which will overlap if we use '.2' etc. to differentiate.
+
+
+;; CHECK: (type $0 (func (result i32)))
+
+;; CHECK: (func $foo (result i32)
+;; CHECK-NEXT: (i32.const 0)
+;; CHECK-NEXT: )
+
+;; CHECK: (func $foo_1 (result i32)
+;; CHECK-NEXT: (i32.const 1)
+;; CHECK-NEXT: )
+
+;; CHECK: (func $foo.1 (result i32)
+;; CHECK-NEXT: (i32.const 2)
+;; CHECK-NEXT: )
diff --git a/test/duplicated_names_collision.wasm b/test/lit/binary/duplicated_names_collision.test.wasm
index b742ce07a..b742ce07a 100644
--- a/test/duplicated_names_collision.wasm
+++ b/test/lit/binary/duplicated_names_collision.test.wasm
Binary files differ
diff --git a/test/lit/binary/duplicated_names_collision_underscore.test b/test/lit/binary/duplicated_names_collision_underscore.test
new file mode 100644
index 000000000..f4f4e56ee
--- /dev/null
+++ b/test/lit/binary/duplicated_names_collision_underscore.test
@@ -0,0 +1,21 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+;; RUN: wasm-opt %s.wasm -S -o - | filecheck %s
+
+;; Test handling of duplicated names where the name in the binary format
+;; overlaps with the suffix we add to deduplicate. This is similar to
+;; the non-underscore version of this test, but has an '_' in the name.
+
+
+;; CHECK: (type $0 (func (result i32)))
+
+;; CHECK: (func $foo (result i32)
+;; CHECK-NEXT: (i32.const 0)
+;; CHECK-NEXT: )
+
+;; CHECK: (func $foo_1 (result i32)
+;; CHECK-NEXT: (i32.const 1)
+;; CHECK-NEXT: )
+
+;; CHECK: (func $foo_1_2 (result i32)
+;; CHECK-NEXT: (i32.const 2)
+;; CHECK-NEXT: )
diff --git a/test/lit/binary/duplicated_names_collision_underscore.test.wasm b/test/lit/binary/duplicated_names_collision_underscore.test.wasm
new file mode 100644
index 000000000..facbee0d8
--- /dev/null
+++ b/test/lit/binary/duplicated_names_collision_underscore.test.wasm
Binary files differ
diff --git a/test/lit/binary/name-overlap.test b/test/lit/binary/name-overlap.test
index 7f5318737..f5c47e50a 100644
--- a/test/lit/binary/name-overlap.test
+++ b/test/lit/binary/name-overlap.test
@@ -17,6 +17,7 @@
;; that we leave the name from the names section as it is, and only adjust the
;; temp name.)
-;; CHECK: (global $global$1 i32 (i32.const 1))
-;; CHECK-NEXT: (global $global$1.1 i32 (i32.const 0))
+;; CHECK: (global $global$1 i32 (i32.const 1))
+
+;; CHECK: (global $global$1_1 i32 (i32.const 0))