Skip to content

Commit 7fdf8ca

Browse files
committed
Fix bitcasts between i32 and pointer.
1 parent d2327ab commit 7fdf8ca

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/core/src/abi.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ pub enum Bitcast {
541541
I64ToP64,
542542
P64ToP,
543543
PToP64,
544+
I32ToP,
545+
PToI32,
544546

545547
None,
546548
}
@@ -1901,13 +1903,16 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
19011903
(Pointer, PointerOrI64) => Bitcast::PToP64,
19021904
(PointerOrI64, Pointer) => Bitcast::P64ToP,
19031905

1906+
(I32, Pointer) => Bitcast::I32ToP,
1907+
(Pointer, I32) => Bitcast::PToI32,
1908+
19041909
(Pointer | PointerOrI64 | Length, _)
19051910
| (_, Pointer | PointerOrI64 | Length)
19061911
| (F32, F64)
19071912
| (F64, F32)
19081913
| (F64, I32)
19091914
| (I32, F64) => {
1910-
unreachable!()
1915+
unreachable!("Don't know how to bitcast from {:?} to {:?}", from, to);
19111916
}
19121917
}
19131918
}

crates/rust/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,14 @@ fn bitcast(casts: &[Bitcast], operands: &[String], results: &mut Vec<String>) {
13071307
operand
13081308
)
13091309
}
1310+
// Convert an `i32` into a pointer.
1311+
Bitcast::I32ToP => {
1312+
format!("{} as *mut ::core::ffi::c_void", operand)
1313+
}
1314+
// Convert a pointer holding an `i32` value back into the `i32`.
1315+
Bitcast::PToI32 => {
1316+
format!("{} as i32", operand)
1317+
}
13101318
});
13111319
}
13121320
}

0 commit comments

Comments
 (0)