Repository: bytecodealliance/wasmtime
Pull request #7519 (2023-11-09 21:05:48)

Downgrade log level on pcc error
Currently `cargo run test filetests` in the `cranelift` directory prints a bunch of `ERROR:` logs for the pcc tests which I'm assuming is expected as they're testing failures. This commit turns down the log level to `info!` so it's suppressed by default in this situation.

<!--
Please make sure you include the following information:

- If this work has been discussed elsewhere, please include a link to that
  conversation. If it was discussed in an issue, just mention "issue #...".

- Explain why this change is needed. If the details are in an issue already,
  this can be brief.

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->



Patch:
diff --git a/cranelift/codegen/src/ir/pcc.rs b/cranelift/codegen/src/ir/pcc.rs
index 4f3dc4d13..33a515cac 100644
--- a/cranelift/codegen/src/ir/pcc.rs
+++ b/cranelift/codegen/src/ir/pcc.rs
@@ -1655,7 +1655,7 @@ pub fn check_vcode_facts<B: LowerBackend + TargetIsa>(
         for inst in vcode.block_insns(block).iter() {
             // Check any output facts on this inst.
             if let Err(e) = backend.check_fact(&ctx, vcode, inst, &mut flow_state) {
-                log::error!("Error checking instruction: {:?}", vcode[inst]);
+                log::info!("Error checking instruction: {:?}", vcode[inst]);
                 return Err(e);
             }
 
diff --git a/crates/wasi-http/wit/main.wit b/crates/wasi-http/wit/main.wit
deleted file mode 100644
index 90aa28ad3..000000000
--- a/crates/wasi-http/wit/main.wit
+++ /dev/null
@@ -1,33 +0,0 @@
-package wasmtime:wasi;
-
-// All of the same imports available in the wasi:cli/command world, but no
-// export required:
-world preview1-adapter-reactor {
-  import wasi:clocks/wall-clock@0.2.0-rc-2023-11-05;
-  import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-05;
-  import wasi:clocks/timezone@0.2.0-rc-2023-11-05;
-  import wasi:filesystem/types@0.2.0-rc-2023-11-05;
-  import wasi:filesystem/preopens@0.2.0-rc-2023-11-05;
-  import wasi:sockets/instance-network@0.2.0-rc-2023-11-05;
-  import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-05;
-  import wasi:sockets/network@0.2.0-rc-2023-11-05;
-  import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-05;
-  import wasi:sockets/tcp@0.2.0-rc-2023-11-05;
-  import wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-05;
-  import wasi:sockets/udp@0.2.0-rc-2023-11-05;
-  import wasi:random/random@0.2.0-rc-2023-11-05;
-  import wasi:random/insecure@0.2.0-rc-2023-11-05;
-  import wasi:random/insecure-seed@0.2.0-rc-2023-11-05;
-  import wasi:io/poll@0.2.0-rc-2023-11-05;
-  import wasi:io/streams@0.2.0-rc-2023-11-05;
-  import wasi:cli/environment@0.2.0-rc-2023-11-05;
-  import wasi:cli/exit@0.2.0-rc-2023-11-05;
-  import wasi:cli/stdin@0.2.0-rc-2023-11-05;
-  import wasi:cli/stdout@0.2.0-rc-2023-11-05;
-  import wasi:cli/stderr@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-input@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-output@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stdin@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stdout@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stderr@0.2.0-rc-2023-11-05;
-}
diff --git a/crates/wasi-preview1-component-adapter/src/lib.rs b/crates/wasi-preview1-component-adapter/src/lib.rs
index ef42ac10c..3e2176516 100644
--- a/crates/wasi-preview1-component-adapter/src/lib.rs
+++ b/crates/wasi-preview1-component-adapter/src/lib.rs
@@ -45,7 +45,7 @@ pub mod bindings {
     #[cfg(feature = "reactor")]
     wit_bindgen::generate!({
         path: "../wasi/wit",
-        world: "wasmtime:wasi/preview1-adapter-reactor",
+        world: "wasi:cli/reactor",
         std_feature,
         raw_strings,
         // Automatically generated bindings for these functions will allocate
diff --git a/crates/wasi/wit/main.wit b/crates/wasi/wit/main.wit
deleted file mode 100644
index 90aa28ad3..000000000
--- a/crates/wasi/wit/main.wit
+++ /dev/null
@@ -1,33 +0,0 @@
-package wasmtime:wasi;
-
-// All of the same imports available in the wasi:cli/command world, but no
-// export required:
-world preview1-adapter-reactor {
-  import wasi:clocks/wall-clock@0.2.0-rc-2023-11-05;
-  import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-05;
-  import wasi:clocks/timezone@0.2.0-rc-2023-11-05;
-  import wasi:filesystem/types@0.2.0-rc-2023-11-05;
-  import wasi:filesystem/preopens@0.2.0-rc-2023-11-05;
-  import wasi:sockets/instance-network@0.2.0-rc-2023-11-05;
-  import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-05;
-  import wasi:sockets/network@0.2.0-rc-2023-11-05;
-  import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-05;
-  import wasi:sockets/tcp@0.2.0-rc-2023-11-05;
-  import wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-05;
-  import wasi:sockets/udp@0.2.0-rc-2023-11-05;
-  import wasi:random/random@0.2.0-rc-2023-11-05;
-  import wasi:random/insecure@0.2.0-rc-2023-11-05;
-  import wasi:random/insecure-seed@0.2.0-rc-2023-11-05;
-  import wasi:io/poll@0.2.0-rc-2023-11-05;
-  import wasi:io/streams@0.2.0-rc-2023-11-05;
-  import wasi:cli/environment@0.2.0-rc-2023-11-05;
-  import wasi:cli/exit@0.2.0-rc-2023-11-05;
-  import wasi:cli/stdin@0.2.0-rc-2023-11-05;
-  import wasi:cli/stdout@0.2.0-rc-2023-11-05;
-  import wasi:cli/stderr@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-input@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-output@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stdin@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stdout@0.2.0-rc-2023-11-05;
-  import wasi:cli/terminal-stderr@0.2.0-rc-2023-11-05;
-}
diff --git a/winch/codegen/src/codegen/mod.rs b/winch/codegen/src/codegen/mod.rs
index bb1a8fead..b9120eb34 100644
--- a/winch/codegen/src/codegen/mod.rs
+++ b/winch/codegen/src/codegen/mod.rs
@@ -345,12 +345,15 @@ where
     }
 
     /// Pops the value at the stack top and assigns it to the local at
-    ///
     /// the given index, returning the typed register holding the
     /// source value.
-    pub fn emit_set_local(&mut self, addr: M::Address, size: OperandSize) -> TypedReg {
+    pub fn emit_set_local(&mut self, index: u32) -> TypedReg {
         let src = self.context.pop_to_reg(self.masm, None);
-        self.masm.store(RegImm::reg(src.reg), addr, size);
+        // Need to get address of local after `pop_to_reg` since `pop_to_reg`
+        // will pop the machine stack causing an incorrect address to be
+        // calculated.
+        let (ty, addr) = self.context.frame.get_local_address(index, self.masm);
+        self.masm.store(RegImm::reg(src.reg), addr, ty.into());
 
         src
     }
diff --git a/winch/codegen/src/visitor.rs b/winch/codegen/src/visitor.rs
index d46104f2c..a69992ac1 100644
--- a/winch/codegen/src/visitor.rs
+++ b/winch/codegen/src/visitor.rs
@@ -914,8 +914,7 @@ where
 
     // TODO: verify the case where the target local is on the stack.
     fn visit_local_set(&mut self, index: u32) {
-        let (ty, slot) = self.context.frame.get_local_address(index, self.masm);
-        let src = self.emit_set_local(slot, ty.into());
+        let src = self.emit_set_local(index);
         self.context.free_reg(src);
     }
 
@@ -1247,8 +1246,7 @@ where
     }
 
     fn visit_local_tee(&mut self, index: u32) {
-        let (ty, slot) = self.context.frame.get_local_address(index, self.masm);
-        let typed_reg = self.emit_set_local(slot, ty.into());
+        let typed_reg = self.emit_set_local(index);
         self.context.stack.push(typed_reg.into());
     }
 


Test patch:
diff --git a/crates/wasi-http/wit/test.wit b/crates/wasi-http/wit/test.wit
index 5e7557ed6..fc31f6ef3 100644
--- a/crates/wasi-http/wit/test.wit
+++ b/crates/wasi-http/wit/test.wit
@@ -1,3 +1,5 @@
+package wasmtime:wasi;
+
 // only used as part of `test-programs`
 world test-reactor {
   include wasi:cli/reactor@0.2.0-rc-2023-11-05;
diff --git a/crates/wasi/wit/test.wit b/crates/wasi/wit/test.wit
index 5e7557ed6..fc31f6ef3 100644
--- a/crates/wasi/wit/test.wit
+++ b/crates/wasi/wit/test.wit
@@ -1,3 +1,5 @@
+package wasmtime:wasi;
+
 // only used as part of `test-programs`
 world test-reactor {
   include wasi:cli/reactor@0.2.0-rc-2023-11-05;
diff --git a/winch/filetests/filetests/x64/block/get_and_set.wat b/winch/filetests/filetests/x64/block/get_and_set.wat
new file mode 100644
index 000000000..3b944e74a
--- /dev/null
+++ b/winch/filetests/filetests/x64/block/get_and_set.wat
@@ -0,0 +1,22 @@
+;;! target = "x86_64"
+
+(module
+  (func (export "") (param i32)
+    local.get 0
+    block
+    end
+    local.set 0
+  )
+)
+;;    0:	 55                   	push	rbp
+;;    1:	 4889e5               	mov	rbp, rsp
+;;    4:	 4883ec10             	sub	rsp, 0x10
+;;    8:	 897c240c             	mov	dword ptr [rsp + 0xc], edi
+;;    c:	 4c89742404           	mov	qword ptr [rsp + 4], r14
+;;   11:	 448b5c240c           	mov	r11d, dword ptr [rsp + 0xc]
+;;   16:	 4153                 	push	r11
+;;   18:	 58                   	pop	rax
+;;   19:	 8944240c             	mov	dword ptr [rsp + 0xc], eax
+;;   1d:	 4883c410             	add	rsp, 0x10
+;;   21:	 5d                   	pop	rbp
+;;   22:	 c3                   	ret	
diff --git a/winch/filetests/filetests/x64/block/get_and_tee.wat b/winch/filetests/filetests/x64/block/get_and_tee.wat
new file mode 100644
index 000000000..1fb77d09a
--- /dev/null
+++ b/winch/filetests/filetests/x64/block/get_and_tee.wat
@@ -0,0 +1,22 @@
+;;! target = "x86_64"
+
+(module
+  (func (export "") (param i32) (result i32)
+    local.get 0
+    block
+    end
+    local.tee 0
+  )
+)
+;;    0:	 55                   	push	rbp
+;;    1:	 4889e5               	mov	rbp, rsp
+;;    4:	 4883ec10             	sub	rsp, 0x10
+;;    8:	 897c240c             	mov	dword ptr [rsp + 0xc], edi
+;;    c:	 4c89742404           	mov	qword ptr [rsp + 4], r14
+;;   11:	 448b5c240c           	mov	r11d, dword ptr [rsp + 0xc]
+;;   16:	 4153                 	push	r11
+;;   18:	 58                   	pop	rax
+;;   19:	 8944240c             	mov	dword ptr [rsp + 0xc], eax
+;;   1d:	 4883c410             	add	rsp, 0x10
+;;   21:	 5d                   	pop	rbp
+;;   22:	 c3                   	ret