summaryrefslogtreecommitdiff
path: root/test/lit/binary/name-overlap.test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-04-28 09:59:23 -0700
committerGitHub <noreply@github.com>2023-04-28 09:59:23 -0700
commit50902ce3514e6c762ae679621df4673b9d7801e5 (patch)
tree1f37c84d1c309d55fe85a47341b22402cfa32e81 /test/lit/binary/name-overlap.test
parentf7706ad4999a087140924f073e1a2135d4ea9074 (diff)
downloadbinaryen-50902ce3514e6c762ae679621df4673b9d7801e5.tar.gz
binaryen-50902ce3514e6c762ae679621df4673b9d7801e5.tar.bz2
binaryen-50902ce3514e6c762ae679621df4673b9d7801e5.zip
Fix name deduplication with partial names sections (#5689)
We already deduplicated names in the names section (to defend against a weird binary), but we also need to deduplicate the names of items not in the names section, so they don't overlap with the names that are. See example in the testcase. Normally wasm files use names for all items in each group. This only became noticeable in some wasm-ctor-eval work where new temp globals were added that were not given names.
Diffstat (limited to 'test/lit/binary/name-overlap.test')
-rw-r--r--test/lit/binary/name-overlap.test22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lit/binary/name-overlap.test b/test/lit/binary/name-overlap.test
new file mode 100644
index 000000000..7f5318737
--- /dev/null
+++ b/test/lit/binary/name-overlap.test
@@ -0,0 +1,22 @@
+;; 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 that we emit deduplicated names even in the corner case that one item
+;; is in the names section and the other is not, and the latter's temp name
+;; coincides with the name the name section gives for the first. Specifically,
+;; the input wasm looks like this:
+;;
+;; (module
+;; (global $global$1 i32 (i32.const 1)) ;; In names section.
+;; (global $........ i32 (i32.const 0)) ;; *Not* in names section.
+;; )
+;;
+;; We give them temp names $global$0, $global$1 to begin with, then apply the
+;; names section which turns the first's name into $global$1 - identical to the
+;; second. We must then deduplicate the second name to avoid a collision. (Note
+;; 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))
+