`aarch64_vector_pcs` function pointers become a zero-sized opaque; rustc drops the argument

オープン
#3,475 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, rust
領域
tooling

調査の方向性

CXCallingConv_AArch64VectorCall が Abi::Vectorcall になる get_abi から始め、関数ポインター型とフィールドで UnsupportedAbi がどのように表現されるかを追ってください。提供されたヘッダーを bindgen で再現し、生成された Rust と LLVM のシグネチャを調べてください。非対応の vectorcall ポインターがポインターサイズのままになるか、引数を失う代わりに警告付きで宣言がスキップされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Input C/C++ Header
typedef int (*fp)(int) __attribute__((aarch64_vector_pcs));
int apply(fp f, int x);
Bindgen Invocation
$ bindgen input.h -- -std=gnu11
Actual Results

bindgen 0.72.1 and 0.73.1 both turn the function-pointer type into a zero-sized opaque blob:

pub type fp = __BindgenOpaqueArray<[u32; 0]>;
pub fn apply(f: fp, x: c_int) -> c_int;

aarch64_vector_pcs is CXCallingConv_AArch64VectorCall, which get_abi maps to Abi::Vectorcall. On a stable rustc that ABI is UnsupportedAbi, so the function-pointer type becomes a 0-size opaque instead of *mut c_void / Option<unsafe extern "C" fn(i32) -> i32>. rustc then drops the ZST from the FFI signature:

; clang
define i32 @apply(ptr noundef %0, i32 noundef %1)

; rustc of the generated bindings (twice)
declare i32 @apply(i32)

A C caller apply(dummy, 7) passes the function pointer and 7. Generated Rust apply(Default::default(), 7) becomes apply(7) and the 7 lands in the pointer register.

This is not #727 / #2693: those abort or skip when the function itself has an unknown/unsupported CC. Here bindgen exits 0 and emits a callable apply with the wrong arity.

The same 0-size opaque happens for an aarch64_vector_pcs function-pointer field (struct S { int (*fp)(int,int) __attribute__((aarch64_vector_pcs)); int t; } — fp is [u32; 0] at offset 0 with t still at offset 8).

Expected Results

If vectorcall is not available, still emit a pointer-sized function-pointer type (or skip apply with a warning), not a ZST that rustc deletes from the signature.

Environment
bindgen: 0.72.1 and 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Homebrew clang 21.1.8
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS
主要言語
Rust
スター
5.3k
フォーク
846
平均マージ
2日 6時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust-bindgen のほかの issue

rust-lang/rust-bindgen の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。