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
5 changes: 3 additions & 2 deletions src/passes/GlobalRefining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ struct GlobalRefining : public Pass {
ReFinalize().walkFunctionInModule(curr, &wasm);
}
}
};
GetUpdater(*this, *module).run(getPassRunner(), module);
} updater(*this, *module);
updater.run(getPassRunner(), module);
updater.runOnModuleCode(getPassRunner(), module);
}
};

Expand Down
8 changes: 5 additions & 3 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,11 @@ void FunctionValidator::visitGlobalGet(GlobalGet* curr) {
if (!info.validateGlobally) {
return;
}
shouldBeTrue(getModule()->getGlobalOrNull(curr->name),
curr,
"global.get name must be valid");
auto* global = getModule()->getGlobalOrNull(curr->name);
if (shouldBeTrue(global, curr, "global.get name must be valid")) {
shouldBeEqual(
curr->type, global->type, curr, "global.get must have right type");
}
}

void FunctionValidator::visitGlobalSet(GlobalSet* curr) {
Expand Down
2 changes: 1 addition & 1 deletion test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ void test_core() {
makeInt32(module, 0)),
BinaryenStringNew(module,
BinaryenStringNewWTF16Array(),
BinaryenGlobalGet(module, "i16Array-global", i8Array),
BinaryenGlobalGet(module, "i16Array-global", i16Array),
makeInt32(module, 0),
makeInt32(module, 0)),
BinaryenStringNew(
Expand Down
28 changes: 28 additions & 0 deletions test/lit/passes/global-refining.wast
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,31 @@
(nop)
)
)

;; We can refine $a, after which we should update the global.get in the other
;; global, or else we'd error on validation.
;; TODO: we could optimize further here and refine the type of the global $b.
(module
;; CHECK: (type $super (sub (func)))
;; CLOSD: (type $super (sub (func)))
(type $super (sub (func)))
;; CHECK: (type $sub (sub $super (func)))
;; CLOSD: (type $sub (sub $super (func)))
(type $sub (sub $super (func)))

;; CHECK: (global $a (ref $sub) (ref.func $func))
;; CLOSD: (global $a (ref $sub) (ref.func $func))
(global $a (ref $super) (ref.func $func))
;; CHECK: (global $b (ref $super) (global.get $a))
;; CLOSD: (global $b (ref $super) (global.get $a))
(global $b (ref $super) (global.get $a))

;; CHECK: (func $func (type $sub)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CLOSD: (func $func (type $sub)
;; CLOSD-NEXT: (nop)
;; CLOSD-NEXT: )
(func $func (type $sub)
)
)