[PATCH] D115748: [WebAssembly] Fix typechecking for else MCInst
Paulo Matos via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 16 02:24:44 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc92d45913c43: [WebAssembly] Fix typechecking for else MCInst (authored by pmatos).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115748/new/
https://reviews.llvm.org/D115748
Files:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
llvm/test/MC/WebAssembly/typechecking-else.s
Index: llvm/test/MC/WebAssembly/typechecking-else.s
===================================================================
--- /dev/null
+++ llvm/test/MC/WebAssembly/typechecking-else.s
@@ -0,0 +1,21 @@
+# Check that it converts to .o without errors
+# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+reference-types < %s
+
+objects:
+ .tabletype objects,externref
+
+handle_value:
+ .hidden handle_value
+ .globl handle_value
+ .type handle_value, at function
+ .functype handle_value (i32) -> (externref)
+ local.get 0
+ i32.const -1
+ i32.eq
+ if externref
+ ref.null_extern
+ else
+ local.get 0
+ table.get objects
+ end_if
+ end_function
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
@@ -39,7 +39,7 @@
bool typeError(SMLoc ErrorLoc, const Twine &Msg);
bool popType(SMLoc ErrorLoc, Optional<wasm::ValType> EVT);
bool getLocal(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
- bool checkEnd(SMLoc ErrorLoc);
+ bool checkEnd(SMLoc ErrorLoc, bool PopVals = false);
bool checkSig(SMLoc ErrorLoc, const wasm::WasmSignature &Sig);
bool getSymRef(SMLoc ErrorLoc, const MCInst &Inst,
const MCSymbolRefExpr *&SymRef);
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -112,9 +112,18 @@
return false;
}
-bool WebAssemblyAsmTypeCheck::checkEnd(SMLoc ErrorLoc) {
+bool WebAssemblyAsmTypeCheck::checkEnd(SMLoc ErrorLoc, bool PopVals) {
if (LastSig.Returns.size() > Stack.size())
return typeError(ErrorLoc, "end: insufficient values on the type stack");
+
+ if (PopVals) {
+ for (auto VT : llvm::reverse(LastSig.Returns)) {
+ if (popType(ErrorLoc, VT))
+ return true;
+ }
+ return false;
+ }
+
for (size_t i = 0; i < LastSig.Returns.size(); i++) {
auto EVT = LastSig.Returns[i];
auto PVT = Stack[Stack.size() - LastSig.Returns.size() + i];
@@ -221,7 +230,7 @@
return true;
} else if (Name == "end_block" || Name == "end_loop" || Name == "end_if" ||
Name == "else" || Name == "end_try") {
- if (checkEnd(ErrorLoc))
+ if (checkEnd(ErrorLoc, Name == "else"))
return true;
if (Name == "end_block")
Unreachable = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115748.394794.patch
Type: text/x-patch
Size: 2680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/6a5c1b78/attachment.bin>
More information about the llvm-commits
mailing list