[PATCH] D135195: [WebAssembly][MC] Fix missing `else` after `return` due to type checker bug
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 14:01:45 PDT 2022
sbc100 created this revision.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, dschuff.
Herald added a project: All.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
Once we are in the `Unreachable` we want to disable type checking, but
we were unconditionally returning `true` here which means we encountered
and error. Instead we unconditionally return false to signal no error.
Fixes: https://github.com/llvm/llvm-project/issues/56935
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135195
Files:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s
Index: llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s
===================================================================
--- /dev/null
+++ llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s
@@ -0,0 +1,27 @@
+# We had a regression where an else instruction would be omitted if it followed
+# return (i.e. it was in an unreachable state).
+# See: https://github.com/llvm/llvm-project/issues/56935
+
+# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
+
+foo:
+ .functype foo () -> (i32)
+ i32.const 1
+ if i32
+ i32.const 2
+ return
+ else
+ i32.const 3
+ end_if
+ end_function
+
+# CHECK-LABEL: foo:
+# CHEKC-NEXT: .functype foo () -> (i32)
+# CHEKC-NEXT: i32.const 1
+# CHEKC-NEXT: if i32
+# CHEKC-NEXT: i32.const 2
+# CHEKC-NEXT: return
+# CHEKC-NEXT: else
+# CHEKC-NEXT: i32.const 3
+# CHEKC-NEXT: end_if
+# CHEKC-NEXT: end_function
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -74,9 +74,9 @@
// which are mostly not helpful.
if (TypeErrorThisFunction)
return true;
- // If we're currently in unreachable code, we surpress errors as well.
+ // If we're currently in unreachable code, we surpress errors completely.
if (Unreachable)
- return true;
+ return false;
TypeErrorThisFunction = true;
dumpTypeStack("current stack: ");
return Parser.Error(ErrorLoc, Msg);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135195.465150.patch
Type: text/x-patch
Size: 1594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/4b191397/attachment.bin>
More information about the llvm-commits
mailing list