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