From ad752d66a7b8f4ca6746314119b0f11786c6092f Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 2 Dec 2019 15:45:12 -0800 Subject: [PATCH 1/2] When modifying the value, also update its ExtraInfo. Fixes a debug_assert! on python3.7 and rustpython in wapm. --- lib/llvm-backend/src/code.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 7f7e1e32f6b..c0f6e07dd63 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -1730,15 +1730,17 @@ impl<'ctx> FunctionCodeGenerator for LLVMFunctionCodeGenerator<'ct // If the pending bits of v1 and v2 are the same, we can pass // them along to the result. Otherwise, apply pending // canonicalizations now. - let (v1, v2) = if i1.has_pending_f32_nan() != i2.has_pending_f32_nan() + let (v1, i1, v2, i2) = if i1.has_pending_f32_nan() != i2.has_pending_f32_nan() || i1.has_pending_f64_nan() != i2.has_pending_f64_nan() { ( apply_pending_canonicalization(builder, intrinsics, v1, i1), + i1.strip_pending(), apply_pending_canonicalization(builder, intrinsics, v2, i2), + i2.strip_pending(), ) } else { - (v1, v2) + (v1, i1, v2, i2) }; let cond_value = builder.build_int_compare( IntPredicate::NE, From 7c6d73d4d9ec64d6675772615e37ae0a841a0576 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 2 Dec 2019 15:49:33 -0800 Subject: [PATCH 2/2] Add test for debug-crash. This also was a wrong-code bug (I think), but we can't yet write tests for those. --- lib/llvm-backend-tests/tests/compile.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/llvm-backend-tests/tests/compile.rs b/lib/llvm-backend-tests/tests/compile.rs index edb59c4692f..17071a44a04 100644 --- a/lib/llvm-backend-tests/tests/compile.rs +++ b/lib/llvm-backend-tests/tests/compile.rs @@ -18,5 +18,23 @@ fn crash_return_with_float_on_stack() { "#; let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed"); let module = compile_with(&wasm_binary, &get_compiler()).unwrap(); - let instance = module.instantiate(&imports! {}).unwrap(); + module.instantiate(&imports! {}).unwrap(); +} + +#[test] +fn crash_select_with_mismatched_pending() { + const MODULE: &str = r#" + (module + (func (param f64) + f64.const 0x0p+0 (;=0;) + local.get 0 + f64.add + f64.const 0x0p+0 (;=0;) + i32.const 0 + select + drop)) +"#; + let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed"); + let module = compile_with(&wasm_binary, &get_compiler()).unwrap(); + module.instantiate(&imports! {}).unwrap(); }