From 350bd06a61514860bfd9d0fba7049201d498434d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 9 Mar 2026 15:01:17 -0700 Subject: [PATCH] go --- src/passes/LegalizeJSInterface.cpp | 14 +++++++++++++- .../passes/legalize-and-prune-js-interface.wast | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index 5eb43a36747..5a3d8841e03 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -414,7 +414,19 @@ struct LegalizeAndPruneJSInterface : public LegalizeJSInterface { ReFinalize().run(getPassRunner(), module); ReFinalize().runOnModuleCode(getPassRunner(), module); - // TODO: globals etc. + // Globals. + std::vector illegalExports; + for (auto& exp : module->exports) { + if (exp->kind == ExternalKind::Global) { + auto name = *exp->getInternalName(); + if (isIllegal(module->getGlobal(name)->type)) { + illegalExports.push_back(exp->name); + } + } + } + for (auto name : illegalExports) { + module->removeExport(name); + } } bool isIllegal(Type type) { diff --git a/test/lit/passes/legalize-and-prune-js-interface.wast b/test/lit/passes/legalize-and-prune-js-interface.wast index c1221959194..dbd168edc55 100644 --- a/test/lit/passes/legalize-and-prune-js-interface.wast +++ b/test/lit/passes/legalize-and-prune-js-interface.wast @@ -245,8 +245,23 @@ ;; and also prune the export, so it remains neither an import nor an export. (export "imported-v128" (func $imported-v128)) ) + ;; CHECK: (type $0 (func (result v128))) ;; CHECK: (func $imported-v128 (type $0) (result v128) ;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) ;; CHECK-NEXT: ) +(module + ;; CHECK: (global $i32 i32 (i32.const 42)) + (global $i32 i32 (i32.const 42)) + + ;; CHECK: (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)) + (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)) + + ;; The illegal export will vanish, but not the legal one. + + (export "illegal" (global $v128)) + ;; CHECK: (export "legal" (global $i32)) + (export "legal" (global $i32)) +) +