rust-bindgen: `_Float16 _Complex` leads to panic (such as when including `immintrin.h` on clang 16)

Input C/C++ Header

/* input.h */
_Float16 _Complex h;

Bindgen Invocation

$ bindgen input.h

Actual Results

panicked at 'Non floating-type complex? Type(_Complex _Float16, kind: Complex, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Type(_Float16, kind: Float16, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None))', J:\Compilers\Rust\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.65.1\ir\context.rs:1994:26

Expected Results

Command completes without error.

Synopsis

Ran into this when using a header from a project that includes immintrin.h, which on clang 16 always seems to include avx512fp16intrin.h and avx512vlfp16intrin.h, which in turn have construct _Float16 _Complex, which currently bindgen cannot handle.

For example, running bindgen on SDL2’s SDL.h which includes immintrin.h through SDL_cpuinfo.h results in the above error.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 17 (7 by maintainers)

Commits related to this issue

Most upvoted comments

If https://github.com/rust-lang/rfcs/pull/3453 gets merged, we might have a clearer way forward here.

For reference, a more precise way to work around this issue is to define the preprocessor definitions __AVX512VLFP16INTRIN_H and __AVX512FP16INTRIN_, instead of undefining __SSE2__ entirely:

$ <...>/rust-bindgen/target/release/bindgen --verbose /usr/x86_64-w64-mingw32/include/winsock2.h -- \
    --target=x86_64-pc-windows-gnu -D__AVX512VLFP16INTRIN_H -D__AVX512FP16INTRIN_H

This effectively disables the C definitions (_Float16 _Complex ...) that trip bindgen inside avx512vlfp16intrin.h and avx512fp16intrin.h.

And, of course, bindgen version 0.66.1 stumbles at a different place even with this work around, so one would need to fetch and build the main branch for the moment.

Notice that, using bindgen built from main branch (commit 2df02c2668f41d35616c8385ed61ada896a4bf4c) fixes the second issue above, so that the following succeeds:

$ <...>/rust-bindgen/target/release/bindgen --verbose /usr/x86_64-w64-mingw32/include/winsock2.h -- --target=x86_64-pc-windows-gnu -U__SSE2__