Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IRBuilder on local operations outside of a function context #7183

Merged
merged 2 commits into from
Jan 6, 2025
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
9 changes: 9 additions & 0 deletions src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,17 @@ Result<> IRBuilder::makeCallIndirect(Name table, HeapType type, bool isReturn) {
}

Result<> IRBuilder::makeLocalGet(Index local) {
if (!func) {
return Err{"local.get is only valid in a function context"};
}
push(builder.makeLocalGet(local, func->getLocalType(local)));
return Ok{};
}

Result<> IRBuilder::makeLocalSet(Index local) {
if (!func) {
return Err{"local.set is only valid in a function context"};
}
LocalSet curr;
curr.index = local;
CHECK_ERR(visitLocalSet(&curr));
Expand All @@ -1272,6 +1278,9 @@ Result<> IRBuilder::makeLocalSet(Index local) {
}

Result<> IRBuilder::makeLocalTee(Index local) {
if (!func) {
return Err{"local.tee is only valid in a function context"};
}
LocalSet curr;
curr.index = local;
CHECK_ERR(visitLocalSet(&curr));
Expand Down
10 changes: 10 additions & 0 deletions test/lit/binary/global-local-get.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RUN: not wasm-opt --debug %s.wasm 2>&1 | filecheck %s

;; Check that we get the expected error for an input binary that looks like
;; this:
;;
;; (module
;; (global $g i32 (local.get 0))
;; )

;; CHECK: local.get is only valid in a function context
Binary file added test/lit/binary/global-local-get.test.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions test/lit/binary/global-local-set.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RUN: not wasm-opt --debug %s.wasm 2>&1 | filecheck %s

;; Check that we get the expected error for an input binary that looks like
;; this:
;;
;; (module
;; (global $g i32 (local.set 0 (i32.const 1)))
;; )

;; CHECK: local.set is only valid in a function context
Binary file added test/lit/binary/global-local-set.test.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions test/lit/binary/global-local-tee.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RUN: not wasm-opt --debug %s.wasm 2>&1 | filecheck %s

;; Check that we get the expected error for an input binary that looks like
;; this:
;;
;; (module
;; (global $g i32 (local.tee 0 (i32.const 1)))
;; )

;; CHECK: local.tee is only valid in a function context
Binary file added test/lit/binary/global-local-tee.test.wasm
Binary file not shown.
Loading