rust-lang / rust-lang/rust-bindgen

Use core::arch vector types on FFI

Open
#1,365 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Currently, vector types like x86's __m128d are bind as follows:

pub type __m128d = [f64; 2]
// - incorrect alignment: missing #[repr(align(16))]
// - incorrect code generation: not #[repr(simd)]

It would be better for these types to just map to their definitions in {core,std}::arch::{$ARCH}::__m128d; since that would solve both issues (note that arm, aarch64, ppc64le, .. each has its own different types).

When C functions use these types in their return type, the correct function signature is produced (e.g. fn foo() -> __m128d), but when C functions use these types in argument position, the types are replaced with a pointer to its element type (e.g. fn foo(x: *mut f64); instead of fn foo(x: __m128d).

Using these types on C FFI requires unstable and the repr(simd_ffi) feature. Not using simd_ffi for this is probably undefined behavior. Therefore, trying to wrap any such type on stable should hard error anyways.

cc @emilio

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by tracing bindgen's vector-type handling and generated FFI argument bindings, then compare the output with the relevant core/std arch definitions across architectures. Done means vector arguments use the correct arch types and stable builds reject unsupported SIMD FFI use.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.