Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread 'main' panicked at '"__mbstate_t_(anonymous_struct_at_foo_cc_2_3)" is not a valid Ident' #2312

Closed
glandium opened this issue Oct 17, 2022 · 8 comments · Fixed by #2319 · May be fixed by geo-engine/xgboost-rs#1
Closed

Comments

@glandium
Copy link
Contributor

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
@emilio
Copy link
Contributor

emilio commented Oct 17, 2022

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?

@glandium
Copy link
Contributor Author

Better if you do because I don't really know what bindgen would rather have available.

@emilio
Copy link
Contributor

emilio commented Oct 18, 2022

@glandium can you check if e69e0df, or 9763aa5 (on top) pass tests with llvm trunk? I can check tomorrow otherwise.

@glandium
Copy link
Contributor Author

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,
}

@glandium
Copy link
Contributor Author

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.

pcwalton added a commit to pcwalton/rust-bindgen that referenced this issue Oct 21, 2022
In trunk, Clang started emitting names like `"(unnamed enum at foo.cpp:4:2)"`
for unnamed enums, structs, and unions, while previous versions emitted the
empty string. This caused panics.

This commit simply rewrites such names back to the empty string so that we stay
compatible with both old and new versions of Clang.

Closes rust-lang#2312.
@pcwalton
Copy link
Contributor

#2316 is a fix.

emilio added a commit to emilio/rust-bindgen that referenced this issue Oct 22, 2022
…y names.

In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes rust-lang#2312
Closes rust-lang#2316

Co-Authored-by: Patrick Walton <[email protected]>
emilio added a commit to emilio/rust-bindgen that referenced this issue Oct 22, 2022
…y names.

In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes rust-lang#2312
Closes rust-lang#2316

Co-Authored-by: Patrick Walton <[email protected]>
emilio added a commit that referenced this issue Oct 22, 2022
…y names.

In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes #2312
Closes #2316

Co-Authored-by: Patrick Walton <[email protected]>
dtolnay pushed a commit to fbsource/bindgen that referenced this issue Oct 25, 2022
…y names.

In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes rust-lang#2312
Closes rust-lang#2316

Co-Authored-by: Patrick Walton <[email protected]>
qsdrqs pushed a commit to qsdrqs/rust-bindgen that referenced this issue Oct 26, 2022
…y names.

In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes rust-lang#2312
Closes rust-lang#2316

Co-Authored-by: Patrick Walton <[email protected]>
@tgross35
Copy link
Contributor

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

@tgross35
Copy link
Contributor

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

shymega pushed a commit to clarkf/guile-rs that referenced this issue Jan 15, 2024
Unable to compile with Guile 3.x due to a clang update, which caused
bindgen to break:

rust-lang/rust-bindgen#2312

This also updates the bindings to GNU Guile 3.0.9.
libvirtmirror pushed a commit to libvirt/libvirt-rust that referenced this issue Jan 17, 2024
Unfortunately, Debian 11 has just too old Rust which prevents us
from working on anything not prehistoric. There are couple of
issues:

1) It doesn't understand modern Cargo.toml syntax, which causes
   CI failures:

     https://gitlab.com/libvirt/libvirt-rust/-/merge_requests/64

2) We currently require bindgen-0.59.2 which doesn't work with
   LLVM-16 because of:

     rust-lang/rust-bindgen#2312

   The fix is contained in bindgen-0.62.0. While there is some
   intersect between versions available to Debian 11 version of
   Rust (0.65.1, 0.64.0, 0.63.0, 0.62.0) neither of them generate
   code that Debian 11 version of Rust (1.48.0) understands.
   The bindgen-0.62.0 release notes set the minimal required
   version of rust to 1.57.0 anyway:

     https://crates.io/crates/bindgen/0.62.0

We are stuck. And the only way out is just to drop Debian 11
support. Live long my old friend.

Signed-off-by: Michal Privoznik <[email protected]>
shymega pushed a commit to clarkf/guile-rs that referenced this issue Jan 22, 2024
Unable to compile with Guile 3.x due to a clang update, which caused
bindgen to break:

rust-lang/rust-bindgen#2312

This also updates the bindings to GNU Guile 3.0.9.
libvirtmirror pushed a commit to libvirt/libvirt-rust that referenced this issue Jan 23, 2024
As LLVM-16 is getting more and more popular, we are hitting the
following bug when trying to regenerate bindings from libvirt
header files:

  rust-lang/rust-bindgen#2312

Long story short, bindgen is not happy with some value that
LLVM-16 returns (LLVM-15 is okay) and panics.

