Skip to content

Commit c41408d

Browse files
committed
long doubles rust-lang#2403: Get tests passing locally
1 parent 4a873bf commit c41408d

File tree

9 files changed

+171
-37
lines changed

9 files changed

+171
-37
lines changed

bindgen-tests/tests/expectations/tests/complex_global.rs

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

bindgen-tests/tests/expectations/tests/convert-floats-win64.rs

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

bindgen-tests/tests/expectations/tests/convert-floats.rs

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

bindgen-tests/tests/expectations/tests/long_double.rs

+4-1
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,9 @@
1+
// bindgen-flags: -- --target=x86_64-pc-windows-msvc
2+
3+
struct foo {
4+
float bar, baz;
5+
double bazz;
6+
long double* bazzz;
7+
float _Complex complexFloat;
8+
double _Complex complexDouble;
9+
};

bindgen-tests/tests/headers/convert-floats.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bindgen-flags: --no-convert-floats
1+
// bindgen-flags: --no-convert-floats -- --target=x86_64-unknown-linux-gnu
22

33
struct foo {
44
float bar, baz;

bindgen/codegen/helpers.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,31 @@ pub mod ast_ty {
187187
pub fn float_kind_rust_type(
188188
ctx: &BindgenContext,
189189
fk: FloatKind,
190-
layout: Option<Layout>,
190+
mut layout: Option<Layout>,
191+
n_parts: usize,
191192
) -> TokenStream {
192-
let bits = layout.map(|l| l.size * 8);
193+
let bits = match layout {
194+
Some(Layout { ref mut size, .. }) => {
195+
*size /= n_parts;
196+
Some(*size * 8)
197+
}
198+
None => None,
199+
};
193200
match (fk, ctx.options().convert_floats, bits) {
194201
// TODO: What about narrower floats?
195202
(_, true, Some(32)) => quote! { f32 },
196-
(_, true, Some(64)) => quote! { f64 },
203+
// FIXME: The (double, true, None) case is an artefact of macro parsing.
204+
(_, true, Some(64)) | (FloatKind::Double, true, None) => {
205+
quote! { f64 }
206+
}
197207
(FloatKind::Float, ..) => raw_type(ctx, "c_float"),
198208
(FloatKind::Double, ..) => raw_type(ctx, "c_double"),
199209
(FloatKind::LongDouble, ..) => {
200210
// TODO(emilio): If rust ever gains f80/f128 we should
201211
// use it here and below.
202-
ctx.generated_bindgen_long_double(layout.expect("unknown layout for long double"));
212+
ctx.generated_bindgen_long_double(
213+
layout.expect("unknown layout for long double"),
214+
);
203215
if ctx.options().enable_cxx_namespaces {
204216
quote! {
205217
root::__BindgenLongDouble

bindgen/codegen/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3741,11 +3741,11 @@ impl TryToRustTy for Type {
37413741
}
37423742
}
37433743
TypeKind::Float(fk) => {
3744-
Ok(float_kind_rust_type(ctx, fk, self.layout(ctx)))
3744+
Ok(float_kind_rust_type(ctx, fk, self.layout(ctx), 1))
37453745
}
37463746
TypeKind::Complex(fk) => {
37473747
let float_path =
3748-
float_kind_rust_type(ctx, fk, self.layout(ctx));
3748+
float_kind_rust_type(ctx, fk, self.layout(ctx), 2);
37493749

37503750
ctx.generated_bindgen_complex();
37513751
Ok(if ctx.options().enable_cxx_namespaces {

bindgen/ir/analysis/never_by_value.rs

+34-27
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'ctx> NeverByValue<'ctx> {
6464

6565
fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
6666
let id = id.into();
67-
info!("inserting {id:?} into the never_by_value set");
67+
trace!("inserting {id:?} into the never_by_value set");
6868

6969
let was_not_already_in_set = self.never_by_value.insert(id);
7070
assert!(
@@ -99,10 +99,10 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
9999
}
100100

101101
fn constrain(&mut self, id: ItemId) -> ConstrainResult {
102-
info!("constrain: {id:?}");
102+
trace!("constrain: {id:?}");
103103

104104
if self.never_by_value.contains(&id) {
105-
info!(" already in set");
105+
trace!(" already in set");
106106
return ConstrainResult::Same;
107107
}
108108

@@ -123,25 +123,30 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
123123
TypeKind::ObjCId |
124124
TypeKind::ObjCSel |
125125
TypeKind::BlockPointer(_) => {
126-
info!(" simple type that is not float");
126+
trace!(" simple type that is not float");
127127
ConstrainResult::Same
128128
}
129129

130130
TypeKind::Float(..) | TypeKind::Complex(..) => {
131-
let size = ty
132-
.layout(self.ctx)
133-
.expect("float with unknown layout")
134-
.size;
135-
match (ty.kind(), size) {
136-
(TypeKind::Float(..), 4 | 8) |
137-
(TypeKind::Complex(..), 8 | 16) => {
138-
info!(" skipped f32 or f64");
139-
ConstrainResult::Same
140-
}
141-
_ => {
142-
info!(" extended float size {size}");
143-
self.insert(id)
131+
if let Some(layout) = ty.layout(self.ctx) {
132+
match (ty.kind(), layout.size) {
133+
(TypeKind::Float(..), 4 | 8) |
134+
(TypeKind::Complex(..), 8 | 16) => {
135+
trace!(" skipped f32 or f64");
136+
ConstrainResult::Same
137+
}
138+
_ => {
139+
trace!(
140+
" extended float size {}",
141+
layout.size
142+
);
143+
self.insert(id)
144+
}
144145
}
146+
} else {
147+
// This case comes up with macro constants and doesn't seem relevant.
148+
trace!(" unknown float");
149+
ConstrainResult::Same
145150
}
146151
}
147152

@@ -151,10 +156,12 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
151156
TypeKind::TemplateAlias(t, _) |
152157
TypeKind::Vector(t, _) => {
153158
if self.never_by_value.contains(&t.into()) {
154-
info!(" contains/aliases matching type, so matches");
159+
trace!(
160+
" contains/aliases matching type, so matches"
161+
);
155162
self.insert(id)
156163
} else {
157-
info!(" does not contain/alias matching type");
164+
trace!(" does not contain/alias matching type");
158165
ConstrainResult::Same
159166
}
160167
}
@@ -164,7 +171,7 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
164171
self.never_by_value.contains(&base.ty.into())
165172
});
166173
if bases_have {
167-
info!(" bases have float, so we also have");
174+
trace!(" bases have float, so we also have");
168175
return self.insert(id);
169176
}
170177
let fields_have = info.fields().iter().any(|f| match *f {
@@ -178,11 +185,11 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
178185
}
179186
});
180187
if fields_have {
181-
info!(" fields have float, so we also have");
188+
trace!(" fields have float, so we also have");
182189
return self.insert(id);
183190
}
184191

185-
info!(" comp doesn't have float");
192+
trace!(" comp doesn't have float");
186193
ConstrainResult::Same
187194
}
188195

@@ -192,24 +199,24 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
192199
.iter()
193200
.any(|arg| self.never_by_value.contains(&arg.into()));
194201
if args_have {
195-
info!(" template args match, so instantiation also matches");
202+
trace!(" template args match, so instantiation also matches");
196203
return self.insert(id);
197204
}
198205

199206
let def_has = self
200207
.never_by_value
201208
.contains(&template.template_definition().into());
202209
if def_has {
203-
info!(" template definition has float, so instantiation also has");
210+
trace!(" template definition has float, so instantiation also has");
204211
return self.insert(id);
205212
}
206213

207-
info!(" template instantiation does not match");
214+
trace!(" template instantiation does not match");
208215
ConstrainResult::Same
209216
}
210217
}
211218
} else {
212-
info!(" not a type; skipped");
219+
trace!(" not a type; skipped");
213220
ConstrainResult::Same
214221
}
215222
}
@@ -220,7 +227,7 @@ impl<'ctx> MonotoneFramework for NeverByValue<'ctx> {
220227
{
221228
if let Some(edges) = self.dependencies.get(&id) {
222229
for item in edges {
223-
info!("enqueue {item:?} into worklist");
230+
trace!("enqueue {item:?} into worklist");
224231
f(*item);
225232
}
226233
}

0 commit comments

Comments
 (0)