-
Notifications
You must be signed in to change notification settings - Fork 165
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
Support align and packed repr layout on structs #1188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1254,6 +1254,20 @@ class ADTType : public BaseType, public SubstitutionRef | |
ENUM | ||
}; | ||
|
||
// Representation options, specified via attributes e.g. #[repr(packed)] | ||
struct ReprOptions | ||
{ | ||
// bool is_c; | ||
// bool is_transparent; | ||
//... | ||
|
||
// For align and pack: 0 = unspecified. Nonzero = byte alignment. | ||
// It is an error for both to be nonzero, this should be caught when | ||
// parsing the #[repr] attribute. | ||
unsigned char align = 0; | ||
unsigned char pack = 0; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be worth having some kind of error node state here. For example, during the type-checking of this structure, you could represent an error state by a flag or something so that when you are compiling the type we know if it's ok or not so we can error or ignore the options. This will only really matter down the line when we get rid of the saw_errors guards between each compiler pass. |
||
|
||
ADTType (HirId ref, std::string identifier, RustIdent ident, ADTKind adt_kind, | ||
std::vector<VariantDef *> variants, | ||
std::vector<SubstitutionParamMapping> subst_refs, | ||
|
@@ -1276,7 +1290,20 @@ class ADTType : public BaseType, public SubstitutionRef | |
identifier (identifier), variants (variants), adt_kind (adt_kind) | ||
{} | ||
|
||
ADTType (HirId ref, HirId ty_ref, std::string identifier, RustIdent ident, | ||
ADTKind adt_kind, std::vector<VariantDef *> variants, | ||
std::vector<SubstitutionParamMapping> subst_refs, ReprOptions repr, | ||
SubstitutionArgumentMappings generic_arguments | ||
= SubstitutionArgumentMappings::error (), | ||
std::set<HirId> refs = std::set<HirId> ()) | ||
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs), | ||
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), | ||
identifier (identifier), variants (variants), adt_kind (adt_kind), | ||
repr (repr) | ||
{} | ||
|
||
ADTKind get_adt_kind () const { return adt_kind; } | ||
ReprOptions get_repr_options () const { return repr; } | ||
|
||
bool is_struct_struct () const { return adt_kind == STRUCT_STRUCT; } | ||
bool is_tuple_struct () const { return adt_kind == TUPLE_STRUCT; } | ||
|
@@ -1385,6 +1412,7 @@ class ADTType : public BaseType, public SubstitutionRef | |
std::string identifier; | ||
std::vector<VariantDef *> variants; | ||
ADTType::ADTKind adt_kind; | ||
ReprOptions repr; | ||
}; | ||
|
||
class FnType : public BaseType, public SubstitutionRef | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[repr(align(8))] | ||
struct Foo { | ||
x: i16, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
y: i8, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
z: i32, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
} | ||
|
||
#[repr(align(8))] | ||
struct Bar(i8, i32); | ||
|
||
fn main () { | ||
let f = Foo { x: 5, y: 2, z: 13 }; | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
let b = Bar (7, 262); | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
fn main () { | ||
|
||
#[repr(align(8))] | ||
struct Baz { | ||
x: u16, | ||
y: u32, | ||
}; | ||
|
||
#[repr(align(4))] | ||
struct Qux (u8, i16); | ||
|
||
let b = Baz { x: 5, y: 1984 }; | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
|
||
let c = Qux (1, 2); | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[repr(packed(2))] | ||
struct Foo { | ||
x: i16, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
y: i8, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
z: i32, | ||
// { dg-warning "field is never read" "" { target *-*-* } .-1 } | ||
} | ||
|
||
#[repr(packed)] | ||
struct Bar(i8, i32); | ||
|
||
fn main () { | ||
let f = Foo { x: 5, y: 2, z: 13 }; | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
let b = Bar (7, 262); | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
fn main () { | ||
|
||
#[repr(packed(2))] | ||
struct Baz { | ||
x: u16, | ||
y: u32, | ||
}; | ||
|
||
#[repr(packed)] | ||
struct Qux (u8, i16); | ||
|
||
let b = Baz { x: 5, y: 1984 }; | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
|
||
let c = Qux (1, 2); | ||
// { dg-warning "unused name" "" { target *-*-* } .-1 } | ||
} |
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.
Yeah i think your right here the AST Meta stuff is not very helpful to work with at the moment.