Skip to content

Commit 3918b47

Browse files
committed
Workaround UB in cranelift-jit
1 parent 35b4318 commit 3918b47

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/constant.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
372372
}
373373

374374
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
375-
data.define(bytes.into_boxed_slice());
375+
if bytes.is_empty() {
376+
// FIXME(bytecodealliance/wasmtime#7918) cranelift-jit has a bug where it causes UB on
377+
// empty data objects
378+
data.define(Box::new([0]));
379+
} else {
380+
data.define(bytes.into_boxed_slice());
381+
}
376382

377383
for &(offset, prov) in alloc.provenance().ptrs().iter() {
378384
let alloc_id = prov.alloc_id();

0 commit comments

Comments
 (0)