@@ -93,23 +93,26 @@ struct WasmValidator : public PostWalker<WasmValidator, Visitor<WasmValidator>>
9393 shouldBeTrue (curr->condition ->type == unreachable || curr->condition ->type == i32 , curr, " br_table condition must be i32" );
9494 }
9595 void visitCall (Call *curr) {
96- auto * target = getModule ()->getFunction (curr->target );
97- shouldBeTrue (curr->operands .size () == target->params .size (), curr, " call param number must match" );
96+ auto * target = getModule ()->checkFunction (curr->target );
97+ if (!shouldBeTrue (!!target, curr, " call target must exist" )) return ;
98+ if (!shouldBeTrue (curr->operands .size () == target->params .size (), curr, " call param number must match" )) return ;
9899 for (size_t i = 0 ; i < curr->operands .size (); i++) {
99100 shouldBeEqualOrFirstIsUnreachable (curr->operands [i]->type , target->params [i], curr, " call param types must match" );
100101 }
101102 }
102103 void visitCallImport (CallImport *curr) {
103- auto * target = getModule ()->getImport (curr->target )->type ;
104- shouldBeTrue (curr->operands .size () == target->params .size (), curr, " call param number must match" );
104+ auto * import = getModule ()->checkImport (curr->target );
105+ if (!shouldBeTrue (!!import , curr, " call_import target must exist" )) return ;
106+ auto * type = import ->type ;
107+ if (!shouldBeTrue (curr->operands .size () == type->params .size (), curr, " call param number must match" )) return ;
105108 for (size_t i = 0 ; i < curr->operands .size (); i++) {
106- shouldBeEqualOrFirstIsUnreachable (curr->operands [i]->type , target ->params [i], curr, " call param types must match" );
109+ shouldBeEqualOrFirstIsUnreachable (curr->operands [i]->type , type ->params [i], curr, " call param types must match" );
107110 }
108111 }
109112 void visitCallIndirect (CallIndirect *curr) {
110113 auto * type = curr->fullType ;
111114 shouldBeEqualOrFirstIsUnreachable (curr->target ->type , i32 , curr, " indirect call target must be an i32" );
112- shouldBeTrue (curr->operands .size () == type->params .size (), curr, " call param number must match" );
115+ if (! shouldBeTrue (curr->operands .size () == type->params .size (), curr, " call param number must match" )) return ;
113116 for (size_t i = 0 ; i < curr->operands .size (); i++) {
114117 shouldBeEqualOrFirstIsUnreachable (curr->operands [i]->type , type->params [i], curr, " call param types must match" );
115118 }
@@ -245,7 +248,7 @@ struct WasmValidator : public PostWalker<WasmValidator, Visitor<WasmValidator>>
245248 }
246249 void visitMemory (Memory *curr) {
247250 shouldBeFalse (curr->initial > curr->max , " memory" , " memory max >= initial" );
248- shouldBeTrue (curr->max <= Memory::kMaxSize , " memory" , " total memory must be <= 4GB" );
251+ shouldBeTrue (curr->max <= Memory::kMaxSize , " memory" , " max memory must be <= 4GB" );
249252 size_t top = 0 ;
250253 for (auto & segment : curr->segments ) {
251254 shouldBeFalse (segment.offset < top, " memory" , " segment offset is small enough" );
0 commit comments