diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp @@ -303,7 +303,7 @@ Name == "else" || Name == "end_try") { if (checkEnd(ErrorLoc, Name == "else")) return true; - if (Name == "end_block") + if (Name.startswith("end_")) Unreachable = false; } else if (Name == "return") { if (endOfFunction(ErrorLoc)) diff --git a/llvm/test/MC/WebAssembly/type-checker-errors.s b/llvm/test/MC/WebAssembly/type-checker-errors.s --- a/llvm/test/MC/WebAssembly/type-checker-errors.s +++ b/llvm/test/MC/WebAssembly/type-checker-errors.s @@ -513,3 +513,44 @@ f32.add # CHECK: :[[@LINE+1]]:3: error: 1 superfluous return values end_function + +check_after_unreachable_within_block: + .functype check_after_unreachable_within_block () -> () + block + unreachable + end_block +# CHECK: :[[@LINE+1]]:3: error: empty stack while popping value + drop + end_function + +check_after_unreachable_within_loop: + .functype check_after_unreachable_within_loop () -> () + loop + unreachable + end_loop +# CHECK: :[[@LINE+1]]:3: error: empty stack while popping value + drop + end_function + +check_after_unreachable_within_if: + .functype check_after_unreachable_within_if () -> () + i32.const 0 + if + unreachable + else + unreachable + end_if +# CHECK: :[[@LINE+1]]:3: error: empty stack while popping value + drop + end_function + +check_after_unreachable_within_try: + .functype check_after_unreachable_within_try () -> () + try + unreachable + catch_all + unreachable + end_try +# CHECK: :[[@LINE+1]]:3: error: empty stack while popping value + drop + end_function diff --git a/llvm/test/MC/WebAssembly/type-checker-return.s b/llvm/test/MC/WebAssembly/type-checker-return.s --- a/llvm/test/MC/WebAssembly/type-checker-return.s +++ b/llvm/test/MC/WebAssembly/type-checker-return.s @@ -27,3 +27,9 @@ i32.const 2 return_call fn_void_to_void end_function + +no_check_after_unreachable: + .functype no_check_after_unreachable () -> () + unreachable + drop + end_function