summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* Handle indirect calls in CallGraphPropertyAnalysis (#2624)Alon Zakai2020-01-242-1/+46
| | | | | | | | | | | | | We ignored them, which is a bad default, as typically they imply we can call anything in the table (and the table might change). Instead, notice indirect calls during traversal, and force the user to decide whether to ignore them or not. This was only an issue in PostEmscripten because the other user, Asyncify, already had indirect call analysis because it needed it for other things. Fixes a bug uncovered by #2619 and fixes the current binaryen roll.
* DWARF: Update .debug_loc (#2616)Alon Zakai2020-01-232-216/+216
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for that section to the YAML layer, and add code to update it. The updating is slightly tricky - unlike .debug_ranges, the size of entries is not fixed. So we can't just skip entries, as the end marker is smaller than a normal entry. Instead, replace now-invalid segments with (1, 1) which is of size 0 and so should be ignored by the debugger (we can't use (0, 0) as that would be an end marker, and (-1, *) is the special base marker). In the future we probably do want to do this in a more sophisticated manner, completely rewriting the indexes into the section as well. For now though this should be enough for when binaryen does not optimize (as we don't move/reorder anything). Note that this doesn't update the location description (like where on the wasm expression stack the value is). Again, that is correct for when binaryen doesn't optimize, but for fully optimized builds we would need to track things (which would be hard!). Also clean up some code that uses "Extra" instead of "Delimiter" that was missed before, and shorten some unnecessarily long names.
* Limit the number of passive segments to work around a Chrome bug (#2613)Thomas Lively2020-01-222-0/+590
| | | | | | Chrome is currently decoding the segment indices as signed numbers, so some ranges of indices greater than 63 do not work. As a temporary workaround, limit the number of segments produced by MemoryPacking to 63 when bulk-memory is enabled.
* DWARF: Update debug_ranges (#2612)Alon Zakai2020-01-225-44/+39
| | | | | | | | | | | | | | | | | | Pretty straightforward given all we have so far. Note that fannkuch3_manyopts has an example of a sequence of ranges of which some must be skipped while others must not, showing we handle that by skipping the bad ones and updating the remaining. That is, if that we have a sequence of two (begin, end) spans [(10, 20), (30, 40)] It's possible (10, 20) maps in the new binary to (110, 120) while (30, 40) was eliminated by the optimizer and we have nothing valid to map it to. In that case we emit [(110, 120)]
* DWARF: Fix debug lines in fannkuch -O0 (#2611)Alon Zakai2020-01-224-294/+10460
| | | | | | | | | | | | | | | | Just some trivial fixes: * Properly reset prologue after each line (unlike others, this flag should be reset immediately). * Test for a function's end address first, as LLVM output appears to use 1-past-the-end-of-the-function as a location in that function, and not the next (note the first byte of the next function, which is ambiguously identical to that value, is used at least in low_pc; I'm not sure if it's used in debug lines too). * Ignore the same address if LLVM emitted it more than once, which it does sometimes.
* DWARF: Use end_sequence and copy properly (#2610)Alon Zakai2020-01-225-2440/+2262
| | | | | | | We need to track end_sequence directly, and use either end_sequence or copy (copy emits a line without marking it as ending a sequence). After this, fib2 debug line output looks perfect.
* DWARF: Allow debug lines with column 0 (#2609)Alon Zakai2020-01-225-1786/+1833
| | | | While line and address values of 0 should be skipped, it seems like column 0 are valid lines emitted by LLVM.
* DWARF: Track more function locations (#2604)Alon Zakai2020-01-221-4/+12
| | | | | | | | | | | | | | DWARF from LLVM can refer to the first byte belonging to the function, where the size LEB is, or to the first byte after that, where the local declarations are, or the end opcode, or to one byte past that which is one byte past the bytes that belong to the function. We aren't sure why LLVM does this, but track it all for now. After this all debug line positions are identified. However, in some cases a debug line refers to one past the end of the function, which may be an LLVM bug. That location is ambiguous as it could also be the first byte of the next function (what made this discovery possible was when this happened to the last function, after which there is another section).
* DWARF: Track the positions of 'end', 'else', 'catch' binary locations (#2603)Alon Zakai2020-01-212-1128/+1170
| | | | | | | | | | | | | | | | | Control flow structures have those in addition to the normal span of (start, end), and we need to track them too. Tracking them during reading requires us to track control flow structures while parsing, so that we can know to which structure an end/else/catch refers to. We track these locations using a map on the side of instruction to its "extra" locations. That avoids increasing the size of the tracking info for the much more common non-control flow instructions. Note that there is one more 'end' location, that of the function (not referring to any instruction). I left that to a later PR to not increase this one too much.
* Unify JS memory segment API (#2533)Daniel Wirtz2020-01-211-3/+5
| | | | | | | | | | Binaryen.js now uses offset instead of byteOffset when inspecting a memory segment, matching the arguments on memory segment creation. Also adds inspection of the passive property. Previously, one would specify { offset, data, passive } on creation and get back { byteOffset, data } upon inspection. This PR unifies both to the keys on creation while also adding the respective C-API to retrieve passive status, which was missing.
* Update debug line info with function entries (#2600)Alon Zakai2020-01-175-756/+827
| | | | | | LLVM points to the start of the function in some debug line entries - right after the size LEB of the function, which is where the locals are declared, and before any instructions.
* Expose ExpressionAnalyzer in C-/JS-API (#2585)Daniel Wirtz2020-01-172-0/+106
| | | | | | | Instead of reinventing the wheel on our side, this adds ExpressionAnalyzer bindings to the C- and JS-APIs, which can be useful for generators. For example, a generator may decide to simplify a compilation step if a subexpression doesn't have any side effects, or simply skip emitting something that is likely to compile to a drop or an empty block right away.
* DWARF: high_pc computation (#2595)Alon Zakai2020-01-165-12/+12
| | | | | | | Update high_pc values. These are interesting as they may be a relative offset compared to the low_pc. For functions we already had both a start and an end. Add such tracking for instructions as well.
* Add EH support for CFGWalker (#2597)Heejin Ahn2020-01-162-0/+204
| | | | | | | | This adds EH instruction support for `CFGWalker`. This also implements `call` instruction handling within a try-catch; every call can possibly throw and unwind to the innermost catch block. This adds tests for RedundantSetElimination pass, which uses `CFGWalker`.
* Update DWARF testcases (#2594)Alon Zakai2020-01-166-8703/+9118
| | | | | This only touches test code. The files are compiled with latest LLVM + https://reviews.llvm.org/D71681 in order to get more realistic DWARF content.
* DWARF: Function location tracking (#2592)Alon Zakai2020-01-164-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Track the beginning and end of each function, both when reading and writing. We track expressions and functions separately, instead of having a single big map of (oldAddr) => (newAddr) because of the potentially ambiguous case of the final expression in a function: it's end might be identical in offset to the end of the function. So we have two different things that map to the same offset. However, if the context is "the end of the function" then the updated address is the new end of the function, even if the function ends with a different instruction now, as the old last instruction might have moved or been optimized out. Concretely, we have getNewExprAddr and getNewFuncAddr, so we can ask to update the location of either an expression or a function, and use that contextual information. This checks for the DIE tag in order to know what we are looking for. To be safe, if we hit an unknown tag, we halt, so that we don't silently miss things. As the test updates show, the new things we can do thanks to this PR are to update compile unit and subprogram low_pc locations. Note btw that in the first test (dwarfdump_roundtrip_dwarfdump.bin.txt) we change 5 to 0: that is correct since that test does not write out DWARF (it intentionally has no -g), so we do not track binary locations while writing, and so we have nothing to update to (the other tests show actual updating). Also fix the order in the python test runner code to show a diff of expected to encountered, and not the reverse, which confused me.
* Optimize passive segments in memory-packing (#2426)Thomas Lively2020-01-153-38/+1362
| | | | | | | | | When memory is packed and there are passive segments, bulk memory operations that reference those segments by index need to be updated to reflect the new indices and possibly split into multiple instructions that reference multiple split segments. For some bulk-memory operations, it is necessary to introduce new globals to explicitly track the drop state of the original segments, but this PR is careful to only add globals where necessary.
* Align binaryen.js with the npm package (#2551)Daniel Wirtz2020-01-1419-826/+693
| | | | | Binaryen.js now uses binaryen (was Binaryen) as its global name to align with the npm package. Also fixes issues with emitting and testing both the JS and Wasm builds.
* DWARF updating: update DW_AT_low_pc attributes (#2584)Alon Zakai2020-01-142-44/+44
| | | | | | | Mostly straightforward: go over the dwarf entries, find the low_pc ones, and update their positions. A slight oddity is that we must traverse both the dwarf context - which has the rich APIs for analsis - and the YAML data structure - which is minimal but is used for writing out.
* Omit DWARF debug line ranges starting with 0 (#2587)Alon Zakai2020-01-143-0/+1068
| | | | | | | | | | | Check if an entry starts a new range of addresses. Each range is a set of related addresses, where in particular, if the first has been zeroed out by the linker, we must omit the entire range. If we do not, then the initial range is 0 and the others are offsets relative to it, which will look like random addresses, perhaps into the middle of instructions, and perhaps that happen to collide with real ones (a debugger would ignore those, so we must too; it's easier and better to simply omit them). See https://bugs.llvm.org/show_bug.cgi?id=44516#c2
* Fix emitting of .debug_abbrev (#2582)Alon Zakai2020-01-105-10/+10
| | | | | gimli-rs and perhaps also the spec require a final 0 to terminate the list. LLVM itself is fine without that.
* wasm2js: Do not convert x >>> 0 | 0 to x >>> 0 (#2581)Alon Zakai2020-01-104-18/+18
| | | | | | | | | | | | isBinary was used where we should only accept a signed binary, as removing the | 0 from an unsigned value may be incorrect. This does regress a few small things (as can be seen in the diff). If it's important we can add more sophisticated optimizations here, perhaps like an assumption that the signedness of a local never matters. Fixes emscripten-core/emscripten#10173
* DWARF support for multiple line tables (#2557)Alon Zakai2020-01-098-0/+2493
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Multiple tables appear to be emitted when linking files together. This fixes our support for that, which did not update their size properly. This required patching the YAML emitting code from LLVM in order to measure the size and then emit it, as that code is apparently not designed to handle changes in line table contents. Other minor fixes: * Set the flags for our dwarfdump command to emit the same as llvm-dwarfdump does with -v -all. * Add support for a few more opcodes, set_discriminator, set_basic_block, fixed_advance_pc, set_isa. * Handle a compile unit without abbreviations in the YAML code (again, apparently not something this LLVM code was intended to do). * Handle a compile unit with zero entries in the YAML code (ditto). * Properly set the AddressSize - we use the DWARFContext in a different way than LLVM expects, apparently. With this the emscripten test suite passes with -gforce_dwarf without crashing. My overall impression so from the the YAML code is that it probably isn't a long-term solution for us. Perhaps it may end up being scaffolding, that is, we can replace it with our own code eventually that is based on it, and remove most of the LLVM code. Before deciding that we should get everything working first, and this seems like the quickest path there.
* Revert "Reland "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" ↵Sam Clegg2020-01-075-423/+47
| | | | | (#2542)" (#2576) This reverts commit f62e171c38bea14302f9b79f7941a248ea704425.
* DCE at the end of wasm2js (#2574)Alon Zakai2020-01-067-69/+262
| | | | | | By doing so we ensure that our calls to convert wasm types to JS types never try to convert an unreachable. Fixes #2558
* Do not print push/pop in stack IR (#2571)Heejin Ahn2020-01-062-9/+9
| | | | | This makes push and pop instructions not printed in the stack IR format to make it valid wat form. Push and pop are still generated in the stack IR in memory but not printed in the text format.
* Allow subtype in throw instruction (#2568)Heejin Ahn2020-01-064-1/+19
| | | | | This allows subtype for arguments of `throw`. This also renames `shouldBeSubTypeOrUnreachable` to `shouldBeSubTypeOrFirstIsUnreachable`, to be consistent with `shouldBeEqualOrFirstIsUnreachable`.
* Skip liveness analysis if too many locals (#2560)Alon Zakai2020-01-063-0/+36
| | | | | | | | | | | | | | | The analysis currently uses a dense matrix. If there are >65535 locals then the indexes don't fit in a 32-bit type like a wasm32 index, which led to overflows and incorrect behavior. To avoid that, don't run passes with liveness analysis for now if they have that many locals. Note that skipping coalesce-locals (the main liveness-using pass) is not that bad, as we run it more than once, and it's likely that even if the first must be skipped, we can still run the second (which is after simplify- and reorder-locals, which can greatly reduce the local count). Fixes #2559
* Parse memarg in atomic.wait and atomic.notify (#2569)Heejin Ahn2020-01-034-0/+80
| | | | | | - Allow `atomic.notify` and `atomic.wait` instructions to parse memory arguments (`align` and `offset`) and print the offset in these instruction when writing binary, rather than assuming it to be 0 - Change arguments of `parseMemAttributes` to be references
* Generate push/pop in stack IR (#2566)Heejin Ahn2020-01-032-0/+9
| | | | | | | | | | | We have not been generating push and pop instructions in the stack IR. Even though they are not written in binary, they have to be in the stack IR to match the number of inputs and outputs of instructions. Currently `BinaryenIRWriter` is used both for stack IR generation and binary generation, so we should emit those instructions in `BinaryenIRWriter`. `BinaryenIRToBinaryWriter`, which inherits `BinaryenIRWriter`, does not do anything for push and pop instructions, so they are still not emitted in binary.
* Add support for reference types proposal (#2451)Heejin Ahn2019-12-3055-1798/+5525
| | | | | | | | | | | | This adds support for the reference type proposal. This includes support for all reference types (`anyref`, `funcref`(=`anyfunc`), and `nullref`) and four new instructions: `ref.null`, `ref.is_null`, `ref.func`, and new typed `select`. This also adds subtype relationship support between reference types. This does not include table instructions yet. This also does not include wasm2js support. Fixes #2444 and fixes #2447.
* Add a dwarf updating test that runs -O4 which does a lot of code changes and ↵Alon Zakai2019-12-243-0/+4746
| | | | movements (#2552)
* Fix for binaryen.js getExpressionInfo on switch names (#2553)Brion Vibber2019-12-232-2/+2
| | | | | | | | | | | | Switch label names for br_table instructions were corrupted in the binaryen.js API layer, with each label cropped down to the number of characters that it is an index into the list. This was due to passing UTF8ToString as a callback method to Array.prototype.map, which passes the index as second parameter. The second parameter of UTF8ToString is the max number of bytes to copy, so the initial label came out as '', then 'l', then 'la', 'lab', etc. Corrected an existing test case that had the wrong output in it.
* Fix memory size calculation in MemoryPacking (#2548)Heejin Ahn2019-12-201-1/+4
| | | | Because `memory.size` returns the size in number of pages, we have to multiply the size with the page size when converting `memory.init`.
* DWARF debug line updating (#2545)Alon Zakai2019-12-2010-126/+6539
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this, we can update DWARF debug line info properly as we write a new binary. To do that we track binary locations as we write. Each instruction is mapped to the location it is written to. We must also adjust them as we move code around because of LEB optimization (we emit a function or a section with a 5-byte LEB placeholder, the maximal size; later we shrink it which is almost always possible). writeDWARFSections() now takes a second param, the new locations of instructions. It then maps debug line info from the original offsets in the binary to the new offsets in the binary being written. The core logic for updating the debug line section is in wasm-debug.cpp. It basically tracks state machine logic both to read the existing debug lines and to emit the new ones. I couldn't find a way to reuse LLVM code for this, but reading LLVM's code was very useful here. A final tricky thing we need to do is to update the DWARF section's internal size annotation. The LLVM YAML writing code doesn't do that for us. Luckily it's pretty easy, in fixEmittedSection we just update the first 4 bytes in place to have the section size, after we've emitted it and know the size. This ignores debug lines with a 0 in the line, col, or addr, see WebAssembly/debugging#9 (comment) This ignores debug line offsets into the middle of instructions, which LLVM sometimes emits for some reason, see WebAssembly/debugging#9 (comment) Handling that would likely at least double our memory usage, which is unfortunate - we are run in an LTO manner, where the entire app's DWARF is present, and it may be massive. I think we should see if such odd offsets are a bug in LLVM, and if we can fix or prevent that. This does not emit "special" opcodes for debug lines. Those are purely an optimization, which I wanted to leave for later. (Even without them we decrease the size quite a lot, btw, as many lines have 0s in them...) This adds some testing that shows we can load and save fib2.c and fannkuch.cpp properly. The latter includes more than one function and has nontrivial code. To actually emit correct offsets a few minor fixes are done here: * Fix the code section location tracking during reading - the correct offset we care about is the body of the code section, not including the section declaration and size. * Fix wasm-stack debug line emitting. We need to update in BinaryInstWriter::visit(), that is, right before writing bytes for the instruction. That differs from * BinaryenIRWriter::visit which is a recursive function that also calls the children - so the offset there would be of the first child. For some reason that is correct with source maps, I don't understand why, but it's wrong for DWARF... * Print code section offsets in hex, to match other tools. Remove DWARFUpdate pass, which was useful for testing temporarily, but doesn't make sense now (it just updates without writing a binary). cc @yurydelendik
* Reland "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" (#2542)Sam Clegg2019-12-205-47/+423
| | | | | | | | | | | | | | | | * Reland "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" In the previous iteration of this change we were not calling `renameFunctions` for each of the functions we removed. The problem manifested itself when we rename the imported function to `emscripten_longjmp_jmpbuf` to `emscripten_longjmp`. In this case the import of `emscripten_longjmp` already exists so we remove the import of `emscripten_longjmp_jmpbuf` but we were not correclty calling renameFunctions to handle the rename of all the uses. Add an additional test case to cover the failures that we saw on the emscripten tree.
* Binary format code section offset tracking (#2515)Alon Zakai2019-12-198-0/+771
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optionally track the binary format code section offsets, that is, when loading a binary, remember where each IR node was read from. This is necessary for DWARF debug info, as these are the offsets DWARF refers to. (Note that eventually we may want to do something else, like first read the DWARF and only then add debug info annotations into the IR in a more LLVM-like manner, but this is more straightforward and should be enough to update debug lines and ranges). This tracking adds noticeable overhead - every single IR node adds an entry in a map - so avoid it unless actually necessary. Specifically, if the user passes in -g and there are actually DWARF sections in the binary, and we are not about to remove those sections, then we need it. Print binary format code section offsets in text, when printing with -g. This will help debug and test dwarf support. It looks like ;; code offset: 0x7 as an annotation right before each node. Also add support for -g in wasm-opt tests (unlike a pass, it has just one - as a prefix). Helps #2400
* Compile Binaryen to WebAssembly (#2503)Daniel Wirtz2019-12-1919-472/+544
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR enables compiling Binaryen to WebAssembly when building binaryen.js. Since WebAssembly is best compiled and instantiated asynchronously in browsers, it also adds a new mechanism to tell if respectively when the module is ready by means of one of the following: // Using a promise const binaryen = require("binaryen"); binaryen.ready.then(() => { ... use normally ... }); // Using await const binaryen = require("binaryen"); (async () => { await binaryen.ready; ... use normally ... })(); // Where top-level await is available const binaryen = await require("binaryen").ready; ... use normally ... One can also tell if Binaryen is already ready (for example when assuming it in follow-up code) by: if (/* we already know that */ binaryen.isReady) { ... use normally ... } else { throw Error("Binaryen is supposed to be ready here but isn't"); } The JS test cases have been updated accordingly by wrapping everything in a test function and invoking it once ready. Documentation will have to be updated as well to cover this of course. New file size is about 2.5mb, even though the Wasm becomes inlined into the JS file which makes distribution across different environments a lot easier. Also makes building binaryen (to either js or wasm) emit binaryen.js, and not binaryen_js.js etc. Supersedes and thus fixes #1381 With .ready it also fixes #2452
* Revert "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" (#2541)Sam Clegg2019-12-192-47/+47
| | | This reverts commit f0a2e2c75c7bb3008f10b6edbb8dc4cfd27b7d28.
* DWARF parsing and writing support using LLVM (#2520)Alon Zakai2019-12-196-0/+378
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This imports LLVM code for DWARF handling. That code has the Apache 2 license like us. It's also the same code used to emit DWARF in the common toolchain, so it seems like a safe choice. This adds two passes: --dwarfdump which runs the same code LLVM runs for llvm-dwarfdump. This shows we can parse it ok, and will be useful for debugging. And --dwarfupdate writes out the DWARF sections (unchanged from what we read, so it just roundtrips - for updating we need #2515). This puts LLVM in thirdparty which is added here. All the LLVM code is behind USE_LLVM_DWARF, which is on by default, but off in JS for now, as it increases code size by 20%. This current approach imports the LLVM files directly. This is not how they are intended to be used, so it required a bunch of local changes - more than I expected actually, for the platform-specific stuff. For now this seems to work, so it may be good enough, but in the long term we may want to switch to linking against libllvm. A downside to doing that is that binaryen users would need to have an LLVM build, and even in the waterfall builds we'd have a problem - while we ship LLVM there anyhow, we constantly update it, which means that binaryen would need to be on latest llvm all the time too (which otherwise, given DWARF is quite stable, we might not need to constantly update). An even larger issue is that as I did this work I learned about how DWARF works in LLVM, and while the reading code is easy to reuse, the writing code is trickier. The main code path is heavily integrated with the MC layer, which we don't have - we might want to create a "fake MC layer" for that, but it sounds hard. Instead, there is the YAML path which is used mostly for testing, and which can convert DWARF to and from YAML and from binary. Using the non-YAML parts there, we can convert binary DWARF to the YAML layer's nice Info data, then convert that to binary. This works, however, this is not the path LLVM uses normally, and it supports only some basic DWARF sections - I had to add ranges support, in fact. So if we need more complex things, we may end up needing to use the MC layer approach, or consider some other DWARF library. However, hopefully that should not affect the core binaryen code which just calls a library for DWARF stuff. Helps #2400
* Fix trapping and dangling insts in memory packing (#2540)Heejin Ahn2019-12-192-7/+26
| | | | | | | | | | | This does two things: - Restore `visitDataDrop` handler deleted in #2529, but now we convert invalid `data.drop`s to not `unreachable` but `nop`. This conforms to the revised spec that `data.drop` on the active segment can be treated as a nop. - Make `visitMemoryInit` trap if offset or size are not equal to 0 or if the dest address is out of bounds. Otherwise drop all its argument. Fixes #2535.
* SIMD {i8x16,i16x8}.avgr_u instructions (#2539)Thomas Lively2019-12-1810-884/+1074
| | | As specified in https://github.com/WebAssembly/simd/pull/126.
* Correctly clear memory / table info in clearModule (#2536)Heejin Ahn2019-12-172-0/+9
| | | | | | Currently `ModuleUtils::clearModule` does not clear `exists` flags in the memory and table, and running RoundTrip pass on any module that has a memory or a table fails as a result. This creates `clear` function in `Memory` and `Table` and makes `clearModule` call them.
* Fix renaming in FixInvokeFunctionNamesWalker (#2513)Sam Clegg2019-12-172-47/+47
| | | | | | | | | | | | | This fixes https://github.com/emscripten-core/emscripten/issues/9950. The issue only shows up when debug names are not present so most of the changes in CL come from disabling debug names in the lld tests. We want to make sure that wasm-emscripten-finalize runs fine without debug names so I think it makes most sense to test in this mode. The actual bugfix is in wasm-emscripten.cpp as part of the FixInvokeFunctionNamesWalker. The problem was the name of the function rather than is import name was being added to importRenames. This means that when debug names were present (and the two names were the same) we didn't see the bug.
* Fix misc. tests (#2534)Heejin Ahn2019-12-174-14/+0
| | | | | | | - Remove a function from memory-packing_all-features.wast, because it does not test anything meaningful after #2529. - Rename a test file to use `--all-features`; it started failing I guess because `exnref` requires also reference type features, but not sure why it was OK so far.
* Implement 0-len/drop spec changes in bulk memory (#2529)Heejin Ahn2019-12-163-29/+25
| | | | | | | | | | | | | | | | | | | | | This implements recent bulk memory spec changes (WebAssembly/bulk-memory-operations#126) in Binaryen. Now `data.drop` is equivalent to shrinking a segment size to 0, and dropping already dropped segments or active segments (which are thought to be dropped in the beginning) is treated as a no-op. And all bounds checking is performed in advance, so partial copying/filling/initializing does not occur. I tried to implement `visitDataDrop` in the interpreter as `segment.data.clear();`, which is exactly what the revised spec says. I didn't end up doing that because this also deletes all contents from active segments, and there are cases we shouldn't do that: - `wasm-ctor-eval` shouldn't delete active segments, because it will store the changed contents back into segments - When `--fuzz-exec` is given to `wasm-opt`, it runs the module and compare the execution call results before and after transformations. But if running a module will nullify all active segments, applying any transformation to the module or re-running it does not make any sense.
* Allow test/passes tests to have arbitrary names, with a side file that ↵Alon Zakai2019-12-163-0/+0
| | | | | | contains the passes (#2532) We already supported this, but required that the filename be a number. This lets the name be anything, and we check if *.passes exists for it.
* Remove redundant instructions in Flatten (#2524)Heejin Ahn2019-12-1216-4768/+3020
| | | | | | | When the expression type is none, it does not seem to be necessary to make it a prelude and insert a nop. This also results in unnecessary blocks that contains an expression with a nop, which can be reduced to just the expression. This also adds some newlines to improve readability.
* Support stack overflow checks in standalone mode (#2525)Alon Zakai2019-12-122-0/+343
| | | | | | | | | In normal mode we call a JS import, but we can't import from JS in standalone mode. Instead, just trap in that case with an unreachable. (The error reporting is not as good in this case, but at least it catches all errors and halts, and the emitted wasm is valid for standalone mode.) Helps emscripten-core/emscripten#10019
* Make local.tee's type its local's type (#2511)Heejin Ahn2019-12-125-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to the current spec, `local.tee`'s return type should be the same as its local's type. (Discussions on whether we should change this rule is going on in WebAssembly/reference-types#55, but here I will assume this spec does not change. If this changes, we should change many parts of Binaryen transformation anyway...) But currently in Binaryen `local.tee`'s type is computed from its value's type. This didn't make any difference in the MVP, but after we have subtype relationship in #2451, this can become a problem. For example: ``` (func $test (result funcref) (local $0 anyref) (local.tee $0 (ref.func $test) ) ) ``` This shouldn't validate in the spec, but this will pass Binaryen validation with the current `local.tee` implementation. This makes `local.tee`'s type computed from the local's type, and makes `LocalSet::makeTee` get a type parameter, to which we should pass the its corresponding local's type. We don't embed the local type in the class `LocalSet` because it may increase memory size. This also fixes the type of `local.get` to be the local type where `local.get` and `local.set` pair is created from `local.tee`.