From da4cde8117aa1c5d2d6bf5c777c114e609ed0658 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Mon, 18 Sep 2017 11:53:32 -0700 Subject: [PATCH] Always insert the entry EBB before translating any WASM. The FuncEnvironment callbacks (make_global in particular) may need to insert code in the entry EBB. We need to make sure the entry EBB has been inserted in the layout before making those callbacks. --- lib/frontend/src/frontend.rs | 2 +- lib/wasm/src/func_translator.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/frontend/src/frontend.rs b/lib/frontend/src/frontend.rs index 29a4f3f644..86a91ae977 100644 --- a/lib/frontend/src/frontend.rs +++ b/lib/frontend/src/frontend.rs @@ -373,7 +373,7 @@ where } /// Make sure that the current EBB is inserted in the layout. - fn ensure_inserted_ebb(&mut self) { + pub fn ensure_inserted_ebb(&mut self) { let ebb = self.position.ebb; if self.builder.ebbs[ebb].pristine { if !self.func.layout.is_ebb_inserted(ebb) { diff --git a/lib/wasm/src/func_translator.rs b/lib/wasm/src/func_translator.rs index c38c420bbb..9a43083461 100644 --- a/lib/wasm/src/func_translator.rs +++ b/lib/wasm/src/func_translator.rs @@ -84,6 +84,10 @@ impl FuncTranslator { let entry_block = builder.create_ebb(); builder.switch_to_block(entry_block, &[]); // This also creates values for the arguments. builder.seal_block(entry_block); + // Make sure the entry block is inserted in the layout before we make any callbacks to + // `environ`. The callback functions may need to insert things in the entry block. + builder.ensure_inserted_ebb(); + let num_args = declare_wasm_arguments(builder); // Set up the translation state with a single pushed control block representing the whole