google/autocxx

binding generation fails with 16bit floats

farnoy opened this issue · 6 comments

Describe the bug
Including AVX-512 intrinsics defines 16b float vectors that autocxx fails to account for.

To Reproduce
Minimal example I was able to come up with:

// repro.h
#include <smmintrin.h>

#define __IMMINTRIN_H // to work around the #include protection of the following headers
#include <avxintrin.h>
#include <avx512fintrin.h>
#include <avx512bwintrin.h>
#include <avx512dqintrin.h>
#include <avx512fp16intrin.h> // Comment this and the problem goes away

// alternatively to doing all of the above, the same error happens with:
// #include <immintrin.h>
// repro.rs
pub(crate) use autocxx::prelude::*;

include_cpp! {
    #include "repro.h"
}

This crashes during the build script execution with the following output:

  --- stderr
  thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autocxx-bindgen-0.65.1/ir/context.rs:1997:26:
  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))
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/189d6c71f3bb6c52113b5639a80839791974fd22/library/std/src/panicking.rs:645:5
     1: core::panicking::panic_fmt
               at /rustc/189d6c71f3bb6c52113b5639a80839791974fd22/library/core/src/panicking.rs:72:14
     2: autocxx_bindgen::ir::context::BindgenContext::build_builtin_ty
     3: autocxx_bindgen::ir::context::BindgenContext::builtin_or_resolved_ty
     4: autocxx_bindgen::ir::item::Item::from_ty_or_ref_with_id
     5: autocxx_bindgen::ir::item::Item::from_ty_or_ref
     6: autocxx_bindgen::ir::function::args_from_ty_and_cursor::{{closure}}
     7: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
     8: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
     9: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
    10: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
    11: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
    12: core::iter::traits::iterator::Iterator::collect
    13: autocxx_bindgen::ir::function::args_from_ty_and_cursor
    14: autocxx_bindgen::ir::function::FunctionSig::from_ty
    15: autocxx_bindgen::ir::ty::Type::from_clang_ty
    16: autocxx_bindgen::ir::item::Item::from_ty_with_id
    17: autocxx_bindgen::ir::item::Item::from_ty
    18: <autocxx_bindgen::ir::function::Function as autocxx_bindgen::parse::ClangSubItemParser>::parse
    19: autocxx_bindgen::ir::item::Item::parse
    20: autocxx_bindgen::parse_one
    21: autocxx_bindgen::parse::{{closure}}::{{closure}}
    22: autocxx_bindgen::clang::visit_children
    23: _ZN5clang8cxcursor13CursorVisitor5VisitE8CXCursorb.localalias
    24: _ZN5clang8cxcursor13CursorVisitor23handleDeclForVisitationEPKNS_4DeclE.localalias
    25: _ZN5clang8cxcursor13CursorVisitor16VisitDeclContextEPNS_11DeclContextE
    26: _ZN5clang8cxcursor13CursorVisitor13VisitChildrenE8CXCursor
    27: clang_visitChildren.localalias
    28: clang_sys::clang_visitChildren
    29: autocxx_bindgen::clang::Cursor::visit
    30: autocxx_bindgen::parse::{{closure}}
    31: autocxx_bindgen::ir::context::BindgenContext::with_module
    32: autocxx_bindgen::parse
    33: autocxx_bindgen::Bindings::generate
    34: autocxx_bindgen::Builder::generate
    35: autocxx_engine::IncludeCppEngine::generate
    36: autocxx_engine::parse_file::ParsedFile::resolve_all
    37: autocxx_engine::builder::Builder<CTX>::build_listing_files
    38: autocxx_engine::builder::Builder<CTX>::build
    39: build_script_build::main
    40: core::ops::function::FnOnce::call_once

Expected behavior
Should finish analysis and generate (in this case empty) bindings.

Additional context

$ echo $LIBCLANG_PATH 
/nix/store/c82g6467pzfhci8m82m43fyskw7wcplz-clang-17.0.2-lib/lib
$ rustc -vV
rustc 1.75.0-nightly (189d6c71f 2023-11-06)
binary: rustc
commit-hash: 189d6c71f3bb6c52113b5639a80839791974fd22
commit-date: 2023-11-06
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

autocxx v0.26.0

Thanks for the report - it's extremely likely that this is a problem with bindgen on which we rely.

Found the issue on bindgen's tracker. Closing this, thanks! rust-lang/rust-bindgen#2500