@@ -140,20 +140,20 @@ std::vector<std::unique_ptr<Module>> buildStubModules(Module& wasm) {
140140 Module* module = it->second .get ();
141141
142142 struct Visitor {
143- Module* module ;
143+ Module* module = nullptr ;
144+
144145 void operator ()(Memory* memory) {
145146 auto * copied = ModuleUtils::copyMemory (memory, *module );
146147 copied->module = Name ();
147148 copied->base = Name ();
148- module ->addExport (Builder (* module ). makeExport (
149+ module ->maybeAddExport (Builder:: makeExport (
149150 memory->base , copied->name , ExternalKind::Memory));
150151 }
151152 void operator ()(Table* table) {
152- // create tables with similar initial and max values
153153 auto * copied = ModuleUtils::copyTable (table, *module );
154154 copied->module = Name ();
155155 copied->base = Name ();
156- module ->addExport (Builder (* module ). makeExport (
156+ module ->maybeAddExport (Builder:: makeExport (
157157 table->base , copied->name , ExternalKind::Table));
158158 }
159159 void operator ()(Global* global) {
@@ -163,17 +163,14 @@ std::vector<std::unique_ptr<Module>> buildStubModules(Module& wasm) {
163163
164164 Builder builder (*module );
165165 copied->init = builder.makeConst (Literal::makeZero (global->type ));
166- module ->addExport (builder. makeExport (
166+ module ->maybeAddExport ( Builder:: makeExport (
167167 global->base , copied->name , ExternalKind::Global));
168168 }
169169 void operator ()(Function* func) {
170170 Builder builder (*module );
171- auto * copied = ModuleUtils::copyFunction (func, *module );
172- copied->module = Name ();
173- copied->base = Name ();
174- copied->body = builder.makeUnreachable ();
175- module ->addExport (builder.makeExport (
176- func->base , copied->name , ExternalKind::Function));
171+ auto stubbedFunc = builder.makeUnreachableFunction (func->name );
172+ module ->maybeAddExport (Builder::makeExport (
173+ func->base , stubbedFunc->name , ExternalKind::Function));
177174 }
178175 void operator ()(Tag* tag) {
179176 // no-op
0 commit comments