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

Handle CXCursor_LinkageSpec in Clang 18+ #2689

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 44 additions & 43 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,57 +1432,58 @@ impl Item {
}
}

// Guess how does clang treat extern "C" blocks?
if cursor.kind() == CXCursor_UnexposedDecl {
Err(ParseError::Recurse)
} else {
match cursor.kind() {
// On Clang 18+, extern "C" is reported accurately as a LinkageSpec.
// Older LLVM treat it as UnexposedDecl.
CXCursor_LinkageSpec | CXCursor_UnexposedDecl => {
Err(ParseError::Recurse)
}

// We allowlist cursors here known to be unhandled, to prevent being
// too noisy about this.
match cursor.kind() {
CXCursor_MacroDefinition |
CXCursor_MacroExpansion |
CXCursor_UsingDeclaration |
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
}
CXCursor_InclusionDirective => {
let file = cursor.get_included_file_name();
match file {
None => {
warn!(
"Inclusion of a nameless file in {:?}",
cursor
);
}
Some(included_file) => {
for cb in &ctx.options().parse_callbacks {
cb.include_file(&included_file);
}
CXCursor_MacroDefinition |
CXCursor_MacroExpansion |
CXCursor_UsingDeclaration |
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
Err(ParseError::Continue)
}

ctx.add_dep(included_file.into_boxed_str());
}
CXCursor_InclusionDirective => {
let file = cursor.get_included_file_name();
match file {
None => {
warn!("Inclusion of a nameless file in {:?}", cursor);
}
}
_ => {
// ignore toplevel operator overloads
let spelling = cursor.spelling();
if !spelling.starts_with("operator") {
warn!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
Some(included_file) => {
for cb in &ctx.options().parse_callbacks {
cb.include_file(&included_file);
}

ctx.add_dep(included_file.into_boxed_str());
}
}
Err(ParseError::Continue)
}

Err(ParseError::Continue)
_ => {
// ignore toplevel operator overloads
let spelling = cursor.spelling();
if !spelling.starts_with("operator") {
warn!(
"Unhandled cursor kind {:?}: {:?}",
cursor.kind(),
cursor
);
}
Err(ParseError::Continue)
}
}
}

Expand Down
Loading