[llvm] be758cd - [WebAssembly][MC] Fix missing `else` after `return` due to type checker bug

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 16:43:32 PDT 2022


Author: Sam Clegg
Date: 2022-10-04T16:43:22-07:00
New Revision: be758cd4a34a2b648a12bb3ae52adf9e6c5472e4

URL: https://github.com/llvm/llvm-project/commit/be758cd4a34a2b648a12bb3ae52adf9e6c5472e4
DIFF: https://github.com/llvm/llvm-project/commit/be758cd4a34a2b648a12bb3ae52adf9e6c5472e4.diff

LOG: [WebAssembly][MC] Fix missing `else` after `return` due to type checker bug

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

Differential Revision: https://reviews.llvm.org/D135195

Added: 
    llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s

Modified: 
    llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
index 16e877812236f..d63de95457194 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -74,9 +74,9 @@ bool WebAssemblyAsmTypeCheck::typeError(SMLoc ErrorLoc, const Twine &Msg) {
   // 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);

diff  --git a/llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s b/llvm/test/MC/WebAssembly/type-checker-emit-after-unreachable.s
new file mode 100644
index 0000000000000..4c88384616f55
--- /dev/null
+++ b/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


        


More information about the llvm-commits mailing list