Skip to content

Commit

Permalink
ir: Dig into atomic types.
Browse files Browse the repository at this point in the history
Fixes #2920
  • Loading branch information
emilio committed Sep 2, 2024
1 parent d89ebe4 commit e148482
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions bindgen-tests/tests/expectations/tests/atomic-constant.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bindgen-tests/tests/headers/atomic-constant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_Atomic(int) a;
int b;
2 changes: 1 addition & 1 deletion bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ path = "lib.rs"
annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
bitflags = "2.2.1"
cexpr = "0.6"
clang-sys = { version = "1", features = ["clang_6_0"] }
clang-sys = { version = "1", features = ["clang_11_0"] }
itertools = { version = ">=0.10,<0.14", default-features = false }
log = { version = "0.4", optional = true }
prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] }
Expand Down
9 changes: 9 additions & 0 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,15 @@ impl Type {
}
}

/// For atomic types, get the underlying type.
pub(crate) fn atomic_value_type(&self) -> Type {
unsafe {
Type {
x: clang_Type_getValueType(self.x),
}
}
}

/// Is this a valid type?
pub(crate) fn is_valid(&self) -> bool {
self.kind() != CXType_Invalid
Expand Down
9 changes: 9 additions & 0 deletions bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,15 @@ impl Type {
.expect("Not able to resolve array element?");
TypeKind::Array(inner, ty.num_elements().unwrap())
}
CXType_Atomic => {
return Self::from_clang_ty(
potential_id,
&ty.atomic_value_type(),
location,
parent_id,
ctx,
);
}
CXType_Elaborated => {
return Self::from_clang_ty(
potential_id,
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl ClangSubItemParser for Var {
matches!(ty.kind(), CXType_Auto | CXType_Unexposed),
"Couldn't resolve constant type, and it \
wasn't an nondeductible auto type or unexposed \
type!"
type: {:?}", ty
);
return Err(e);
}
Expand Down

0 comments on commit e148482

Please sign in to comment.