Skip to content

Don't warn about v128 in wasm ABI transition #139809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_monomorphize/src/mono_checks/abi_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ fn wasm_abi_safe<'tcx>(tcx: TyCtxt<'tcx>, arg: &ArgAbi<'tcx, Ty<'tcx>>) -> bool
return true;
}

// If this is a simd argument let other rustc warnings kick in and don't
// provide extra warnings here
Comment on lines +102 to +103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If this is a simd argument let other rustc warnings kick in and don't
// provide extra warnings here
// SIMD types are passed the same way under both ABIs.

if uses_vector_registers(&arg.mode, &arg.layout.backend_repr) {
return true;
}

// This matches `unwrap_trivial_aggregate` in the wasm ABI logic.
if arg.layout.is_aggregate() {
let cx = LayoutCx::new(tcx, TypingEnv::fully_monomorphized());
Expand Down
15 changes: 14 additions & 1 deletion tests/ui/lint/wasm_c_abi_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ add-core-stubs
//@ build-fail

#![feature(no_core)]
#![feature(no_core, repr_simd)]
#![no_core]
#![crate_type = "lib"]
#![deny(wasm_c_abi)]
Expand Down Expand Up @@ -45,3 +45,16 @@ pub fn call_other_fun(x: MyType) {
pub struct MyZstType;
#[allow(improper_ctypes_definitions)]
pub extern "C" fn zst_safe(_x: (), _y: MyZstType) {}

// The `v128` is already warned as not-FFI-safe by the
// `improper_ctypes_definitions` lint, so no need to doubly warn about it with
// the `wasm_c_abi` lint. Test for the lint from `improper_ctypes_definitions`
// but this doubly asserts that there are no other lints, such as from the
// `wasm_c_abi` lint.
Comment on lines +49 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment also needs updating.

#[repr(simd)]
#[allow(non_camel_case_types)]
pub struct v128([i32; 4]);
#[target_feature(enable = "simd128")]
pub extern "C" fn my_safe_simd(x: v128) -> v128 { x }
//~^ WARN `extern` fn uses type `v128`, which is not FFI-safe
//~| WARN `extern` fn uses type `v128`, which is not FFI-safe
31 changes: 30 additions & 1 deletion tests/ui/lint/wasm_c_abi_transition.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
warning: `extern` fn uses type `v128`, which is not FFI-safe
--> $DIR/wasm_c_abi_transition.rs:58:35
|
LL | pub extern "C" fn my_safe_simd(x: v128) -> v128 { x }
| ^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
--> $DIR/wasm_c_abi_transition.rs:56:1
|
LL | pub struct v128([i32; 4]);
| ^^^^^^^^^^^^^^^
= note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `v128`, which is not FFI-safe
--> $DIR/wasm_c_abi_transition.rs:58:44
|
LL | pub extern "C" fn my_safe_simd(x: v128) -> v128 { x }
| ^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
--> $DIR/wasm_c_abi_transition.rs:56:1
|
LL | pub struct v128([i32; 4]);
| ^^^^^^^^^^^^^^^

error: this function definition involves an argument of type `MyType` which is affected by the wasm ABI transition
--> $DIR/wasm_c_abi_transition.rs:18:1
|
Expand Down Expand Up @@ -33,7 +62,7 @@ LL | unsafe { other_fun(x) }
= note: for more information, see issue #138762 <https://github.com/rust-lang/rust/issues/138762>
= help: the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target

error: aborting due to 3 previous errors
error: aborting due to 3 previous errors; 2 warnings emitted

Future incompatibility report: Future breakage diagnostic:
error: this function definition involves an argument of type `MyType` which is affected by the wasm ABI transition
Expand Down
Loading