-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add #[packed] attribute to create packed structs #5758
Conversation
@@ -174,7 +185,8 @@ fn struct_ty(ty: TypeRef, | |||
fields.push(ty); | |||
} | |||
|
|||
return T_struct(fields); | |||
// XXX: Is this meant to be always non-packed? | |||
return T_struct(fields, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@crabtw, git blame
seems to say you wrote much of the mips backend.
I don't understand the purpose of the struct being created by struct_ty
(something about passing arguments to a function since it is called from classify_arg_ty
?). Is this struct always meant to be non-packed, even if the argument being classified is a packed struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbaupp struct_ty
is used to ensure argument is placed in correct offset. The returned struct is always non-packed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
A struct (inc. tuple struct) can be annotated with #[packed], so that there is no padding between its elements, like GCC's `__attribute__((packed))`. Closes rust-lang#1704.
This is good work but I think the approach isn't quite congruent with how we normally do things. Whether or not a struct is packed is really a detail of its representation, and is not a concern of the type system, so I think we should not modify There are two common patterns to this approach. One is to add a side table in the type context (indexed by the struct's def-id) to indicate whether or not a struct is packed. Typically, for things local to the crate, these side tables are populated during the "collect" phase of type check (i.e., However, a cache might be overkill, since the "packed" information is only relevant to |
Hm, thanks for the explanation. I'll try to fix that some time in the next week or so. |
Require `or_patterns` to suggest nesting them changelog: Require `#![feature(or_patterns)]` to trigger [`unnested_or_patterns`] Fixes rust-lang#5704
This adds a
#[packed]
attribute for structs, like GCC's__attribute__((packed))
, e.g.It works on normal and tuple structs, but is (silently) ignored on enums.
Notes:
ty::sty
.Closes #1704.
(I'm not sure about the XXX in cabi_mips.rs, so merging this should probably wait.)Resolved!