summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ir.cc57
-rw-r--r--src/binary-reader.cc172
-rw-r--r--src/shared-validator.cc18
3 files changed, 60 insertions, 187 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index b1c341b0..f1e3d32b 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -270,6 +270,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result TopLabel(LabelNode** label);
Result TopLabelExpr(LabelNode** label, Expr** expr);
Result AppendExpr(std::unique_ptr<Expr> expr);
+ void SetFuncDeclaration(FuncDeclaration* decl, Var var);
void SetBlockDeclaration(BlockDeclaration* decl, Type sig_type);
std::string GetUniqueName(BindingHash* bindings,
@@ -349,13 +350,19 @@ Result BinaryReaderIR::AppendExpr(std::unique_ptr<Expr> expr) {
return Result::Ok;
}
+void BinaryReaderIR::SetFuncDeclaration(FuncDeclaration* decl, Var var) {
+ decl->has_func_type = true;
+ decl->type_var = var;
+ if (auto* func_type = module_->GetFuncType(var)) {
+ decl->sig = func_type->sig;
+ }
+}
+
void BinaryReaderIR::SetBlockDeclaration(BlockDeclaration* decl,
Type sig_type) {
if (sig_type.IsIndex()) {
Index type_index = sig_type.GetIndex();
- decl->has_func_type = true;
- decl->type_var = Var(type_index);
- decl->sig = cast<FuncType>(module_->types[type_index])->sig;
+ SetFuncDeclaration(decl, Var(type_index));
} else {
decl->has_func_type = false;
decl->sig.param_types.clear();
@@ -422,9 +429,7 @@ Result BinaryReaderIR::OnImportFunc(Index import_index,
auto import = MakeUnique<FuncImport>();
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
- import->func.decl.has_func_type = true;
- import->func.decl.type_var = Var(sig_index, GetLocation());
- import->func.decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&import->func.decl, Var(sig_index, GetLocation()));
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
@@ -483,9 +488,7 @@ Result BinaryReaderIR::OnImportEvent(Index import_index,
auto import = MakeUnique<EventImport>();
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
- import->event.decl.has_func_type = true;
- import->event.decl.type_var = Var(sig_index, GetLocation());
- import->event.decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&import->event.decl, Var(sig_index, GetLocation()));
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
@@ -501,9 +504,7 @@ Result BinaryReaderIR::OnFunctionCount(Index count) {
Result BinaryReaderIR::OnFunction(Index index, Index sig_index) {
auto field = MakeUnique<FuncModuleField>(GetLocation());
Func& func = field->func;
- func.decl.has_func_type = true;
- func.decl.type_var = Var(sig_index, GetLocation());
- func.decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&func.decl, Var(sig_index, GetLocation()));
module_->AppendField(std::move(field));
return Result::Ok;
}
@@ -583,23 +584,6 @@ Result BinaryReaderIR::OnExport(Index index,
auto field = MakeUnique<ExportModuleField>(GetLocation());
Export& export_ = field->export_;
export_.name = name.to_string();
- switch (kind) {
- case ExternalKind::Func:
- assert(item_index < module_->funcs.size());
- break;
- case ExternalKind::Table:
- assert(item_index < module_->tables.size());
- break;
- case ExternalKind::Memory:
- assert(item_index < module_->memories.size());
- break;
- case ExternalKind::Global:
- assert(item_index < module_->globals.size());
- break;
- case ExternalKind::Event:
- assert(item_index < module_->events.size());
- break;
- }
export_.var = Var(item_index, GetLocation());
export_.kind = kind;
module_->AppendField(std::move(field));
@@ -607,7 +591,6 @@ Result BinaryReaderIR::OnExport(Index index,
}
Result BinaryReaderIR::OnStartFunction(Index func_index) {
- assert(func_index < module_->funcs.size());
Var start(func_index, GetLocation());
module_->AppendField(MakeUnique<StartModuleField>(start, GetLocation()));
return Result::Ok;
@@ -712,31 +695,25 @@ Result BinaryReaderIR::OnBrTableExpr(Index num_targets,
}
Result BinaryReaderIR::OnCallExpr(Index func_index) {
- assert(func_index < module_->funcs.size());
return AppendExpr(MakeUnique<CallExpr>(Var(func_index)));
}
Result BinaryReaderIR::OnCallIndirectExpr(Index sig_index, Index table_index) {
assert(sig_index < module_->types.size());
auto expr = MakeUnique<CallIndirectExpr>();
- expr->decl.has_func_type = true;
- expr->decl.type_var = Var(sig_index, GetLocation());
- expr->decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
expr->table = Var(table_index);
return AppendExpr(std::move(expr));
}
Result BinaryReaderIR::OnReturnCallExpr(Index func_index) {
- assert(func_index < module_->funcs.size());
return AppendExpr(MakeUnique<ReturnCallExpr>(Var(func_index)));
}
Result BinaryReaderIR::OnReturnCallIndirectExpr(Index sig_index, Index table_index) {
assert(sig_index < module_->types.size());
auto expr = MakeUnique<ReturnCallIndirectExpr>();
- expr->decl.has_func_type = true;
- expr->decl.type_var = Var(sig_index, GetLocation());
- expr->decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
expr->table = Var(table_index);
return AppendExpr(std::move(expr));
}
@@ -1257,9 +1234,7 @@ Result BinaryReaderIR::OnLocalName(Index func_index,
Result BinaryReaderIR::OnEventType(Index index, Index sig_index) {
auto field = MakeUnique<EventModuleField>(GetLocation());
Event& event = field->event;
- event.decl.has_func_type = true;
- event.decl.type_var = Var(sig_index, GetLocation());
- event.decl.sig = cast<FuncType>(module_->types[sig_index])->sig;
+ SetFuncDeclaration(&event.decl, Var(sig_index, GetLocation()));
module_->AppendField(std::move(field));
return Result::Ok;
}
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 2a28a569..3eabc698 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -113,10 +113,6 @@ class BinaryReader {
bool IsBlockType(Type);
Index NumTotalFuncs();
- Index NumTotalTables();
- Index NumTotalMemories();
- Index NumTotalGlobals();
- Index NumTotalEvents();
Result ReadI32InitExpr(Index index) WABT_WARN_UNUSED;
Result ReadInitExpr(Index index, bool require_i32 = false) WABT_WARN_UNUSED;
@@ -158,20 +154,13 @@ class BinaryReader {
BinarySection last_known_section_ = BinarySection::Invalid;
bool did_read_names_section_ = false;
bool reading_custom_section_ = false;
- Index num_signatures_ = 0;
- Index num_imports_ = 0;
Index num_func_imports_ = 0;
Index num_table_imports_ = 0;
Index num_memory_imports_ = 0;
Index num_global_imports_ = 0;
Index num_event_imports_ = 0;
Index num_function_signatures_ = 0;
- Index num_tables_ = 0;
- Index num_memories_ = 0;
- Index num_globals_ = 0;
- Index num_exports_ = 0;
Index num_function_bodies_ = 0;
- Index num_events_ = 0;
Index data_count_ = kInvalidIndex;
using ReadEndRestoreGuard =
@@ -417,29 +406,13 @@ bool BinaryReader::IsBlockType(Type type) {
return false;
}
- return type.GetIndex() < num_signatures_;
+ return true;
}
Index BinaryReader::NumTotalFuncs() {
return num_func_imports_ + num_function_signatures_;
}
-Index BinaryReader::NumTotalTables() {
- return num_table_imports_ + num_tables_;
-}
-
-Index BinaryReader::NumTotalMemories() {
- return num_memory_imports_ + num_memories_;
-}
-
-Index BinaryReader::NumTotalGlobals() {
- return num_global_imports_ + num_globals_;
-}
-
-Index BinaryReader::NumTotalEvents() {
- return num_event_imports_ + num_events_;
-}
-
Result BinaryReader::ReadI32InitExpr(Index index) {
return ReadInitExpr(index, true);
}
@@ -538,8 +511,6 @@ Result BinaryReader::ReadTable(Type* out_elem_type, Limits* out_elem_limits) {
ERROR_IF(is_shared, "tables may not be shared");
if (has_max) {
CHECK_RESULT(ReadU32Leb128(&max, "table max elem count"));
- ERROR_UNLESS(initial <= max,
- "table initial elem count must be <= max elem count");
}
out_elem_limits->has_max = has_max;
@@ -554,14 +525,10 @@ Result BinaryReader::ReadMemory(Limits* out_page_limits) {
uint32_t max = 0;
CHECK_RESULT(ReadU32Leb128(&flags, "memory flags"));
CHECK_RESULT(ReadU32Leb128(&initial, "memory initial page count"));
- ERROR_UNLESS(initial <= WABT_MAX_PAGES, "invalid memory initial size");
bool has_max = flags & WABT_BINARY_LIMITS_HAS_MAX_FLAG;
bool is_shared = flags & WABT_BINARY_LIMITS_IS_SHARED_FLAG;
- ERROR_IF(is_shared && !has_max, "shared memory must have a max size");
if (has_max) {
CHECK_RESULT(ReadU32Leb128(&max, "memory max page count"));
- ERROR_UNLESS(max <= WABT_MAX_PAGES, "invalid memory max size");
- ERROR_UNLESS(initial <= max, "memory initial size must be <= max size");
}
out_page_limits->has_max = has_max;
@@ -792,8 +759,6 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
case Opcode::Call: {
Index func_index;
CHECK_RESULT(ReadIndex(&func_index, "call function index"));
- ERROR_UNLESS(func_index < NumTotalFuncs(),
- "invalid call function index: %" PRIindex, func_index);
CALLBACK(OnCallExpr, func_index);
CALLBACK(OnOpcodeIndex, func_index);
break;
@@ -802,18 +767,13 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
case Opcode::CallIndirect: {
Index sig_index;
CHECK_RESULT(ReadIndex(&sig_index, "call_indirect signature index"));
- ERROR_UNLESS(sig_index < num_signatures_,
- "invalid call_indirect signature index");
Index table_index = 0;
if (options_.features.reference_types_enabled()) {
CHECK_RESULT(ReadIndex(&table_index, "call_indirect table index"));
- ERROR_UNLESS(table_index < NumTotalTables(),
- "invalid call_indirect table index");
} else {
uint8_t reserved;
CHECK_RESULT(ReadU8(&reserved, "call_indirect reserved"));
- ERROR_UNLESS(reserved == 0,
- "call_indirect reserved value must be 0");
+ ERROR_UNLESS(reserved == 0, "call_indirect reserved value must be 0");
}
CALLBACK(OnCallIndirectExpr, sig_index, table_index);
CALLBACK(OnOpcodeUint32Uint32, sig_index, table_index);
@@ -823,9 +783,6 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
case Opcode::ReturnCall: {
Index func_index;
CHECK_RESULT(ReadIndex(&func_index, "return_call"));
- ERROR_UNLESS(func_index < NumTotalFuncs(),
- "invalid return_call function index: %" PRIindex,
- func_index);
CALLBACK(OnReturnCallExpr, func_index);
CALLBACK(OnOpcodeIndex, func_index);
break;
@@ -834,18 +791,15 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
case Opcode::ReturnCallIndirect: {
Index sig_index;
CHECK_RESULT(ReadIndex(&sig_index, "return_call_indirect"));
- ERROR_UNLESS(sig_index < num_signatures_,
- "invalid return_call_indirect signature index");
Index table_index = 0;
if (options_.features.reference_types_enabled()) {
- CHECK_RESULT(ReadIndex(&table_index, "return_call_indirect table index"));
- ERROR_UNLESS(table_index < NumTotalTables(),
- "invalid return_call_indirect table index");
+ CHECK_RESULT(
+ ReadIndex(&table_index, "return_call_indirect table index"));
} else {
uint8_t reserved;
CHECK_RESULT(ReadU8(&reserved, "return_call_indirect reserved"));
ERROR_UNLESS(reserved == 0,
- "return_call_indirect reserved value must be 0");
+ "return_call_indirect reserved value must be 0");
}
CALLBACK(OnReturnCallIndirectExpr, sig_index, table_index);
CALLBACK(OnOpcodeUint32Uint32, sig_index, table_index);
@@ -1449,9 +1403,6 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
CHECK_RESULT(ReadIndex(&segment, "elem segment index"));
Index table_index;
CHECK_RESULT(ReadIndex(&table_index, "reserved table index"));
- if (!options_.features.reference_types_enabled()) {
- ERROR_UNLESS(table_index == 0, "table.index index must be 0");
- }
CALLBACK(OnTableInitExpr, segment, table_index);
CALLBACK(OnOpcodeUint32Uint32, segment, table_index);
break;
@@ -1509,13 +1460,7 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
Index table_dst;
Index table_src;
CHECK_RESULT(ReadIndex(&table_dst, "reserved table index"));
- if (!options_.features.reference_types_enabled()) {
- ERROR_UNLESS(table_dst == 0, "table.copy dst must be 0");
- }
CHECK_RESULT(ReadIndex(&table_src, "table src"));
- if (!options_.features.reference_types_enabled()) {
- ERROR_UNLESS(table_src == 0, "table.copy src must be 0");
- }
CALLBACK(OnTableCopyExpr, table_dst, table_src);
CALLBACK(OnOpcodeUint32Uint32, table_dst, table_src);
break;
@@ -1897,17 +1842,16 @@ Result BinaryReader::ReadEventType(Index* out_sig_index) {
CHECK_RESULT(ReadU32Leb128(&attribute, "event attribute"));
ERROR_UNLESS(attribute == 0, "event attribute must be 0");
CHECK_RESULT(ReadIndex(out_sig_index, "event signature index"));
- ERROR_UNLESS(*out_sig_index < num_signatures_,
- "invalid event signature index");
return Result::Ok;
}
Result BinaryReader::ReadEventSection(Offset section_size) {
CALLBACK(BeginEventSection, section_size);
- CHECK_RESULT(ReadCount(&num_events_, "event count"));
- CALLBACK(OnEventCount, num_events_);
+ Index num_events;
+ CHECK_RESULT(ReadCount(&num_events, "event count"));
+ CALLBACK(OnEventCount, num_events);
- for (Index i = 0; i < num_events_; ++i) {
+ for (Index i = 0; i < num_events; ++i) {
Index event_index = num_event_imports_ + i;
Index sig_index;
CHECK_RESULT(ReadEventType(&sig_index));
@@ -1945,10 +1889,11 @@ Result BinaryReader::ReadCustomSection(Offset section_size) {
Result BinaryReader::ReadTypeSection(Offset section_size) {
CALLBACK(BeginTypeSection, section_size);
- CHECK_RESULT(ReadCount(&num_signatures_, "type count"));
- CALLBACK(OnTypeCount, num_signatures_);
+ Index num_signatures;
+ CHECK_RESULT(ReadCount(&num_signatures, "type count"));
+ CALLBACK(OnTypeCount, num_signatures);
- for (Index i = 0; i < num_signatures_; ++i) {
+ for (Index i = 0; i < num_signatures; ++i) {
Type form;
CHECK_RESULT(ReadType(&form, "type form"));
@@ -1970,9 +1915,6 @@ Result BinaryReader::ReadTypeSection(Offset section_size) {
Index num_results;
CHECK_RESULT(ReadCount(&num_results, "function result count"));
- ERROR_UNLESS(
- num_results <= 1 || options_.features.multi_value_enabled(),
- "result count must be 0 or 1");
result_types_.resize(num_results);
@@ -2012,9 +1954,10 @@ Result BinaryReader::ReadTypeSection(Offset section_size) {
Result BinaryReader::ReadImportSection(Offset section_size) {
CALLBACK(BeginImportSection, section_size);
- CHECK_RESULT(ReadCount(&num_imports_, "import count"));
- CALLBACK(OnImportCount, num_imports_);
- for (Index i = 0; i < num_imports_; ++i) {
+ Index num_imports;
+ CHECK_RESULT(ReadCount(&num_imports, "import count"));
+ CALLBACK(OnImportCount, num_imports);
+ for (Index i = 0; i < num_imports; ++i) {
string_view module_name;
CHECK_RESULT(ReadStr(&module_name, "import module name"));
string_view field_name;
@@ -2028,8 +1971,6 @@ Result BinaryReader::ReadImportSection(Offset section_size) {
case ExternalKind::Func: {
Index sig_index;
CHECK_RESULT(ReadIndex(&sig_index, "import signature index"));
- ERROR_UNLESS(sig_index < num_signatures_,
- "invalid import signature index");
CALLBACK(OnImportFunc, i, module_name, field_name, num_func_imports_,
sig_index);
num_func_imports_++;
@@ -2078,15 +2019,6 @@ Result BinaryReader::ReadImportSection(Offset section_size) {
}
}
- ERROR_UNLESS(num_memory_imports_ <= 1,
- "memory count (%" PRIindex ") must be 0 or 1",
- num_memory_imports_);
- if (!options_.features.reference_types_enabled()) {
- ERROR_UNLESS(num_table_imports_ <= 1,
- "table count (%" PRIindex ") must be 0 or 1",
- num_table_imports_);
- }
-
CALLBACK0(EndImportSection);
return Result::Ok;
}
@@ -2100,8 +2032,6 @@ Result BinaryReader::ReadFunctionSection(Offset section_size) {
Index func_index = num_func_imports_ + i;
Index sig_index;
CHECK_RESULT(ReadIndex(&sig_index, "function signature index"));
- ERROR_UNLESS(sig_index < num_signatures_,
- "invalid function signature index: %" PRIindex, sig_index);
CALLBACK(OnFunction, func_index, sig_index);
}
CALLBACK0(EndFunctionSection);
@@ -2110,14 +2040,10 @@ Result BinaryReader::ReadFunctionSection(Offset section_size) {
Result BinaryReader::ReadTableSection(Offset section_size) {
CALLBACK(BeginTableSection, section_size);
- CHECK_RESULT(ReadCount(&num_tables_, "table count"));
- if (!options_.features.reference_types_enabled()) {
- ERROR_UNLESS(num_table_imports_ + num_tables_ <= 1,
- "table count (%" PRIindex ") must be 0 or 1",
- num_table_imports_ + num_tables_);
- }
- CALLBACK(OnTableCount, num_tables_);
- for (Index i = 0; i < num_tables_; ++i) {
+ Index num_tables;
+ CHECK_RESULT(ReadCount(&num_tables, "table count"));
+ CALLBACK(OnTableCount, num_tables);
+ for (Index i = 0; i < num_tables; ++i) {
Index table_index = num_table_imports_ + i;
Type elem_type;
Limits elem_limits;
@@ -2130,12 +2056,10 @@ Result BinaryReader::ReadTableSection(Offset section_size) {
Result BinaryReader::ReadMemorySection(Offset section_size) {
CALLBACK(BeginMemorySection, section_size);
- CHECK_RESULT(ReadCount(&num_memories_, "memory count"));
- ERROR_UNLESS(num_memory_imports_ + num_memories_ <= 1,
- "memory count (%" PRIindex ") must be 0 or 1",
- num_memory_imports_ + num_memories_);
- CALLBACK(OnMemoryCount, num_memories_);
- for (Index i = 0; i < num_memories_; ++i) {
+ Index num_memories;
+ CHECK_RESULT(ReadCount(&num_memories, "memory count"));
+ CALLBACK(OnMemoryCount, num_memories);
+ for (Index i = 0; i < num_memories; ++i) {
Index memory_index = num_memory_imports_ + i;
Limits page_limits;
CHECK_RESULT(ReadMemory(&page_limits));
@@ -2147,9 +2071,10 @@ Result BinaryReader::ReadMemorySection(Offset section_size) {
Result BinaryReader::ReadGlobalSection(Offset section_size) {
CALLBACK(BeginGlobalSection, section_size);
- CHECK_RESULT(ReadCount(&num_globals_, "global count"));
- CALLBACK(OnGlobalCount, num_globals_);
- for (Index i = 0; i < num_globals_; ++i) {
+ Index num_globals;
+ CHECK_RESULT(ReadCount(&num_globals, "global count"));
+ CALLBACK(OnGlobalCount, num_globals);
+ for (Index i = 0; i < num_globals; ++i) {
Index global_index = num_global_imports_ + i;
Type global_type;
bool mutable_;
@@ -2166,9 +2091,10 @@ Result BinaryReader::ReadGlobalSection(Offset section_size) {
Result BinaryReader::ReadExportSection(Offset section_size) {
CALLBACK(BeginExportSection, section_size);
- CHECK_RESULT(ReadCount(&num_exports_, "export count"));
- CALLBACK(OnExportCount, num_exports_);
- for (Index i = 0; i < num_exports_; ++i) {
+ Index num_exports;
+ CHECK_RESULT(ReadCount(&num_exports, "export count"));
+ CALLBACK(OnExportCount, num_exports);
+ for (Index i = 0; i < num_exports; ++i) {
string_view name;
CHECK_RESULT(ReadStr(&name, "export item name"));
@@ -2177,29 +2103,9 @@ Result BinaryReader::ReadExportSection(Offset section_size) {
Index item_index;
CHECK_RESULT(ReadIndex(&item_index, "export item index"));
- switch (kind) {
- case ExternalKind::Func:
- ERROR_UNLESS(item_index < NumTotalFuncs(),
- "invalid export func index: %" PRIindex, item_index);
- break;
- case ExternalKind::Table:
- ERROR_UNLESS(item_index < NumTotalTables(),
- "invalid export table index: %" PRIindex, item_index);
- break;
- case ExternalKind::Memory:
- ERROR_UNLESS(item_index < NumTotalMemories(),
- "invalid export memory index: %" PRIindex, item_index);
- break;
- case ExternalKind::Global:
- ERROR_UNLESS(item_index < NumTotalGlobals(),
- "invalid export global index: %" PRIindex, item_index);
- break;
- case ExternalKind::Event:
- ERROR_UNLESS(options_.features.exceptions_enabled(),
- "invalid export event kind: exceptions not allowed");
- ERROR_UNLESS(item_index < NumTotalEvents(),
- "invalid export event index: %" PRIindex, item_index);
- break;
+ if (kind == ExternalKind::Event) {
+ ERROR_UNLESS(options_.features.exceptions_enabled(),
+ "invalid export event kind: exceptions not allowed");
}
CALLBACK(OnExport, i, static_cast<ExternalKind>(kind), item_index, name);
@@ -2212,8 +2118,6 @@ Result BinaryReader::ReadStartSection(Offset section_size) {
CALLBACK(BeginStartSection, section_size);
Index func_index;
CHECK_RESULT(ReadIndex(&func_index, "start function index"));
- ERROR_UNLESS(func_index < NumTotalFuncs(),
- "invalid start function index: %" PRIindex, func_index);
CALLBACK(OnStartFunction, func_index);
CALLBACK0(EndStartSection);
return Result::Ok;
@@ -2224,8 +2128,6 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
Index num_elem_segments;
CHECK_RESULT(ReadCount(&num_elem_segments, "elem segment count"));
CALLBACK(OnElemSegmentCount, num_elem_segments);
- ERROR_UNLESS(num_elem_segments == 0 || NumTotalTables() > 0,
- "elem section without table section");
for (Index i = 0; i < num_elem_segments; ++i) {
uint32_t flags;
CHECK_RESULT(ReadU32Leb128(&flags, "elem segment flags"));
@@ -2341,8 +2243,6 @@ Result BinaryReader::ReadDataSection(Offset section_size) {
Index num_data_segments;
CHECK_RESULT(ReadCount(&num_data_segments, "data segment count"));
CALLBACK(OnDataSegmentCount, num_data_segments);
- ERROR_UNLESS(num_data_segments == 0 || NumTotalMemories() > 0,
- "data section without memory section");
// If the DataCount section is not present, then data_count_ will be invalid.
ERROR_UNLESS(data_count_ == kInvalidIndex || data_count_ == num_data_segments,
"data segment count does not equal count in DataCount section");
diff --git a/src/shared-validator.cc b/src/shared-validator.cc
index 1d251e2e..5af98356 100644
--- a/src/shared-validator.cc
+++ b/src/shared-validator.cc
@@ -49,19 +49,20 @@ Result SharedValidator::OnFuncType(const Location& loc,
const Type* param_types,
Index result_count,
const Type* result_types) {
+ Result result = Result::Ok;
+ if (!options_.features.multi_value_enabled() && result_count > 1) {
+ result |=
+ PrintError(loc, "multiple result values not currently supported.");
+ }
types_.push_back(FuncType{ToTypeVector(param_count, param_types),
ToTypeVector(result_count, result_types)});
- return Result::Ok;
+ return result;
}
Result SharedValidator::OnFunction(const Location& loc, Var sig_var) {
Result result = Result::Ok;
FuncType type;
result |= CheckTypeIndex(sig_var, &type);
- if (!options_.features.multi_value_enabled() && type.results.size() > 1) {
- result |=
- PrintError(loc, "multiple result values not currently supported.");
- }
funcs_.push_back(type);
return result;
}
@@ -481,11 +482,8 @@ Result SharedValidator::CheckBlockSignature(const Location& loc,
result |= PrintError(loc, "%s params not currently supported.",
opcode.GetName());
}
- if (func_type.results.size() > 1 &&
- !options_.features.multi_value_enabled()) {
- result |= PrintError(loc, "multiple %s results not currently supported.",
- opcode.GetName());
- }
+ // Multiple results without --enable-multi-value is checked above in
+ // OnType.
*out_param_types = func_type.params;
*out_result_types = func_type.results;