wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

wasm-smith: add a "no trapping" mode

Open fitzgen opened this issue 4 years ago • 0 comments

I think we could do this with a post-processing pass, similar to what we do with ensure_termination.

We'd walk over each instruction and potentially insert some code right before it:

  • We would insert a couple instructions to ensure that a division instruction's denominator is never zero
  • We would insert a couple instructions to mask heap addresses to ensure they are within the memory's minimum size
  • Similar for table.get and table.set
  • Similar for trapping floating point conversion instructions
  • Every unreachable would be replaced with code to create dummy result values (ie zeroes) and then br out of the current control frame

We would also have to make sure that active data/elem segments were always in bounds of their memories/tables.

I think that's everything? I might be missing some trapping cases, but I think the approach would work for everything.

cc @alexcrichton

fitzgen avatar Apr 22 '21 18:04 fitzgen