Skip to content

Commit fcf4e0e

Browse files
authored
miri: Fix a new code pattern with stacked borrows (bytecodealliance#11019)
Joel and I went down a deep rabbit hole today trying to figure out what's going on with a new code pattern which was being flagged as violating stacked borrows. At the end of the day I'm honestly not 100% sure what this doing or how to explain all the behavior we were seeing, but this seems to be basically equivalent and we're otherwise able to get a bit further so I figured I'd commit this. Along the way I updated the preexisting `table-intrinsics` test to correctly use the table it was supposed to be using instead of using the previous table by accident.
1 parent a8e0d07 commit fcf4e0e

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

crates/wasmtime/src/runtime/vm/table.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -957,25 +957,19 @@ impl Table {
957957
},
958958
Table::Dynamic(DynamicTable::Func(DynamicFuncTable { elements, .. })) => {
959959
VMTableDefinition {
960-
base: NonNull::<[FuncTableElem]>::from(&mut elements[..])
961-
.cast()
962-
.into(),
960+
base: NonNull::new(elements.as_mut_ptr()).unwrap().cast().into(),
963961
current_elements: elements.len(),
964962
}
965963
}
966964
Table::Dynamic(DynamicTable::GcRef(DynamicGcRefTable { elements, .. })) => {
967965
VMTableDefinition {
968-
base: NonNull::<[Option<VMGcRef>]>::from(&mut elements[..])
969-
.cast()
970-
.into(),
966+
base: NonNull::new(elements.as_mut_ptr()).unwrap().cast().into(),
971967
current_elements: elements.len(),
972968
}
973969
}
974970
Table::Dynamic(DynamicTable::Cont(DynamicContTable { elements, .. })) => {
975971
VMTableDefinition {
976-
base: NonNull::<[Option<VMContObj>]>::from(&mut elements[..])
977-
.cast()
978-
.into(),
972+
base: NonNull::new(elements.as_mut_ptr()).unwrap().cast().into(),
979973
current_elements: elements.len(),
980974
}
981975
}

tests/all/pulley.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ fn pulley_provenance_test() -> Result<()> {
177177
instance
178178
.get_typed_func::<(), ()>(&mut store, "table-intrinsics")?
179179
.call(&mut store, ())?;
180+
instance
181+
.get_typed_func::<(), ()>(&mut store, "table-intrinsics2")?
182+
.call(&mut store, ())?;
180183

181184
let funcref = Func::wrap(&mut store, move |mut caller: Caller<'_, ()>| {
182185
let func = instance.get_typed_func::<(), (i32, i32, i32)>(&mut caller, "call-wasm")?;

tests/all/pulley_provenance_test.wat

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,27 @@
6767
)
6868
(data $d "abcd")
6969

70-
(table 1 funcref)
70+
(table $t 1 funcref)
7171
(func (export "table-intrinsics")
72-
(drop (table.get (i32.const 0)))
73-
(table.set (i32.const 0) (table.get (i32.const 0)))
72+
(drop (table.get $t (i32.const 0)))
73+
(table.set $t (i32.const 0) (table.get $t (i32.const 0)))
7474

75-
(drop (table.grow (ref.null func) (i32.const 100)))
75+
(drop (table.grow $t (ref.null func) (i32.const 100)))
7676

77-
(drop (table.get (i32.const 1)))
78-
(table.set (i32.const 1) (table.get (i32.const 1)))
77+
(drop (table.get $t (i32.const 1)))
78+
(table.set $t (i32.const 1) (table.get $t (i32.const 1)))
7979

80-
(table.copy (i32.const 0) (i32.const 1) (i32.const 10))
81-
(table.init $e (i32.const 0) (i32.const 1) (i32.const 3))
82-
(table.fill (i32.const 0) (ref.func $empty) (i32.const 10))
80+
(table.copy $t $t (i32.const 0) (i32.const 1) (i32.const 10))
81+
(table.init $t $e (i32.const 0) (i32.const 1) (i32.const 3))
82+
(table.fill $t (i32.const 0) (ref.func $empty) (i32.const 10))
8383
)
8484
(elem $e func $empty $empty $empty $empty)
8585
(func $empty)
86+
87+
(table $t2 2 funcref)
88+
(elem (table $t2) (i32.const 0) func $empty)
89+
(func (export "table-intrinsics2")
90+
(drop (table.get $t2 (i32.const 1)))
91+
(drop (table.get $t2 (i32.const 0)))
92+
)
8693
)

0 commit comments

Comments
 (0)