about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-02-15 10:23:58 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-02-15 10:23:58 +0000
commit3918b4783d4290b5d64e5c69c30ebaee87f2b125 (patch)
tree3a7b4d3fdd32ac525f5ff6967f8387a2379bdba4 /src
parent35b431884f3ef4d77c9e9ee1ff8a8e2cf36a67c1 (diff)
downloadrust-3918b4783d4290b5d64e5c69c30ebaee87f2b125.tar.gz
rust-3918b4783d4290b5d64e5c69c30ebaee87f2b125.zip
Workaround UB in cranelift-jit
Diffstat (limited to 'src')
-rw-r--r--src/constant.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/constant.rs b/src/constant.rs
index b6de688130c..18c5960ffc6 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -372,7 +372,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
         }
 
         let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
-        data.define(bytes.into_boxed_slice());
+        if bytes.is_empty() {
+            // FIXME(bytecodealliance/wasmtime#7918) cranelift-jit has a bug where it causes UB on
+            // empty data objects
+            data.define(Box::new([0]));
+        } else {
+            data.define(bytes.into_boxed_slice());
+        }
 
         for &(offset, prov) in alloc.provenance().ptrs().iter() {
             let alloc_id = prov.alloc_id();