diff options
| author | bors <bors@rust-lang.org> | 2023-05-28 12:33:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-28 12:33:52 +0000 |
| commit | 39c03fb65268e3331f381714c664a581a6e86b8c (patch) | |
| tree | 6bccf8406f5cd042d2bdc26408ef64825149a30b /compiler/rustc_mir_transform/src/check_alignment.rs | |
| parent | f59d577838fb0449a2b59ec3525a7fa91509e861 (diff) | |
| parent | 783b1ce99c86106456329d7fc51c149bc27a282a (diff) | |
| download | rust-39c03fb65268e3331f381714c664a581a6e86b8c.tar.gz rust-39c03fb65268e3331f381714c664a581a6e86b8c.zip | |
Auto merge of #112026 - saethlin:misaligned-addrof, r=pnkfelix
Don't check for misaligned raw pointer derefs inside Rvalue::AddressOf From https://github.com/rust-lang/rust/pull/112026#issuecomment-1565686697: rustc 1.70 (stable next week) added a Mir pass to add pointer alignment checks in debug mode. Adding these checks caused some crates to break, but that was expected, since they contain broken code (https://github.com/rust-lang/rust/issues/111487) for tracking that. However, the checks added are slightly more aggressive than they should have been. Specifically, they also check the place in an `addr_of!` expression. Whether lack of alignment there is or isn't UB is unclear. This PR modifies the pass to not affect those cases. I spot checked the crater regressions and the ones I saw were not the case that this PR is modifying. It still seems good to not land anything overaggressive though
Diffstat (limited to 'compiler/rustc_mir_transform/src/check_alignment.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_alignment.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index d60184e0ebe..1fe8ea07892 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -75,6 +75,14 @@ struct PointerFinder<'tcx, 'a> { } impl<'tcx, 'a> Visitor<'tcx> for PointerFinder<'tcx, 'a> { + fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + if let Rvalue::AddressOf(..) = rvalue { + // Ignore dereferences inside of an AddressOf + return; + } + self.super_rvalue(rvalue, location); + } + fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) { if let PlaceContext::NonUse(_) = context { return; |
