Skip to content

ir: Deal with _Atomic correctly. #2153

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bitflags = "1.0.3"
cexpr = "0.6"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = { version = "3", optional = true }
clang-sys = { version = "1", features = ["clang_6_0"] }
clang-sys = { version = "1", features = ["clang_11_0"] }
lazycell = "1"
lazy_static = "1"
peeking_take_while = "0.1.2"
Expand Down
9 changes: 9 additions & 0 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,15 @@ impl Type {
}
}

/// If this is an atomic type, returns the underlying value type, otherwise
/// an invalid type.
#[inline]
pub fn atomic_value_type(&self) -> Self {
Self {
x: unsafe { clang_Type_getValueType(self.x) },
}
}

/// What is the size of this type? Paper over invalid types by returning `0`
/// for them.
pub fn size(&self, ctx: &BindgenContext) -> usize {
Expand Down
4 changes: 4 additions & 0 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
CXType_Double => TypeKind::Float(FloatKind::Double),
CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble),
CXType_Float128 => TypeKind::Float(FloatKind::Float128),
CXType_Atomic => {
// TODO(#2151): Preserve atomicity in a useful way somehow.
return self.build_builtin_ty(&ty.atomic_value_type());
}
CXType_Complex => {
let float_type =
ty.elem_type().expect("Not able to resolve complex type?");
Expand Down
10 changes: 10 additions & 0 deletions tests/expectations/tests/atomic-constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

extern "C" {
pub static mut interrupted: ::std::os::raw::c_uint;
}
1 change: 1 addition & 0 deletions tests/headers/atomic-constant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern _Atomic unsigned interrupted;