Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift-wasm: Fix reachability tracking for `if .. else .. end` #1143

Merged
merged 1 commit into from Oct 15, 2019

Conversation

@fitzgen
Copy link
Member

fitzgen commented Oct 14, 2019

We weren't previously keeping track of quite the right information for whether an if .. else .. end's following block was reachable or not. It should be reachable if the head is reachable and either the consequent or alternative end reachable (and therefore fall through to the following block) or do an early br_if to it.

This commit rejiggers ControlStackFrame::If to keep track of reachability at the end of the consequent (we don't need to keep track of it at the end of the alternative, since that is simply state.reachable) and adds Wasm tests for every reachability situation we can encounter with if .. else .. end.

Fixes #1132

We weren't previously keeping track of quite the right information for whether
an `if .. else .. end`'s following block was reachable or not. It should be
reachable if the head is reachable and either the consequent or alternative end
reachable (and therefore fall through to the following block) or do an early
`br_if` to it.

This commit rejiggers `ControlStackFrame::If` to keep track of reachability at
the end of the consequent (we don't need to keep track of it at the end of the
alternative, since that is simply `state.reachable`) and adds Wasm tests for
every reachability situation we can encounter with `if .. else .. end`.

Fixes #1132
@fitzgen fitzgen requested a review from bnjbvr Oct 14, 2019
@fitzgen

This comment was marked as resolved.

Copy link
Member Author

fitzgen commented Oct 14, 2019

CI failure looks like it is just a flaky CI thing, but I also don't have the ability to retry the job.

@abrown

This comment was marked as resolved.

Copy link
Collaborator

abrown commented Oct 14, 2019

I bumped it... let's see what happens.

@fitzgen

This comment was marked as resolved.

Copy link
Member Author

fitzgen commented Oct 14, 2019

Thanks!

@fitzgen

This comment was marked as resolved.

Copy link
Member Author

fitzgen commented Oct 14, 2019

Hmm still failing with the same linker error:

   Compiling clif-wasm-fuzz v0.0.1 (/Users/vsts/agent/2.158.0/work/1/s/fuzz)
     Running `rustc --edition=2018 --crate-name fuzz_translate_module fuzz_translate_module.rs --color never --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=2b3b22e0c65bf56b -C extra-filename=-2b3b22e0c65bf56b --out-dir /Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps --target x86_64-apple-darwin -C incremental=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/incremental -L dependency=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps -L dependency=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/debug/deps --extern binaryen=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libbinaryen-3bdc218f525f4683.rlib --extern cranelift_codegen=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_codegen-235ea5a714d1de8f.rlib --extern cranelift_reader=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_reader-e3be78048b5296f5.rlib --extern cranelift_wasm=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_wasm-15c7a81ea4224a09.rlib --extern libfuzzer_sys=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/liblibfuzzer_sys-edf81580efe8fb6c.rlib --extern target_lexicon=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libtarget_lexicon-0c1b1b1589fe271f.rlib --cfg fuzzing -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=4 -Cllvm-args=-sanitizer-coverage-trace-compares -Cllvm-args=-sanitizer-coverage-trace-divs -Cllvm-args=-sanitizer-coverage-trace-geps -Cllvm-args=-sanitizer-coverage-prune-blocks=0 -Zsanitizer=address -Cpanic=abort -L native=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/binaryen-sys-2baa14fa185055c1/out/build/lib -L native=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/binaryen-sys-2baa14fa185055c1/out -L native=/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/libfuzzer-sys-37d52cae8feba0a6/out`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.13nuekoqiuqo7e7y.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.1820ry8e4qchtrih.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.1lq5rkgnccnayhw3.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.28fn01r9zlykil0b.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.2bo5y4d9tbek4ivs.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.2cyyoty0iz0v9udt.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.2p0naxnthcjsfijm.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.39za3pabdhgjcnwo.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3ivraxh2hy3ejmxe.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3kf57mbvif9kardk.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3mgyefrlmswwhigw.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3niexchysvpy92qc.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3yc9r7in0pcydvv9.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.3yhzxui0c12zjkmf.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.4f2159t56pnemqti.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.4fu9md4zrkbrubw2.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.4wiu9icycx840gf.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.50wcd2w5ebcj1i8u.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.57epcpvrcq03yukx.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.5864gfwtrohe4nh2.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.59i1a63tm9kgz96r.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.5cgqbanizy01tb24.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.5ggo1wx8qvkeug0e.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.ha31it174553nbv.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.lqiyn5a22byya0q.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.nmtn1l4gkkwmm5w.rcgu.o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.s3b74t40btwpjvv.rcgu.o" "-o" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/fuzz_translate_module-2b3b22e0c65bf56b.4yf0ckxl9j416c9b.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps" "-L" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/debug/deps" "-L" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/binaryen-sys-2baa14fa185055c1/out/build/lib" "-L" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/binaryen-sys-2baa14fa185055c1/out" "-L" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/build/libfuzzer-sys-37d52cae8feba0a6/out" "-L" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-Wl,-rpath" "-Xlinker" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-Wl,-force_load" "-Wl,/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/rustcmqzrVd/librustc_asan-bc7e8e8f5bb0d427.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_wasm-15c7a81ea4224a09.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libwasmparser-e66d15d91ae75d30.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_frontend-8f8cb89d325342b5.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_codegen-235ea5a714d1de8f.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libsmallvec-3bec0dc6812eb8ca.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libtarget_lexicon-0c1b1b1589fe271f.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libfailure-2580a54126d22a28.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_codegen_shared-1f0f995586e3f263.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/liblog-627183980b36bb06.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcfg_if-dbeb87a460d4b36d.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_bforest-c5cc5bf8a5bc5f60.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libcranelift_entity-65d523818aac743c.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libbinaryen-3bdc218f525f4683.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/libbinaryen_sys-c78b5012e08ca98a.rlib" "/Users/vsts/agent/2.158.0/work/1/s/fuzz/target/x86_64-apple-darwin/debug/deps/liblibfuzzer_sys-edf81580efe8fb6c.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-cab47fec5d55161d.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_abort-fe5aae1d29094d6a.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-bf6dcbc7a32bdeed.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-508508a6728c609f.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace-2b127b3a6b0a74b0.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace_sys-cae9d608d9c44d98.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-03d92ba09e009ca9.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-45ee9cd7354eae7d.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-02ec246fcbb38efa.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-9b4e843eaad0911b.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-d7f0fafbf449014c.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-412422824c47d151.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-ff1d6301f4e32861.rlib" "/Users/vsts/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-fcec5e859e39fecf.rlib" "-l__rustc__clang_rt.asan_osx_dynamic" "-lc++" "-lc++" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: ld: library not found for -l__rustc__clang_rt.asan_osx_dynamic
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I can't imagine what in this PR would mess with the asan/CI setup...

@bnjbvr

This comment has been minimized.

Copy link
Member

bnjbvr commented Oct 15, 2019

Thanks, I confirm this fixes all the pending wasm tests to add, as well as all the Spidermonkey tests that were passing before. I can review it, but @sunfishcode probably has a better preexisting understanding of this code, since he's reviewed the first batch of changes.

@fitzgen fitzgen requested review from sunfishcode and removed request for bnjbvr Oct 15, 2019
@sunfishcode sunfishcode merged commit a1f2a15 into bytecodealliance:master Oct 15, 2019
13 checks passed
13 checks passed
CraneStation.cranelift Build #refs_pull_1143_merge-2019-10-14.1 succeeded
Details
CraneStation.cranelift (Build mac) Build mac succeeded
Details
CraneStation.cranelift (Build windows) Build windows succeeded
Details
CraneStation.cranelift (Build_linux) Build_linux succeeded
Details
CraneStation.cranelift (Fuzz regression) Fuzz regression succeeded
Details
CraneStation.cranelift (Test linux-earliest) Test linux-earliest succeeded
Details
CraneStation.cranelift (Test mac-beta) Test mac-beta succeeded
Details
CraneStation.cranelift (Test mac-earliest) Test mac-earliest succeeded
Details
CraneStation.cranelift (Test mac-nightly) Test mac-nightly succeeded
Details
CraneStation.cranelift (Test mac-stable) Test mac-stable succeeded
Details
CraneStation.cranelift (Test windows-earliest) Test windows-earliest succeeded
Details
CraneStation.cranelift (docs) docs succeeded
Details
CraneStation.cranelift (rustfmt) rustfmt succeeded
Details
@fitzgen fitzgen deleted the fitzgen:if-else-reachability branch Oct 15, 2019
@fitzgen

This comment has been minimized.

Copy link
Member Author

fitzgen commented Oct 15, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.