-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #83605 - RalfJung:unaligned, r=petrochenkov
unaligned_references: align(N) fields in packed(N) structs are fine This removes some false positives from the unaligned_references lint: in a `repr(packed(2))` struct, fields of alignment 2 (and less) are guaranteed to be properly aligned, so we do not have to consider them "disaligned".
- Loading branch information
Showing
7 changed files
with
87 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// run-pass (note: this is spec-UB, but it works for now) | ||
// ignore-32bit (needs `usize` to be 8-aligned to reproduce all the errors below) | ||
#![allow(dead_code)] | ||
// ignore-emscripten weird assertion? | ||
|
||
#[repr(C, packed(4))] | ||
struct Foo4C { | ||
bar: u8, | ||
baz: usize | ||
} | ||
|
||
pub fn main() { | ||
let foo = Foo4C { bar: 1, baz: 2 }; | ||
let brw = &foo.baz; //~WARN reference to packed field is unaligned | ||
//~^ previously accepted | ||
assert_eq!(*brw, 2); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/packed/packed-struct-borrow-element-64bit.stderr
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,13 @@ | ||
warning: reference to packed field is unaligned | ||
--> $DIR/packed-struct-borrow-element-64bit.rs:14:15 | ||
| | ||
LL | let brw = &foo.baz; | ||
| ^^^^^^^^ | ||
| | ||
= note: `#[warn(unaligned_references)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> | ||
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) | ||
|
||
warning: 1 warning emitted | ||
|
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