Skip to content

wasm-split error without an element segment #6572

@kripken

Description

@kripken
(module
 (table 0 funcref)
 (export "func_94_invoker" (func $0))
 (func $0
  (nop)
 )
)
$ bin/wasm-split a.wat -all --split -o1 a.wasm -o2 b.wasm -S --split-funcs=0
warning: not keeping any functions in the primary module
wasm-split: src/support/name.cpp:44: std::ostream& wasm::Name::print(std::ostream&) const: Assertion `*this && "Cannot print an empty name"' failed.
Aborted

It seems to have a null Name for the table when it creates a CallIndirect. At a glance at the code I thought this might work:

diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp
index e0fba8ae8..31b85b906 100644
--- a/src/ir/module-splitting.cpp
+++ b/src/ir/module-splitting.cpp
@@ -158,6 +158,10 @@ TableSlotManager::TableSlotManager(Module& module) : module(module) {
   }
 
   activeTable = it->get();
+  if (activeTable == nullptr) {
+    activeTable = makeTable();
+    activeBase = {activeTable->name, "", 0};
+  }
   ModuleUtils::iterTableSegments(
     module, activeTable->name, [&](ElementSegment* segment) {
       activeTableSegments.push_back(segment);
@@ -220,11 +227,6 @@ TableSlotManager::Slot TableSlotManager::getSlot(Name func, HeapType type) {
 
   // If there are no segments yet, allocate one.
   if (activeSegment == nullptr) {
-    if (activeTable == nullptr) {
-      activeTable = makeTable();
-      activeBase = {activeTable->name, "", 0};
-    }
-
     // None of the existing segments should refer to the active table
     assert(std::all_of(module.elementSegments.begin(),
                        module.elementSegments.end(),

That fixes this one but other testcases start to fail so I am not sure if I understand what "active base/table/segment" mean here - some seem to need to be set in the constructor but others not? Anyhow this might be something trivial I am missing, @tlively

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions