summaryrefslogtreecommitdiff
path: root/src/wasm-validator.h
Commit message (Collapse)AuthorAgeFilesLines
* Do not optimize public types (#5347)Thomas Lively2022-12-161-1/+4
| | | | | | | | | | | | | | | | | Do not optimize or modify public heap types in any way. Public heap types include the types of imported or exported functions, tables, globals, etc. This is important to maintain the public interface of a module and ensure it can still link interact as intended with the outside world. Also add validation error if we find any nontrivial public types that are not the types of imported or exported functions. This error is meant to help the user ensure that type optimizations are not silently inhibited. In the future, we may want to add options to silence this error or downgrade it to a warning. This commit only updates the type updating machinery to avoid updating public types. It does not update any optimization passes accordingly. Since we avoid modifying public signature types already, this is not expected to break anything, but in the future once we have function subtyping or if we make the error optional, we may have to update some of our optimization passes.
* Switch from `typedef` to `using` in C++ code. NFC (#5258)Sam Clegg2022-11-151-1/+1
| | | | This is more modern and (IMHO) easier to read than that old C typedef syntax.
* Function-level pass-debug mode 2 validation (#4897)Alon Zakai2022-08-121-0/+4
| | | | | | In BINARYEN_PASS_DEBUG=2 we save the module before each pass, and if validation fails afterwards, we print the module before. This PR does the same for function-parallel passes - in that case, we can actually show the specific function that broke validation, as opposed to the whole module.
* Refactor printing code so that printing Expressions always works (#3450)Alon Zakai2020-12-171-1/+0
| | | | | | | | This avoids needing to add include wasm-printing if a file doesn't already have it. To achieve that, add the std::ostream hooks in wasm.h, and also use them when possible, removing the need for the special WasmPrinter object. Also stop printing in "full" (print types on each line) in error messages by default. The user can still get that, as always, using BINARYEN_PRINT_FULL=1 in the env.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-1/+1
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-121-1/+1
| | | | | This allows us to emit a (potentially modified) target features section and conditionally emit other sections such as the DataCount section based on the presence of features.
* Feature options (#1797)Thomas Lively2018-12-031-1/+1
| | | | Add feature flags and struct interface. Default feature set has all feature enabled.
* Add Features enum to IR (#1250)Derek Schuff2017-10-271-1/+1
| | | | | | | | | | | | This enum describes which wasm features the IR is expected to include. The validator should reject operations which require excluded features, and passes should avoid producing IR which requires excluded features. This makes it easier to catch possible errors in Binaryen producers (e.g. emscripten). Asm2wasm has a flag to enable or disable atomics. Other tools currently just accept all features (as, dis and opt are just for inspecting or modifying existing modules, so it would be annoying to have to use flags with those tools and I expect the risk of accidentally introducing atomics to be low).
* Refactor validator API to use enums (#1209)Alon Zakai2017-10-031-1/+9
| | | | * refactor validator API to use enums
* Fast validation (#1204)Alon Zakai2017-10-021-182/+4
| | | | | | | This makes wasm validation parallel (the function part). This makes loading+validating tanks (a 12MB wasm file) 2.3x faster on a 4-core machine (from 3.5 to 1.5 seconds). It's a big speedup because most of loading+validating was actually validating. It's also noticeable during compilation, since we validate by default at the end. 8% faster on -O2 and 23% on -O0. So actually fairly significant on -O0 builds. As a bonus, this PR also moves the code from being 99% in the header to be 1% in the header.
* Expressions should not appear twice in the ast (#1191)Alon Zakai2017-09-181-0/+3
|
* clean up untaken => unreachable, as well as unnecessary named stuff in ↵Alon Zakai2017-09-061-1/+0
| | | | validation that was from when we differentiated reachable from unreachable breaks (#1166)
* wasm-reduce tool (#1139)Alon Zakai2017-09-011-1/+3
| | | Reduce an interesting wasm to a smaller still interesting wasm. This takes an arbitrary command to run, and reduces the wasm as much as it can while keeping the behavior of that command fixed. This can be used to reduce compiler bugs in an arbitrary VM, etc.
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-0/+2
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators
* Merge pull request #1095 from WebAssembly/fuzz-3Alon Zakai2017-07-181-1/+1
|\ | | | | More fuzz fixes
| * fix validation of memBytes, if the load type is unreachable, we can't and ↵Alon Zakai (kripken)2017-07-131-1/+1
| | | | | | | | shouldn't try to validate
* | Validation for AtomicRMW and cmpxchg (#1092)Derek Schuff2017-07-141-9/+12
|/ | | | Also fix cases where fail() had the arguments backwards. Wasn't an error because lol templates. Also fix printModuleComponent template to SFINAE on Expression* so we properly get the specialized version.
* Merge pull request #1087 from WebAssembly/fuzz-2Alon Zakai2017-07-121-3/+4
|\ | | | | Fuzz fixes
| * refactor and improve break validation. breaks names are unique, so we don't ↵Alon Zakai (kripken)2017-07-111-3/+4
| | | | | | | | need a stack, and break targets must exist even if they are not actually taken
* | Refactor validation failure and printing, validate atomic memory (#1090)Derek Schuff2017-07-121-23/+34
|/
* Factor wasm validator into a cpp file (#1086)Derek Schuff2017-07-101-611/+35
| | | Also small cleanup to CMake libraries
* Support new result syntax for if/loop/block (#1047)Sam Clegg2017-06-121-1/+1
| | | | | | Support both syntax formats in input since the old spec tests still need to be parsable.
* validate returned values in all cases, even if the function returns none we ↵Alon Zakai2017-06-021-6/+4
| | | | should still not have returns with a value, etc. update spec tests to remove some stacky tests that do not fit these new validation rules (#1034)
* error if select sides are concrete but differentAlon Zakai (kripken)2017-06-011-0/+3
|
* in extra pass-debug validation, don't assume there is always a function, the ↵Alon Zakai (kripken)2017-06-011-1/+1
| | | | error may be in a global init
* More fuzz fixes (#1021)Alon Zakai2017-05-221-4/+16
| | | | | | * validate that memory/table segment values fit in the initial range * validate that select condition should be i32
* use TypeUpdater in vacuumAlon Zakai (kripken)2017-05-201-6/+15
|
* Address review feedback for #1014 (#1016)Alon Zakai2017-05-181-3/+3
| | | | | | * address review feedback for #1014
* Validate finalization (#1014)Alon Zakai2017-05-181-7/+50
| | | | | | | * validate that types are properly finalized, when in pass-debug mode (BINARYEN_PASS_DEBUG env var): check after each pass is run that the type of each node is equal to the proper type (when finalizing it, i.e., fully recomputing the type). * fix many fuzz bugs found by that. * in particular, fix dce bugs with type changes not being fully updated during code removal. add a new TypeUpdater helper class that lets a pass update types efficiently, by the helper tracking deps between blocks and branches etc., and updating/propagating type changes only as necessary.
* fix unreachable typing: for all nodes, if they are not reached - e.g., a ↵Alon Zakai (kripken)2017-05-021-12/+2
| | | | binary with either side unreachable - then they are unreachable. this makes our usage of the unreachable type consistent
* disallow empty blocks with a type - if they return a type, they must have ↵Alon Zakai2017-05-021-0/+3
| | | | contents. make s2wasm avoid outputting that as well (#992)
* Validation fixes for issues noticed by afl (#988)Alon Zakai2017-05-021-6/+109
| | | | | | | | | | | | * properly validate block endings * blocks with a value must not have a last element that is none * fully validate input types to binary expressions * validate i32.eqz/i64.eqz more carefully * if condition must be i32
* wasm-merge tool (#919)Alon Zakai2017-04-171-1/+3
| | | | wasm-merge tool: combines two wasm files into a larger one, handling collisions, and aware of the dynamic linking conventions. it does not do full static linking, but may eventually.
* finalize interim ifs in relooper, and other if handling issues (#940)Alon Zakai2017-03-131-0/+10
|
* Wasm h to cpp (#926)jgravelle-google2017-03-101-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | * Move WasmType function implementations to wasm.cpp * Move Literal methods to wasm.cpp * Reorder wasm.cpp shared constants back to top * Move expression functions to wasm.cpp * Finish moving things to wasm.cpp * Split out Literal into its own .h/.cpp. Also factor out common wasm-type module * Remove unneeded/transitive includes from wasm.h * Add comment to try/check methods * Rename tryX/checkX methods to getXOrNull * Add missing include that should fix appveyor build breakage * More appveyor
* Default Walker subclasses to using Visitor<SubType> (#921)jgravelle-google2017-02-231-3/+3
| | | | Most module walkers use PostWalker<T, Visitor<T>>, let that pattern be expressed as simply PostWalker<T>
* clean up raw pointer import->functionType, make it a Name like everything ↵Alon Zakai2017-02-171-4/+5
| | | | else (#915)
* Fix emitting of unreachable block/if/loop (#911)Alon Zakai2017-02-161-1/+6
| | | | | | | | | | | | | | | | | | | | | | * an unreachable block is one with an unreachable child, plus no breaks * document new difference between binaryen IR and wasm * fix relooper missing finalize * add a bunch of tests * don't assume that test/*.wast files print to themselves exactly; print to from.wast. this allows wast tests with comments in them * emit unreachable blocks as (block .. unreachable) unreachable * if without else and unreachable ifTrue is still not unreachable, it should be none * update wasm.js * cleanups * empty blocks have none type
* Handle importing globals in s2wasm (#843)jgravelle-google2016-11-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Handle importing globals in s2wasm * Make importedGlobals a set of Names, make Names hashable * Revert "Make importedGlobals a set of Names, make Names hashable" This reverts commit 1d0ca7a5e3839b15ca60593330979864c9c3ed60. * Refactor relocation parsing to handle expressions directly * PR Feedback - Move comment where it belongs - Add comment about ownership to addRelocation - Remove do-nothing parseImportGlobal * Reword "imported globals" to "imported objects" - Flip isObjectImported to isObjectImplemented, for consistency * Add tests for s2wasm globals. Also implement import relocation expression handling * Simplify globals.s test * Fix memory leak of relocation * Use unique_ptr instead of delete in getRelocatableExpression
* Don't create a memory section for an imported memory; fixes #772 (#773)Benjamin Bouvier2016-10-131-0/+3
|
* Don't create table sections for imported tables (#756)Derek Schuff2016-10-111-0/+3
| | | Previously the Print pass searched the imports for a table import and skipped printing a local table declaration if found. Instead this refactors to make importation explicit, and also create importation records (previously we were inconsistent about whether such records were created in the IR depending on the wast syntax).
* Require unique names in binaryen IR (#746)Alon Zakai2016-10-061-0/+13
|
* validate get_local type (#745)Alon Zakai2016-10-061-0/+3
|
* Refactor Import::Kind and Export::Kind into an ExternalKind enum class (#725)Alon Zakai2016-10-031-6/+6
|
* Document and clean up validation options (#730)Alon Zakai2016-10-031-9/+31
| | | | * document and clean up validation options
* passRunner debug and validation improvements (#726)Alon Zakai2016-10-021-5/+15
|
* asm2wasm i64 support (#723)Alon Zakai2016-09-301-0/+3
| | | | | | | | | | | | * support i64 intrinsics from fastcomp, adding --wasm-only flag * refactor callImport logic in asm2wasm to avoid recomputing wasm types again * legalize illegal i64 params in exports and imports * do safe i64 binary ops depending on precision * fix addVar, only assert on names if we are using a name
* validate drop (#712)Alon Zakai2016-09-301-6/+1
|
* Type check block/loop/if sigs (#717)Alon Zakai2016-09-281-0/+23
| | | | | | * type check using block/loop/if types provided in text and binary formats. * print if and loop sigs which were missing. * remove dsl from OptimizeInstructions as after those changes it needs rethinking.
* table elem parsing fixesAlon Zakai2016-09-201-1/+0
|