Skip to content

Commit 55769a5

Browse files
committed
wasm: Make simd types passed via indirection again
This commit updates wasm target specs to use `simd_types_indirect: true` again. Long ago this was added since wasm simd types were always translated to `v128` under-the-hood in LLVM, meaning that it didn't matter whether that target feature was enabled or not. Now, however, `v128` is conditionally used in codegen depending on target features enabled, meaning that it's possible to get linker errors about different signatures in code that correctly uses simd types. The fix is the same as for all other platforms, which is to pass the type indirectly.
1 parent 835150e commit 55769a5

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

compiler/rustc_target/src/spec/wasm_base.rs

-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ pub fn options() -> TargetOptions {
103103
linker: Some("rust-lld".to_owned()),
104104
lld_flavor: LldFlavor::Wasm,
105105

106-
// No need for indirection here, simd types can always be passed by
107-
// value as the whole module either has simd or not, which is different
108-
// from x86 (for example) where programs can have functions that don't
109-
// enable simd features.
110-
simd_types_indirect: false,
111-
112106
pre_link_args,
113107

114108
crt_objects_fallback: Some(CrtObjectsFallback::Wasm),
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// build-pass
2+
3+
#![cfg_attr(target_arch = "wasm32", feature(wasm_simd, wasm_target_feature))]
4+
5+
#[cfg(target_arch = "wasm32")]
6+
fn main() {
7+
unsafe {
8+
a::api_with_simd_feature();
9+
}
10+
}
11+
12+
#[cfg(target_arch = "wasm32")]
13+
mod a {
14+
use std::arch::wasm32::*;
15+
16+
#[target_feature(enable = "simd128")]
17+
pub unsafe fn api_with_simd_feature() {
18+
crate::b::api_takes_v128(u64x2(0, 1));
19+
}
20+
}
21+
22+
#[cfg(target_arch = "wasm32")]
23+
mod b {
24+
use std::arch::wasm32::*;
25+
26+
#[inline(never)]
27+
pub fn api_takes_v128(a: v128) -> v128 {
28+
a
29+
}
30+
}
31+
32+
#[cfg(not(target_arch = "wasm32"))]
33+
fn main() {}

0 commit comments

Comments
 (0)