[PATCH] D53620: [WebAssembly] Error out when block/loop markers mismatch
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 23 15:39:14 PDT 2018
aheejin created this revision.
aheejin added a reviewer: aardappel.
Herald added subscribers: llvm-commits, sunfish, jgravelle-google, sbc100, dschuff.
Currently InstPrinter ignores if there are mismatches between block/loop
and end markers by skipping the case if ControlFlowStack is empty. I
guess it is better to explicitly error out in this case, because this
signals invalid input.
Repository:
rL LLVM
https://reviews.llvm.org/D53620
Files:
lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
test/CodeGen/WebAssembly/block-mismatch.mir
Index: test/CodeGen/WebAssembly/block-mismatch.mir
===================================================================
--- /dev/null
+++ test/CodeGen/WebAssembly/block-mismatch.mir
@@ -0,0 +1,18 @@
+# RUN: not llc -mtriple=wasm32-unknown-unknown -start-after xray-instrumentation %s -o /dev/null 2>&1 | FileCheck %s
+
+# This tests if there are block/loop marker mismatches, the program crashes.
+
+---
+name: block_mismatch
+liveins:
+ - { reg: '$arguments', reg: '$value_stack' }
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $arguments, $value_stack
+ BLOCK 64, implicit-def $value_stack, implicit $value_stack
+ END_BLOCK implicit-def $value_stack, implicit $value_stack
+ ; CHECK: LLVM ERROR: END marker mismatch!
+ END_BLOCK implicit-def $value_stack, implicit $value_stack
+ RETURN_VOID implicit-def dead $arguments
+...
Index: lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
===================================================================
--- lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
+++ lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
@@ -85,16 +85,16 @@
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();
+ if (ControlFlowStack.empty())
+ report_fatal_error("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) + ':');
+ if (ControlFlowStack.empty())
+ report_fatal_error("END marker mismatch!");
+ printAnnotation(
+ OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':');
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53620.170769.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181023/5efba5a7/attachment.bin>
More information about the llvm-commits
mailing list