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

Fix handling of anonymous names in Clang 16. #2316

Closed
wants to merge 1 commit into from

Conversation

pcwalton
Copy link
Contributor

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 #2312.

r? @emilio

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 Author

With this PR, 3 tests still fail with Clang 16, but they look unrelated. In fact, for those 3 failing tests, Clang 16's output looks superior to the existing Clang.

emilio added a commit to emilio/rust-bindgen that referenced this pull request 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 <pcwalton@fb.com>
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! While this does fix the issue, I'd much rather check clang_Cursor_isAnonymous than relying on the spelling.

I had a WIP in the issue, and you found the place that I had missed, so #2319 contains that and I confirmed I get the same results as with this fix.

If you're ok with that (and assuming that's green on CI), I'd rather use that approach, which seems slightly more robust.

Thanks!

@@ -1422,7 +1423,9 @@ impl CompInfo {

// A declaration of an union or a struct without name
// could also be an unnamed field, unfortunately.
if cur.spelling().is_empty() &&
let mut spelling = cur.spelling();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bit I had missed in #2312 (comment), thanks for catching it :)

emilio added a commit to emilio/rust-bindgen that referenced this pull request 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 <pcwalton@fb.com>
@emilio emilio closed this in #2319 Oct 22, 2022
emilio added a commit that referenced this pull request 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 <pcwalton@fb.com>
dtolnay pushed a commit to fbsource/bindgen that referenced this pull request 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 <pcwalton@fb.com>
qsdrqs pushed a commit to qsdrqs/rust-bindgen that referenced this pull request 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 <pcwalton@fb.com>
mqudsi added a commit to mqudsi/ffmpeg-the-third that referenced this pull request Feb 10, 2023
This patch upgrades the `bindgen` dependency to version 0.64 which includes a
fix for an upstream issue broken builds when building w/ clang 16 or newer [0].

The use of a wildcard `*` was removed in bindgen 0.62 [1], code has been updated
to use the regex approach instead to continue working.

[0]: rust-lang/rust-bindgen#2316
[1]: rust-lang/rust-bindgen#2373
shssoichiro pushed a commit to shssoichiro/ffmpeg-the-third that referenced this pull request Feb 10, 2023
This patch upgrades the `bindgen` dependency to version 0.64 which includes a
fix for an upstream issue broken builds when building w/ clang 16 or newer [0].

The use of a wildcard `*` was removed in bindgen 0.62 [1], code has been updated
to use the regex approach instead to continue working.

[0]: rust-lang/rust-bindgen#2316
[1]: rust-lang/rust-bindgen#2373
SWW13 pushed a commit to SWW13/rust-bindgen that referenced this pull request Sep 18, 2023
…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 <pcwalton@fb.com>
aktaboot added a commit to aktaboot/nixpkgs that referenced this pull request Apr 17, 2024
The build was encountering an issue in rust-bindgen, that has been
fixed[1], but nettle-sys depends on an old version of rust-bindgen,

Updated nettle-sys, patched Cargo.lock

[1]- rust-lang/rust-bindgen#2316

https://bugs.launchpad.net/ubuntu/+source/rust-bindgen/+bug/2030886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread 'main' panicked at '"__mbstate_t_(anonymous_struct_at_foo_cc_2_3)" is not a valid Ident'
2 participants