c-variadic: fix implementation on avr#152980
c-variadic: fix implementation on avr#152980folkertdev wants to merge 2 commits intorust-lang:mainfrom
avr#152980Conversation
|
...a double-precision float is sometimes a single-precision float in C? |
|
I don't make the rules... This is what the target does (it's a 16-bit target, so it sort of makes sense I guess) |
|
@Patryk27 did the Also, I have some local code that makes the test compile on avr, which I can then run in |
| assert!( | ||
| self.cx().size_of(result.layout.ty).bits() | ||
| >= u64::from(self.cx().sess().target.options.c_int_width) | ||
| ); |
There was a problem hiding this comment.
@workingjubilee how do you feel about the checks here. The c_int_width is not actually used by core at all, it has its own logic. We already have several layers of defence against an incorrect type ending up here, so maybe we can just remove the check here?
This comment has been minimized.
This comment has been minimized.
f039e11 to
61b24ec
Compare
|
I think it mostly bothers me that it isn't a symmetric halving. If the (almost always software, I assume) implementation of |
This comment has been minimized.
This comment has been minimized.
61b24ec to
a88e5f9
Compare
I don't recall anything - it's not every day one tries to use floating-point on an 8-bit micro! We did have a tangentially related type-problem over at compiler-builtins - it turns out that on AVRs some floating-point intrinsics return i8 instead of i32: ... but I'm not sure if that type is exposed as any of those
You can see the sizes here: https://gcc.gnu.org/wiki/avr-gcc#Type_Layout Note that
There's simavr which I've managed to hook up with Rust, see: avr-tester - does that help? 👀 |
Fair. I didn't even do any math though, just passed some bits around.
The rest looks good.
So conceivably you could take the rmake test and turn it into a rust repo (using |
a88e5f9 to
0e7395a
Compare
| // targets, c_double is f32 and c_int/c_uing are i16/u16, and these types implement | ||
| // VaArgSafe there. On all other targets, these types do not implement VaArgSafe. | ||
| let arg_ty = self.structurally_resolve_type(arg.span, arg_ty); | ||
| if let Some(trait_def_id) = tcx.lang_items().va_arg_safe() |
There was a problem hiding this comment.
just unwrap ing the lang item causes bootstrap issues.
|
|
…eanup, r=jieyouxu Cleanup of c-variadic link test Some changes pulled out of rust-lang#152980 that are just cosmetic, but will help make the code run on embedded targets. r? jieyouxu
…eanup, r=jieyouxu Cleanup of c-variadic link test Some changes pulled out of rust-lang#152980 that are just cosmetic, but will help make the code run on embedded targets. r? jieyouxu
so that we can check whether a type implements the trait
0e7395a to
dbdc731
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
tracking issue: #44930
cc target maintainer @Patryk27
I ran into multiple issues, and although with this PR and a little harness I can run the test with qemu on avr, the implementation is perhaps not ideal.
The problem we found is that on
avrthec_int/c_uinttypes arei16/u16, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targetsc_int_width. However, this field is not actually used incoreat all, there the 16-bit targets are just hardcoded.rust/library/core/src/ffi/primitives.rs
Lines 174 to 185 in 1500f0f
Perhaps we should expose this like endianness and pointer width?
Next, it turned out that
c_doubleshould bef32on this target. So for now I hardcoded that incoretoo, but doing this properly would require another field in the target config I guess?Finally there are some changes to the test to make it compile with
no_std.