Index: lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp =================================================================== --- lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp +++ lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp @@ -85,16 +85,14 @@ break; case WebAssembly::END_LOOP: case WebAssembly::END_LOOP_S: - // Have to guard against an empty stack, in case of mismatched pairs - // in assembly parsing. - if (!ControlFlowStack.empty()) - ControlFlowStack.pop_back(); + assert(!ControlFlowStack.empty() && "End marker mismatch!"); + ControlFlowStack.pop_back(); break; case WebAssembly::END_BLOCK: case WebAssembly::END_BLOCK_S: - if (!ControlFlowStack.empty()) - printAnnotation( - OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':'); + assert(!ControlFlowStack.empty() && "End marker mismatch!"); + printAnnotation( + OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':'); break; } Index: test/MC/WebAssembly/block-mismatch.s =================================================================== --- /dev/null +++ test/MC/WebAssembly/block-mismatch.s @@ -0,0 +1,11 @@ +# RUN: not llvm-mc -triple=wasm32-unknown-unknown %s -o - 2>&1 | FileCheck %s + +# This tests if there are block/loop marker mismatches, the program crashes. + .text + .type test0,@function +test0: + block + end_block + # CHECK: End marker mismatch! + end_block + end_function