Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,7 +3700,7 @@ void WasmBinaryReader::readNames(size_t payloadLen) {
auto rawName = getInlineString();
auto name = processor.process(rawName);
if (index < wasm.dataSegments.size()) {
wasm.dataSegments[i]->setExplicitName(name);
wasm.dataSegments[index]->setExplicitName(name);
} else {
std::cerr << "warning: data index out of bounds in name section, "
"data subsection: "
Expand Down
25 changes: 25 additions & 0 deletions test/lit/binary/data-names.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: wasm-opt -all %s.wasm -q -S -o - | filecheck %s

;; Test that data segment names roundtrip properly. The wasm file contains
;;
;; (module
;; (memory $mem 10)
;; (data $passive1 "passive1")
;; (data $passive2 "passive2")
;; (data $active1 (offset i32.const 0) "active1")
;; (data $active2 (offset i32.const 0) "active2")
;; )
;;
;; But the names section is *reversed*: the name of the last data segment is
;; first, and so forth. We must still give the proper segments their names.

;; CHECK: (memory $mem 10)

;; CHECK: (data $passive1 "passive1")

;; CHECK: (data $passive2 "passive2")

;; CHECK: (data $active1 (i32.const 0) "active1")

;; CHECK: (data $active2 (i32.const 0) "active2")
Binary file added test/lit/binary/data-names.test.wasm
Binary file not shown.