While it's sufficient to bump bindgen to 0.62.0 we can go all the
way to 0.69.2 which is supposed to work even with LLVM-18:

  https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md#0692-2024-01-13

Signed-off-by: Michal Privoznik <[email protected]>
ianichitei added a commit to bitdefender/bddisasm that referenced this issue Feb 20, 2024
kodiakhq bot pushed a commit to sbdchd/squawk that referenced this issue Feb 21, 2024
This updates `bindgen` to 0.64, fixing rust-lang/rust-bindgen#2312 (via [`libpg_query-sys`](https://crates.io/crates/libpg_query-sys/0.2.1)) when building from source.
koalo added a commit to koalo/sysrepo-rs that referenced this issue Mar 11, 2024
Bump bindgen to support newer clang versions.
See rust-lang/rust-bindgen#2312

Also adapt the types referring to a size to usize,
otherwise the new bindgen will no longer accept it.

Signed-off-by: Florian Kauer <[email protected]>
AMagicHarry added a commit to AMagicHarry/sonic that referenced this issue Mar 12, 2024
Fixes #315

Build of sonic-server is failing on NixOS
for a few weeks now, see https://hydra.nixos.org/build/239524816

This failing build has been caused by a clang 16 upgrade,
because rocksdb depends on a old rust-bindgen version which
is not compatible with this version of clang.

See rust-lang/rust-bindgen#2312

A resolution is to upgrade rocksdb to its latest version.
shymega pushed a commit to clarkf/guile-rs that referenced this issue Mar 21, 2024
Unable to compile with Guile 3.x due to a clang update, which caused
bindgen to break:

rust-lang/rust-bindgen#2312

This also updates the bindings to GNU Guile 3.0.9.
shymega pushed a commit to guile-rs/guile-rs that referenced this issue Mar 21, 2024
* Update bindgen

Unable to compile with Guile 3.x due to a clang update, which caused
bindgen to break:

rust-lang/rust-bindgen#2312

This also updates the bindings to GNU Guile 3.0.9.

* Update rust edition

Use the most recent rust edition (2021) so that any future code is
conformant.

* Fix clippy lint issues

Fix a trivial issue discovered by `cargo clippy'.
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Apr 20, 2024
…package

postgresql14Packages.promscale_extension breaks with:

  Error:
    0: `pgx-0.6.1` shouldn't be used with `cargo-pgx-0.7.4`,
    please use `pgx = "~0.7.4"` in your `Cargo.toml`.

However, pinning cargo-pgx to 0_6_1 via the following

  buildPgxExtension.override { cargo-pgx = cargo-pgx_0_6_1; }

does not work either, because the build then fails with:

  thread 'main' panicked at /build/promscale_extension-0.8.0-vendor.tar.gz/proc-macro2/src/fallback.rs:756:9:
  "__mbstate_t_union_(unnamed_at_/nix/store/ij144ma6vs8acil8r9hgr8xkb1dp9azg-glibc-2_39-5-dev/include/bits/types/__mbstate_t_h_16_3)" is not a valid Ident

This seems to be related to [1], which indicates that this is a
problem with newer LLVM / clang toolchains.

At the same time th upstream package is deprecated / archived since
the 2nd of April 2024 [2]. Additionally this package is unfree and
thus very unlikely to be forked. Since we can't expect this to be
fixed, the only sensible thing to do is to remove the package.

[1]: rust-lang/rust-bindgen#2312
[2]: timescale/promscale#1836
koalo added a commit to Linutronix/sysrepo-rs that referenced this issue Jun 24, 2024
Bump bindgen to support newer clang versions.
See rust-lang/rust-bindgen#2312

Also adapt the types referring to a size to usize,
otherwise the new bindgen will no longer accept it.

Signed-off-by: Florian Kauer <[email protected]>
koalo added a commit to Linutronix/detnetctl that referenced this issue Jun 24, 2024
Use sysrepo-rs version with newer bindgen version
to support newer clang versions.
See rust-lang/rust-bindgen#2312

Signed-off-by: Florian Kauer <[email protected]>
koalo added a commit to Linutronix/detnetctl that referenced this issue Jun 25, 2024
Use sysrepo-rs version with newer bindgen version
to support newer clang versions.
See rust-lang/rust-bindgen#2312

Signed-off-by: Florian Kauer <[email protected]>
Reviewed-by: Kurt Kanzenbach <[email protected]>
zachs18 added a commit to zachs18/imagegen-rs that referenced this issue Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants