-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1188: Support align and packed repr layout on structs r=dafaust a=dafaust This is a start at handling the various layout options supported by Rust, beginning with `#[repr(align(N))]` and `#[repr(packed(N))]`, on structs and tuple structs. There are several other layout options which remain to be supported such as `#[repr(C)]`, `#[repr(transparent)]`, combinations e.g. `#[repr(C, packed(2))]`, as well as layouts on union and enum types. Fixes: #915 Co-authored-by: David Faust <david.faust@oracle.com>
- Loading branch information
Showing
12 changed files
with
223 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |