thread 'main' panicked at '"__mbstate_t_(anonymous_struct_at_foo_cc_2_3)" is not a valid Ident'
glandium opened this issue · comments
This started happening on clang-trunk with llvm/llvm-project@19e984e
Input C/C++ Header
typedef struct {
struct {};
} __mbstate_t;
Bindgen Invocation
bindgen::Builder::default()
.header("foo.cc")
.generate()
.unwrap()
Actual Results
thread 'main' panicked at '"__mbstate_t_(anonymous_struct_at_foo_cc_2_3)" is not a valid Ident', /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.46/src/fallback.rs:756:9
stack backtrace:
0: rust_begin_unwind
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
2: proc_macro2::fallback::validate_ident
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.46/src/fallback.rs:756:9
3: proc_macro2::fallback::Ident::_new
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.46/src/fallback.rs:698:9
4: proc_macro2::fallback::Ident::new
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.46/src/fallback.rs:708:9
5: proc_macro2::Ident::new
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.46/src/lib.rs:974:21
6: bindgen::ir::context::BindgenContext::rust_ident_raw
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/ir/context.rs:861:9
7: bindgen::ir::context::BindgenContext::rust_ident
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/ir/context.rs:853:9
8: <bindgen::ir::comp::CompInfo as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:1786:31
9: <bindgen::ir::ty::Type as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:814:39
10: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:500:17
11: <bindgen::ir::comp::CompInfo as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:2115:13
12: <bindgen::ir::ty::Type as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:814:39
13: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:500:17
14: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen::{{closure}}
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:523:21
15: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:553:13
16: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:491:17
17: bindgen::codegen::codegen::{{closure}}
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:4364:9
18: bindgen::ir::context::BindgenContext::gen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/ir/context.rs:1173:19
19: bindgen::codegen::codegen
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/codegen/mod.rs:4328:5
20: bindgen::Bindings::generate
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/lib.rs:2438:32
21: bindgen::Builder::generate
at /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.60.1/src/lib.rs:1502:9
This is due to this behavior change here, which changes the behavior of libclang:
llvm/llvm-project@19e984e#diff-cde6fae42b53073a85e0901697f60ea80262705f86643b7b27524c7bd24c6f80
It seems they changed an API that was returning an empty string to return a formatted thing that we can't really easily parse or identify as an anonymous struct.
@glandium I think this is worth an upstream bug report, could you do that if you have a build locally? Or do you want me to?
Better if you do because I don't really know what bindgen would rather have available.
Tests seem to pass, but they also pass with current master...
However, for the testcase, with e69e0df + clang-trunk:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __mbstate_t {
pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __mbstate_t__bindgen_ty_1 {
pub _address: u8,
}
With e69e0df + clang 14:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __mbstate_t {
pub __bindgen_anon_1: __mbstate_t__bindgen_ty_1,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __mbstate_t__bindgen_ty_1 {
pub _address: u8,
}
Tests seem to pass, but they also pass with current master...
scrap that, I didn't run them correctly. They do fail with master and fail less with your patches, but there are still 39 failing (vs. 87 without the patches), with errors that align with the previous comment.
#2316 is a fix.
It looks like #2316 was canceled but #2319 resolved it instead? I am wondering why I am still hitting this issue on 0.61.0
thread 'main' panicked at '"type-parameter-0-1" is not a valid Ident', /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/fallback.rs:756:9
stack backtrace:
0: rust_begin_unwind
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
2: proc_macro2::fallback::validate_ident
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/fallback.rs:756:9
3: proc_macro2::fallback::Ident::_new
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/fallback.rs:698:9
4: proc_macro2::fallback::Ident::new
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/fallback.rs:708:9
5: proc_macro2::imp::Ident::new
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/wrapper.rs:701:50
6: proc_macro2::Ident::new
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/lib.rs:974:21
7: bindgen::ir::context::BindgenContext::rust_ident_raw
at /home/default/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.61.0/ir/context.rs:859:9
Oops, I misread the release log, looks like there actually hasn't been one since the patch.
Please ignore me, hopefully the next release isn't too far