Skip to content

Add rudimentary support for __float128 #233

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

Merged
merged 1 commit into from
Nov 11, 2016
Merged
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
1 change: 1 addition & 0 deletions src/clangll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ pub const CXType_Dependent: c_uint = 26;
pub const CXType_ObjCId: c_uint = 27;
pub const CXType_ObjCClass: c_uint = 28;
pub const CXType_ObjCSel: c_uint = 29;
pub const CXType_Float128: c_uint = 30;
pub const CXType_FirstBuiltin: c_uint = 2;
pub const CXType_LastBuiltin: c_uint = 29;
pub const CXType_Complex: c_uint = 100;
Expand Down
35 changes: 15 additions & 20 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,27 +1609,22 @@ impl ToRustTy for Type {
}
}
TypeKind::Float(fk) => {
// TODO: we probably should just take the type layout into
// account?
//
// Also, maybe this one shouldn't be the default?
//
// FIXME: `c_longdouble` doesn't seem to be defined in some
// systems, so we use `c_double` directly.
use ir::ty::FloatKind;
if ctx.options().convert_floats {
// TODO: we probably should just take the type layout into
// account?
//
// Also, maybe this one shouldn't be the default?
match fk {
FloatKind::Float => aster::ty::TyBuilder::new().f32(),
FloatKind::Double | FloatKind::LongDouble => {
aster::ty::TyBuilder::new().f64()
}
}
} else {
// FIXME: `c_longdouble` doesn't seem to be defined in some
// systems, so we use `c_double` directly.
match fk {
FloatKind::Float => raw!(c_float),
FloatKind::Double | FloatKind::LongDouble => {
raw!(c_double)
}
}
match (fk, ctx.options().convert_floats) {
(FloatKind::Float, true) => aster::ty::TyBuilder::new().f32(),
(FloatKind::Double, true) |
(FloatKind::LongDouble, true) => aster::ty::TyBuilder::new().f64(),
(FloatKind::Float, false) => raw!(c_float),
(FloatKind::Double, false) |
(FloatKind::LongDouble, false) => raw!(c_double),
(FloatKind::Float128, _) => aster::ty::TyBuilder::new().array(16).u8(),
}
}
TypeKind::Function(ref fs) => {
Expand Down
1 change: 1 addition & 0 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ impl<'ctx> BindgenContext<'ctx> {
CXType_Float => TypeKind::Float(FloatKind::Float),
CXType_Double => TypeKind::Float(FloatKind::Double),
CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble),
CXType_Float128 => TypeKind::Float(FloatKind::Float128),
_ => return None,
};

Expand Down
7 changes: 6 additions & 1 deletion src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ pub enum FloatKind {
Double,
/// A `long double`.
LongDouble,
/// A `__float128`.
Float128,
}

/// The different kinds of types that we can parse.
Expand Down Expand Up @@ -771,7 +773,10 @@ impl Type {
ctx);
}
_ => {
error!("unsupported type {:?} at {:?}", ty, location);
error!("unsupported type: kind = {:?}; ty = {:?}; at {:?}",
ty.kind(),
ty,
location);
return Err(ParseError::Continue);
}
};
Expand Down
7 changes: 7 additions & 0 deletions tests/expectations/tests/float128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]



13 changes: 13 additions & 0 deletions tests/headers/float128.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// FIXME: libclang < 3.9 does not expose `__float128` in its interface, so this
// test will fail. Once we remove support for `--features llvm_stable` and
// require libclang >= 3.9, we can reenable this test.
//
// static __float128 global = 1.0;

// FIXME: We have no way to get 128 bit aligned structs in Rust at the moment,
// and therefore the generated layout tests for this struct will fail. When we
// can enforce 128 bit alignment, we can re-enable this test.
//
// struct A {
// __float128 f;
// };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have a global constant __float128 gloablaFloat to test it a bit.
This does not generate layout tests, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That struct would generate layout tests, but would fail them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean, yeah that'd be neat.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thanks.