c-variadic: fix implementation on avr#152980
Conversation
|
...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 |
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
|
|
…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
0e7395a to
dbdc731
Compare
0712ba6 to
ebeb9a0
Compare
| // types with an alignment larger than 8, or with a non-scalar layout. Inline assembly can be used | ||
| // to accept unsupported types in the meantime. | ||
| #[lang = "va_arg_safe"] | ||
| pub unsafe trait VaArgSafe: sealed::Sealed {} |
There was a problem hiding this comment.
Seems like a bunch of work for little upside? But maybe
| unsafe impl VaArgSafe for usize {} | ||
|
|
||
| // f32 is implicitly promoted to c_double in C, and cannot implement `VaArgSafe`. | ||
| unsafe impl VaArgSafe for f64 {} |
There was a problem hiding this comment.
Thanks for checking!
| // Check that relevant `core::ffi` types implement `VaArgSafe`. | ||
| const _: () = { | ||
| const fn va_arg_safe_check<T: VaArgSafe>() {} | ||
|
|
||
| va_arg_safe_check::<crate::ffi::c_int>(); | ||
| va_arg_safe_check::<crate::ffi::c_uint>(); | ||
| va_arg_safe_check::<crate::ffi::c_double>(); | ||
| }; |
There was a problem hiding this comment.
Maybe worth adding long/ulong and longlong/ulonglong?
so that we can check whether a type implements the trait
ebeb9a0 to
a875e14
Compare
|
@bors r=tgross35 |
| }; | ||
|
|
||
| match scalar.primitive() { | ||
| Primitive::Pointer(_) => { |
There was a problem hiding this comment.
| Primitive::Pointer(_) => { | |
| // We reject types that would never be passed as varargs in C because | |
| // they get promoted to a larger type: small integer types, and all | |
| // float types except `f64`. | |
| Primitive::Pointer(_) => { |
| Primitive::Float(Float::F32) => { | ||
| if self.cx().sess().target.arch == Arch::Avr { | ||
| // c_double is actually f32 on avr. | ||
| emit_va_arg(self, args[0], result.layout.ty) |
There was a problem hiding this comment.
This line is always the same, right?
So maybe refactor this so the match just determines whether the type is valid (let valid = ...), and then always continue the same way?
c-variadic: fix implementation on `avr` tracking issue: rust-lang#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 `avr` the `c_int/c_uint` types are `i16/u16`, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targets `c_int_width`. However, this field is not actually used in `core` at all, there the 16-bit targets are just hardcoded. https://github.com/rust-lang/rust/blob/1500f0f47f5fe8ddcd6528f6c6c031b210b4eac5/library/core/src/ffi/primitives.rs#L174-L185 Perhaps we should expose this like endianness and pointer width? --- Finally there are some changes to the test to make it compile with `no_std`.
c-variadic: fix implementation on `avr` tracking issue: rust-lang#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 `avr` the `c_int/c_uint` types are `i16/u16`, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targets `c_int_width`. However, this field is not actually used in `core` at all, there the 16-bit targets are just hardcoded. https://github.com/rust-lang/rust/blob/1500f0f47f5fe8ddcd6528f6c6c031b210b4eac5/library/core/src/ffi/primitives.rs#L174-L185 Perhaps we should expose this like endianness and pointer width? --- Finally there are some changes to the test to make it compile with `no_std`.
c-variadic: fix implementation on `avr` tracking issue: rust-lang#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 `avr` the `c_int/c_uint` types are `i16/u16`, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targets `c_int_width`. However, this field is not actually used in `core` at all, there the 16-bit targets are just hardcoded. https://github.com/rust-lang/rust/blob/1500f0f47f5fe8ddcd6528f6c6c031b210b4eac5/library/core/src/ffi/primitives.rs#L174-L185 Perhaps we should expose this like endianness and pointer width? --- Finally there are some changes to the test to make it compile with `no_std`.
Rollup of 13 pull requests Successful merges: - #152980 (c-variadic: fix implementation on `avr`) - #154491 (Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)) - #155354 (Remove AttributeSafety from BUILTIN_ATTRIBUTES) - #154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases) - #155095 (changed the information provided by (mut x) to mut x (Fix 155030)) - #155358 (ImproperCTypes: Move erasing_region_normalisation into helper function) - #155377 (tests/debuginfo/basic-stepping.rs: Remove FIXME related to ZSTs) - #155383 (Rearrange `rustc_ast_pretty`) - #155384 (triagebot: notify on diagnostic attribute changes) - #155386 (Use `box_new` diagnostic item for Box::new suggestions) - #155391 (Small refactor of `QueryJob::latch` method) - #155395 (Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc) - #155396 (`as_ref_unchecked` docs link fix)
Rollup of 19 pull requests Successful merges: - #141633 (Suggest to bind `self.x` to `x` when field `x` may be in format string) - #152980 (c-variadic: fix implementation on `avr`) - #154491 (Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)) - #155318 (Use mutable pointers for Unix path buffers) - #155335 (Bump bootstrap to 1.96 beta) - #155354 (Remove AttributeSafety from BUILTIN_ATTRIBUTES) - #154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases) - #155095 (changed the information provided by (mut x) to mut x (Fix 155030)) - #155305 (Make `convert_while_ascii` unsafe) - #155358 (ImproperCTypes: Move erasing_region_normalisation into helper function) - #155377 (tests/debuginfo/basic-stepping.rs: Remove FIXME related to ZSTs) - #155383 (Rearrange `rustc_ast_pretty`) - #155384 (triagebot: notify on diagnostic attribute changes) - #155386 (Use `box_new` diagnostic item for Box::new suggestions) - #155391 (Small refactor of `QueryJob::latch` method) - #155395 (Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc) - #155396 (`as_ref_unchecked` docs link fix) - #155411 (compiletest: Remove the `//@ should-ice` directive) - #155413 (fix: typo in `std::fs::hard_link` documentation)
Rollup merge of #152980 - folkertdev:c-variadic-avr, r=tgross35 c-variadic: fix implementation on `avr` 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 `avr` the `c_int/c_uint` types are `i16/u16`, and this was not handled in the c-variadic checks. Luckily there is a field in the target configuration that contains the targets `c_int_width`. However, this field is not actually used in `core` at all, there the 16-bit targets are just hardcoded. https://github.com/rust-lang/rust/blob/1500f0f47f5fe8ddcd6528f6c6c031b210b4eac5/library/core/src/ffi/primitives.rs#L174-L185 Perhaps we should expose this like endianness and pointer width? --- Finally there are some changes to the test to make it compile with `no_std`.
…=RalfJung c-variadic: add roundtrip test tracking issue: rust-lang#44930 Test that our `va_arg` implementation matches (as in, can decode) how LLVM passes c-variadic arguments. And some comment followup to rust-lang#152980 (cc @RalfJung, feel free to review this PR too btw). r? tgross35
Rollup merge of #155486 - folkertdev:c-variadic-roundtrip, r=RalfJung c-variadic: add roundtrip test tracking issue: #44930 Test that our `va_arg` implementation matches (as in, can decode) how LLVM passes c-variadic arguments. And some comment followup to #152980 (cc @RalfJung, feel free to review this PR too btw). r? tgross35
Rollup of 19 pull requests Successful merges: - rust-lang/rust#141633 (Suggest to bind `self.x` to `x` when field `x` may be in format string) - rust-lang/rust#152980 (c-variadic: fix implementation on `avr`) - rust-lang/rust#154491 (Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)) - rust-lang/rust#155318 (Use mutable pointers for Unix path buffers) - rust-lang/rust#155335 (Bump bootstrap to 1.96 beta) - rust-lang/rust#155354 (Remove AttributeSafety from BUILTIN_ATTRIBUTES) - rust-lang/rust#154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases) - rust-lang/rust#155095 (changed the information provided by (mut x) to mut x (Fix 155030)) - rust-lang/rust#155305 (Make `convert_while_ascii` unsafe) - rust-lang/rust#155358 (ImproperCTypes: Move erasing_region_normalisation into helper function) - rust-lang/rust#155377 (tests/debuginfo/basic-stepping.rs: Remove FIXME related to ZSTs) - rust-lang/rust#155383 (Rearrange `rustc_ast_pretty`) - rust-lang/rust#155384 (triagebot: notify on diagnostic attribute changes) - rust-lang/rust#155386 (Use `box_new` diagnostic item for Box::new suggestions) - rust-lang/rust#155391 (Small refactor of `QueryJob::latch` method) - rust-lang/rust#155395 (Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc) - rust-lang/rust#155396 (`as_ref_unchecked` docs link fix) - rust-lang/rust#155411 (compiletest: Remove the `//@ should-ice` directive) - rust-lang/rust#155413 (fix: typo in `std::fs::hard_link` documentation)
View all comments
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?
Finally there are some changes to the test to make it compile with
no_std.