Skip to content

Commit 1cb81d2

Browse files
committed
work around the wasm32-unknown-unknown ABI being broken
1 parent c637bda commit 1cb81d2

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,14 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Str
308308
other => bug!("wasm pointer size cannot be {other} bits"),
309309
};
310310

311-
let hidden_return =
312-
matches!(fn_abi.ret.mode, PassMode::Indirect { .. } | PassMode::Pair { .. });
311+
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
312+
if let PassMode::Pair { .. } = fn_abi.ret.mode {
313+
bug!(
314+
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
315+
);
316+
}
317+
318+
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
313319

314320
signature.push('(');
315321

@@ -346,6 +352,12 @@ fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_t
346352
let direct_type = match arg_abi.layout.backend_repr {
347353
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
348354
BackendRepr::Vector { .. } => "v128",
355+
BackendRepr::Memory { .. } => {
356+
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
357+
bug!(
358+
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
359+
);
360+
}
349361
other => unreachable!("unexpected BackendRepr: {:?}", other),
350362
};
351363

tests/assembly/wasm32-naked-fn.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//@ revisions: wasm32-unknown wasm64-unknown wasm32-wasip1
1+
// FIXME: add wasm32-unknown when the wasm32-unknown-unknown ABI is fixed
2+
// see https://github.com/rust-lang/rust/issues/115666
3+
//@ revisions: wasm64-unknown wasm32-wasip1
24
//@ add-core-stubs
35
//@ assembly-output: emit-asm
4-
//@ [wasm32-unknown] compile-flags: --target wasm32-unknown-unknown
56
//@ [wasm64-unknown] compile-flags: --target wasm64-unknown-unknown
67
//@ [wasm32-wasip1] compile-flags: --target wasm32-wasip1
7-
//@ [wasm32-unknown] needs-llvm-components: webassembly
88
//@ [wasm64-unknown] needs-llvm-components: webassembly
99
//@ [wasm32-wasip1] needs-llvm-components: webassembly
1010

@@ -98,7 +98,7 @@ unsafe extern "C" fn fn_i64_i64(num: i64) -> i64 {
9898
}
9999

100100
// CHECK-LABEL: fn_i128_i128:
101-
// wasm32-unknown,wasm32-wasip1: .functype fn_i128_i128 (i32, i64, i64) -> ()
101+
// wasm32-wasip1: .functype fn_i128_i128 (i32, i64, i64) -> ()
102102
// wasm64-unknown: .functype fn_i128_i128 (i64, i64, i64) -> ()
103103
#[allow(improper_ctypes_definitions)]
104104
#[no_mangle]
@@ -115,7 +115,7 @@ unsafe extern "C" fn fn_i128_i128(num: i128) -> i128 {
115115
}
116116

117117
// CHECK-LABEL: fn_f128_f128:
118-
// wasm32-unknown,wasm32-wasip1: .functype fn_f128_f128 (i32, i64, i64) -> ()
118+
// wasm32-wasip1: .functype fn_f128_f128 (i32, i64, i64) -> ()
119119
// wasm64-unknown: .functype fn_f128_f128 (i64, i64, i64) -> ()
120120
#[no_mangle]
121121
#[naked]
@@ -138,18 +138,19 @@ struct Compound {
138138

139139
// CHECK-LABEL: fn_compound_compound:
140140
// wasm32-wasip1: .functype fn_compound_compound (i32, i32) -> ()
141-
// wasm32-unknown: .functype fn_compound_compound (i32, i32, i64) -> ()
142141
// wasm64-unknown: .functype fn_compound_compound (i64, i64) -> ()
143142
#[no_mangle]
144143
#[naked]
145144
unsafe extern "C" fn fn_compound_compound(_: Compound) -> Compound {
146-
// this is the wasm32-unknown-unknown assembly
145+
// this is the wasm32-wasip1 assembly
147146
naked_asm!(
148147
"local.get 0",
149-
"local.get 2",
148+
"local.get 1",
149+
"i64.load 8",
150150
"i64.store 8",
151151
"local.get 0",
152152
"local.get 1",
153+
"i32.load16_u 0",
153154
"i32.store16 0",
154155
)
155156
}

0 commit comments

Comments
 (0)