diff options
author | Alon Zakai <azakai@google.com> | 2021-03-29 15:32:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 15:32:01 -0700 |
commit | 09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d (patch) | |
tree | bc654bcc92cab64a08fe0bd9197c2f9c4a324ca4 /src/wasm/wasm-validator.cpp | |
parent | 244f886cb2f1d9c5dddbf2dea5d47e6b0a434c5d (diff) | |
download | binaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.tar.gz binaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.tar.bz2 binaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.zip |
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.
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
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()) { |