summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/decompiler-ast.h5
-rw-r--r--src/decompiler-naming.h3
-rw-r--r--src/interp/binary-reader-interp.cc7
-rw-r--r--test/binary/bad-interp-returncallindirect-invalid-sig.txt20
-rw-r--r--test/binary/bad-returncall-invalid-func.txt20
-rw-r--r--test/regress/regress-1922.txt18
-rw-r--r--test/regress/regress-1924.txt16
7 files changed, 89 insertions, 0 deletions
diff --git a/src/decompiler-ast.h b/src/decompiler-ast.h
index 584a8373..e5dd358e 100644
--- a/src/decompiler-ast.h
+++ b/src/decompiler-ast.h
@@ -226,6 +226,11 @@ struct AST {
mc.GetLabel(cast<BrIfExpr>(&e)->var)->label_type;
return;
}
+ case ExprType::BrTable: {
+ InsertNode(NodeType::Expr, ExprType::BrTable, &e, 1).u.lt =
+ mc.GetLabel(cast<BrTableExpr>(&e)->default_target)->label_type;
+ return;
+ }
default: {
InsertNode(NodeType::Expr, e.type(), &e, arity.nargs);
return;
diff --git a/src/decompiler-naming.h b/src/decompiler-naming.h
index 91f841f8..bb7a0819 100644
--- a/src/decompiler-naming.h
+++ b/src/decompiler-naming.h
@@ -85,6 +85,9 @@ inline void RenameToIdentifier(std::string& name,
if (s.size() > max_identifier_length) {
s.resize(max_identifier_length);
}
+ if (s.empty()) {
+ s = "__empty";
+ }
// Remove original binding first, such that it doesn't match with our
// new name.
bh.erase(name);
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index e1696ce2..05296220 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -1139,6 +1139,9 @@ Result BinaryReaderInterp::OnCallIndirectExpr(Index sig_index,
}
Result BinaryReaderInterp::OnReturnCallExpr(Index func_index) {
+ CHECK_RESULT(
+ validator_.OnReturnCall(GetLocation(), Var(func_index, GetLocation())));
+
FuncType& func_type = func_types_[func_index];
Index drop_count, keep_count, catch_drop_count;
@@ -1169,6 +1172,10 @@ Result BinaryReaderInterp::OnReturnCallExpr(Index func_index) {
Result BinaryReaderInterp::OnReturnCallIndirectExpr(Index sig_index,
Index table_index) {
+ CHECK_RESULT(validator_.OnReturnCallIndirect(
+ GetLocation(), Var(sig_index, GetLocation()),
+ Var(table_index, GetLocation())));
+
FuncType& func_type = module_.func_types[sig_index];
Index drop_count, keep_count, catch_drop_count;
diff --git a/test/binary/bad-interp-returncallindirect-invalid-sig.txt b/test/binary/bad-interp-returncallindirect-invalid-sig.txt
new file mode 100644
index 00000000..5df642b3
--- /dev/null
+++ b/test/binary/bad-interp-returncallindirect-invalid-sig.txt
@@ -0,0 +1,20 @@
+;;; TOOL: run-gen-wasm-interp
+;;; ARGS1: --enable-tail-call
+;;; ERROR: 1
+magic
+version
+section(TYPE) { count[1] function params[0] results[0] }
+section(FUNCTION) { count[1] type[0] }
+section(TABLE) { count[1] funcref flags[0] min[0] }
+section(CODE) {
+ count[1]
+ func {
+ locals[0]
+ i32.const 0
+ return_call_indirect leb_i32(100) 0
+ }
+}
+(;; STDERR ;;;
+out/test/binary/bad-interp-returncallindirect-invalid-sig/bad-interp-returncallindirect-invalid-sig.wasm:0000023: error: function type variable out of range: 100 (max 1)
+0000023: error: OnReturnCallIndirectExpr callback failed
+;;; STDERR ;;)
diff --git a/test/binary/bad-returncall-invalid-func.txt b/test/binary/bad-returncall-invalid-func.txt
new file mode 100644
index 00000000..152c734f
--- /dev/null
+++ b/test/binary/bad-returncall-invalid-func.txt
@@ -0,0 +1,20 @@
+;;; TOOL: run-gen-wasm-interp
+;;; ARGS1: --enable-tail-call
+;;; ERROR: 1
+magic
+version
+section(TYPE) { count[1] function params[0] results[0] }
+section(FUNCTION) { count[1] type[0] }
+section(TABLE) { count[1] funcref flags[0] min[0] }
+section(CODE) {
+ count[1]
+ func {
+ locals[0]
+ i32.const 0
+ return_call leb_i32(100) 0
+ }
+}
+(;; STDERR ;;;
+out/test/binary/bad-returncall-invalid-func/bad-returncall-invalid-func.wasm:0000022: error: function variable out of range: 100 (max 1)
+0000022: error: OnReturnCallExpr callback failed
+;;; STDERR ;;)
diff --git a/test/regress/regress-1922.txt b/test/regress/regress-1922.txt
new file mode 100644
index 00000000..c6262a96
--- /dev/null
+++ b/test/regress/regress-1922.txt
@@ -0,0 +1,18 @@
+;;; TOOL: run-wasm-decompile
+(module
+ (type (;0;) (func (param i32 i32) (result i32)))
+ (func (;0;) (type 0) (param i32 i32) (result i32)
+ local.get 0
+ loop (param i32) (result i32) ;; label = @1
+ unreachable
+ br_table 0 (;@1;) 0 (;@1;)
+ i32.add
+ end))
+(;; STDOUT ;;;
+function f_a(a:int, b:int):int {
+ a + br_table[L_a, ..L_a](unreachable);
+ return loop L_a {
+ }
+}
+
+;;; STDOUT ;;)
diff --git a/test/regress/regress-1924.txt b/test/regress/regress-1924.txt
new file mode 100644
index 00000000..a755a559
--- /dev/null
+++ b/test/regress/regress-1924.txt
@@ -0,0 +1,16 @@
+;;; TOOL: run-wasm-decompile
+(module
+ (type (;0;) (func (result i64)))
+ (func (;0;) (type 0) (result i64)
+ global.get 0)
+ (global (;0;) i64 (i64.const 8))
+ (export "" (global 0))
+)
+(;; STDOUT ;;;
+export global __empty:long = 8L;
+
+function f_a():long {
+ return __empty
+}
+
+;;; STDOUT ;;)