Skip to content

Commit 39232cc

Browse files
emiliopvdrz
authored andcommitted
ir: Dig into atomic types.
Fixes #2920
1 parent d89ebe4 commit 39232cc

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

bindgen-tests/tests/expectations/tests/atomic-constant.rs

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_Atomic(int) a;
2+
int b;

bindgen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ path = "lib.rs"
2828
annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
2929
bitflags = "2.2.1"
3030
cexpr = "0.6"
31-
clang-sys = { version = "1", features = ["clang_6_0"] }
31+
clang-sys = { version = "1", features = ["clang_11_0"] }
3232
itertools = { version = ">=0.10,<0.14", default-features = false }
3333
log = { version = "0.4", optional = true }
3434
prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] }

bindgen/clang.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,15 @@ impl Type {
14931493
}
14941494
}
14951495

1496+
/// For atomic types, get the underlying type.
1497+
pub(crate) fn atomic_value_type(&self) -> Type {
1498+
unsafe {
1499+
Type {
1500+
x: clang_Type_getValueType(self.x),
1501+
}
1502+
}
1503+
}
1504+
14961505
/// Is this a valid type?
14971506
pub(crate) fn is_valid(&self) -> bool {
14981507
self.kind() != CXType_Invalid

bindgen/ir/ty.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,18 @@ impl Type {
11671167
.expect("Not able to resolve array element?");
11681168
TypeKind::Array(inner, ty.num_elements().unwrap())
11691169
}
1170+
CXType_Atomic => {
1171+
// TODO(emilio): Maybe we can preserve the "is atomic" bit somehow and generate
1172+
// something more useful... But for now this is better than panicking or
1173+
// generating nothing.
1174+
return Self::from_clang_ty(
1175+
potential_id,
1176+
&ty.atomic_value_type(),
1177+
location,
1178+
parent_id,
1179+
ctx,
1180+
);
1181+
}
11701182
CXType_Elaborated => {
11711183
return Self::from_clang_ty(
11721184
potential_id,

bindgen/ir/var.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ impl ClangSubItemParser for Var {
320320
matches!(ty.kind(), CXType_Auto | CXType_Unexposed),
321321
"Couldn't resolve constant type, and it \
322322
wasn't an nondeductible auto type or unexposed \
323-
type!"
323+
type: {:?}",
324+
ty
324325
);
325326
return Err(e);
326327
}

0 commit comments

Comments
 (0)