Skip to content

Commit 9309812

Browse files
committed
ir: Deal with _Atomic correctly.
Part of rust-lang#2151.
1 parent e24afad commit 9309812

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bitflags = "1.0.3"
5050
cexpr = "0.6"
5151
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
5252
clap = { version = "2", optional = true }
53-
clang-sys = { version = "1", features = ["clang_6_0"] }
53+
clang-sys = { version = "1", features = ["clang_11_0"] }
5454
lazycell = "1"
5555
lazy_static = "1"
5656
peeking_take_while = "0.1.2"

src/clang.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,15 @@ impl Type {
10681068
}
10691069
}
10701070

1071+
/// If this is an atomic type, returns the underlying value type, otherwise
1072+
/// an invalid type.
1073+
#[inline]
1074+
pub fn atomic_value_type(&self) -> Self {
1075+
Self {
1076+
x: unsafe { clang_Type_getValueType(self.x) },
1077+
}
1078+
}
1079+
10711080
/// What is the size of this type? Paper over invalid types by returning `0`
10721081
/// for them.
10731082
pub fn size(&self, ctx: &BindgenContext) -> usize {

src/ir/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
19701970
CXType_Double => TypeKind::Float(FloatKind::Double),
19711971
CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble),
19721972
CXType_Float128 => TypeKind::Float(FloatKind::Float128),
1973+
CXType_Atomic => {
1974+
// TODO(#2151): Preserve atomicity in a useful way somehow.
1975+
return self.build_builtin_ty(&ty.atomic_value_type());
1976+
}
19731977
CXType_Complex => {
19741978
let float_type =
19751979
ty.elem_type().expect("Not able to resolve complex type?");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
extern "C" {
9+
pub static mut interrupted: ::std::os::raw::c_uint;
10+
}

tests/headers/atomic-constant.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern _Atomic unsigned interrupted;

0 commit comments

Comments
 (0)