Skip to content

Commit d332def

Browse files
committed
Auto merge of rust-lang#112107 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
[stable] 1.70.0 (backport) Backport rust-lang#112026 into 1.70.0 stable. Will rebuild dev-static artifacts after this gets built. r? `@Mark-Simulacrum`
2 parents 8b07c88 + 8fc89a2 commit d332def

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

compiler/rustc_mir_transform/src/check_alignment.rs

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ struct PointerFinder<'tcx, 'a> {
7575
}
7676

7777
impl<'tcx, 'a> Visitor<'tcx> for PointerFinder<'tcx, 'a> {
78+
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
79+
if let Rvalue::AddressOf(..) = rvalue {
80+
// Ignore dereferences inside of an AddressOf
81+
return;
82+
}
83+
self.super_rvalue(rvalue, location);
84+
}
85+
7886
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
7987
if let PlaceContext::NonUse(_) = context {
8088
return;

tests/ui/mir/addrof_alignment.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
// ignore-wasm32-bare: No panic messages
3+
// compile-flags: -C debug-assertions
4+
5+
struct Misalignment {
6+
a: u32,
7+
}
8+
9+
fn main() {
10+
let items: [Misalignment; 2] = [Misalignment { a: 0 }, Misalignment { a: 1 }];
11+
unsafe {
12+
let ptr: *const Misalignment = items.as_ptr().cast::<u8>().add(1).cast::<Misalignment>();
13+
let _ptr = core::ptr::addr_of!((*ptr).a);
14+
}
15+
}

0 commit comments

Comments
 (0)