diff options
-rw-r--r-- | src/wat-writer.cc | 9 | ||||
-rw-r--r-- | test/roundtrip/invalid-br-var.txt | 11 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/wat-writer.cc b/src/wat-writer.cc index f3c46afe..9eadcce7 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -356,9 +356,12 @@ void WatWriter::WriteVar(const Var* var, NextChar next_char) { void WatWriter::WriteBrVar(const Var* var, NextChar next_char) { if (var->type == VarType::Index) { - assert(var->index < GetLabelStackSize()); - Writef("%" PRIindex " (;@%" PRIindex ";)", var->index, - GetLabelStackSize() - var->index - 1); + if (var->index < GetLabelStackSize()) { + Writef("%" PRIindex " (;@%" PRIindex ";)", var->index, + GetLabelStackSize() - var->index - 1); + } else { + Writef("%" PRIindex " (; INVALID ;)", var->index); + } next_char_ = next_char; } else { WriteStringSlice(&var->name, next_char); diff --git a/test/roundtrip/invalid-br-var.txt b/test/roundtrip/invalid-br-var.txt new file mode 100644 index 00000000..8489d5d9 --- /dev/null +++ b/test/roundtrip/invalid-br-var.txt @@ -0,0 +1,11 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --no-check +(module + (func + br 1)) +(;; STDOUT ;;; +(module + (type (;0;) (func)) + (func (;0;) (type 0) + br 1 (; INVALID ;))) +;;; STDOUT ;;) |