[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 16:43:45 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbe758cd4a34a: [WebAssembly][MC] Fix missing `else` after `return` due to type checker bug (authored by sbc100).

Changed prior to commit:
  https://reviews.llvm.org/D135195?vs=465150&id=465221#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135195/new/

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 suppress 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.465221.patch
Type: text/x-patch
Size: 1594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/3e8faff6/attachment.bin>


More information about the llvm-commits mailing list