Skip to content

Commit 53f7a50

Browse files
committed
Add rudimentary support for __float128
This adds `__float128` as a builtin type, and generates an opaque array of 16 `u8`s to represent it in the generated bindings since Rust doesn't have an `f128` type. Context and motivation: Somehow `__float128` is getting pulled into SpiderMonkey headers from somewhere, and the lack of `__float128` support was causing bindgen to hard fail in bindings generation.
1 parent 8d83bdf commit 53f7a50

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

src/clangll.rs

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ pub const CXType_Dependent: c_uint = 26;
392392
pub const CXType_ObjCId: c_uint = 27;
393393
pub const CXType_ObjCClass: c_uint = 28;
394394
pub const CXType_ObjCSel: c_uint = 29;
395+
pub const CXType_Float128: c_uint = 30;
395396
pub const CXType_FirstBuiltin: c_uint = 2;
396397
pub const CXType_LastBuiltin: c_uint = 29;
397398
pub const CXType_Complex: c_uint = 100;

src/codegen/mod.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -1609,27 +1609,22 @@ impl ToRustTy for Type {
16091609
}
16101610
}
16111611
TypeKind::Float(fk) => {
1612+
// TODO: we probably should just take the type layout into
1613+
// account?
1614+
//
1615+
// Also, maybe this one shouldn't be the default?
1616+
//
1617+
// FIXME: `c_longdouble` doesn't seem to be defined in some
1618+
// systems, so we use `c_double` directly.
16121619
use ir::ty::FloatKind;
1613-
if ctx.options().convert_floats {
1614-
// TODO: we probably should just take the type layout into
1615-
// account?
1616-
//
1617-
// Also, maybe this one shouldn't be the default?
1618-
match fk {
1619-
FloatKind::Float => aster::ty::TyBuilder::new().f32(),
1620-
FloatKind::Double | FloatKind::LongDouble => {
1621-
aster::ty::TyBuilder::new().f64()
1622-
}
1623-
}
1624-
} else {
1625-
// FIXME: `c_longdouble` doesn't seem to be defined in some
1626-
// systems, so we use `c_double` directly.
1627-
match fk {
1628-
FloatKind::Float => raw!(c_float),
1629-
FloatKind::Double | FloatKind::LongDouble => {
1630-
raw!(c_double)
1631-
}
1632-
}
1620+
match (fk, ctx.options().convert_floats) {
1621+
(FloatKind::Float, true) => aster::ty::TyBuilder::new().f32(),
1622+
(FloatKind::Double, true) |
1623+
(FloatKind::LongDouble, true) => aster::ty::TyBuilder::new().f64(),
1624+
(FloatKind::Float, false) => raw!(c_float),
1625+
(FloatKind::Double, false) |
1626+
(FloatKind::LongDouble, false) => raw!(c_double),
1627+
(FloatKind::Float128, _) => aster::ty::TyBuilder::new().array(16).u8(),
16331628
}
16341629
}
16351630
TypeKind::Function(ref fs) => {

src/ir/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ impl<'ctx> BindgenContext<'ctx> {
697697
CXType_Float => TypeKind::Float(FloatKind::Float),
698698
CXType_Double => TypeKind::Float(FloatKind::Double),
699699
CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble),
700+
CXType_Float128 => TypeKind::Float(FloatKind::Float128),
700701
_ => return None,
701702
};
702703

src/ir/ty.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ pub enum FloatKind {
363363
Double,
364364
/// A `long double`.
365365
LongDouble,
366+
/// A `__float128`.
367+
Float128,
366368
}
367369

368370
/// The different kinds of types that we can parse.
@@ -771,7 +773,10 @@ impl Type {
771773
ctx);
772774
}
773775
_ => {
774-
error!("unsupported type {:?} at {:?}", ty, location);
776+
error!("unsupported type: kind = {:?}; ty = {:?}; at {:?}",
777+
ty.kind(),
778+
ty,
779+
location);
775780
return Err(ParseError::Continue);
776781
}
777782
};

tests/expectations/tests/float128.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+

tests/headers/float128.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// FIXME: libclang < 3.9 does not expose `__float128` in its interface, so this
2+
// test will fail. Once we remove support for `--features llvm_stable` and
3+
// require libclang >= 3.9, we can reenable this test.
4+
//
5+
// static __float128 global = 1.0;
6+
7+
// FIXME: We have no way to get 128 bit aligned structs in Rust at the moment,
8+
// and therefore the generated layout tests for this struct will fail. When we
9+
// can enforce 128 bit alignment, we can re-enable this test.
10+
//
11+
// struct A {
12+
// __float128 f;
13+
// };

0 commit comments

Comments
 (0)