From 09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 29 Mar 2021 15:32:01 -0700 Subject: Scan module-level code in necessary places (#3744) Several old passes like DeadArgumentElimination and DuplicateFunctionElimination need to look at all ref.funcs, and they scanned functions for that, but that is not enough as such an instruction might appear in a global initializer. To fix this, add a walkModuleCode method. walkModuleCode is useful when doing the pattern of creating a function-parallel pass to scan functions quickly, but we also want to do the same scanning of code at the module level. This allows doing so in a single line. (It is also possible to just do walk() on the entire module, which will find all code, but that is not function-parallel. Perhaps we should have a walkParallel() option to simplify this further in a followup, and that would call walkModuleCode afterwards etc.) Also add some missing validation and comments in the validator about issues that I noticed in relation to the new testcases here. --- src/wasm/wasm-validator.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 425792e22..8bc12cadf 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1998,6 +1998,13 @@ void FunctionValidator::visitRefFunc(RefFunc* curr) { shouldBeTrue(curr->type.isFunction(), curr, "ref.func must have a function reference type"); + // TODO: verify it also has a typed function references type, and the right + // one, + // curr->type.getHeapType().getSignature() + // That is blocked on having the ability to create signature types in the C + // API (for now those users create the type with funcref). This also needs to + // be fixed in LegalizeJSInterface and FuncCastEmulation and other places that + // update function types. // TODO: check for non-nullability } @@ -2843,6 +2850,9 @@ static void validateTables(Module& module, ValidationInfo& info) { auto table = module.getTableOrNull(segment->table); info.shouldBeTrue( table != nullptr, "elem", "elem segment must have a valid table name"); + info.shouldBeTrue(!!segment->offset, + "elem", + "table segment offset should have an offset"); info.shouldBeEqual(segment->offset->type, Type(Type::i32), segment->offset, @@ -2853,6 +2863,10 @@ static void validateTables(Module& module, ValidationInfo& info) { segment->offset, "table segment offset should be reasonable"); validator.validate(segment->offset); + } else { + info.shouldBeTrue(!segment->offset, + "elem", + "non-table segment offset should have no offset"); } // Avoid double checking items if (module.features.hasReferenceTypes()) { -- cgit v1.2.3