[PATCH] D53620: [WebAssembly] Error out when block/loop markers mismatch

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 03:55:31 PDT 2018


aheejin updated this revision to Diff 170841.
aheejin added a comment.

- Add llvm-mc test case (and delete the old one)
- Change report_fatal_error to assertions


Repository:
  rL LLVM

https://reviews.llvm.org/D53620

Files:
  lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
  test/MC/WebAssembly/block-mismatch.s


Index: test/MC/WebAssembly/block-mismatch.s
===================================================================
--- /dev/null
+++ test/MC/WebAssembly/block-mismatch.s
@@ -0,0 +1,13 @@
+# 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, at function
+test0:
+  block
+  end_block
+  # CHECK: End marker mismatch!
+  end_block
+  end_function
+.Lfunc_end1:
+  .size  test1, .Lfunc_end1-test1
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;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53620.170841.patch
Type: text/x-patch
Size: 1600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181024/4150dc99/attachment.bin>


More information about the llvm-commits mailing list