Skip to content

Commit

Permalink
Try to debug another miscompile
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 29, 2023
1 parent 2ae0dbc commit 086c91c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions compiler/rustc_mir_transform/src/check_niches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
if let Rvalue::Cast(CastKind::Transmute, op, ty) = rvalue {
if let Some(niche) = self.get_niche(*ty) {
with_no_trimmed_paths!(debug!(
"Found place {op:?}: {ty:?} with niche due to Transmute"
"Found place {op:?}: {ty:?} with niche {niche:?} due to Transmute: {:?}", self.body.stmt_at(location)
));
self.places.push((op.clone(), niche));
}
Expand All @@ -114,9 +114,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
}

let ty = place.ty(self.body, self.tcx).ty;
if ty == self.tcx.types.bool {
// LLVM defeats our attempts to insert niche checks for bools by truncating all our
// loads to an i1.
// bool is actually an i1 to LLVM which means a bool local can never be invalid.
if ty == self.tcx.types.bool && place.projection.is_empty() {
return;
}
let Some(niche) = self.get_niche(ty) else {
Expand All @@ -136,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
}

with_no_trimmed_paths!(debug!(
"Found place {place:?}: {ty:?} with niche due to {context:?}"
"Found place {place:?}: {ty:?} with niche {niche:?} due to {:?}", self.body.stmt_at(location)
));
self.places.push((Operand::Copy(*place), niche));

Expand All @@ -153,6 +152,10 @@ impl<'a, 'tcx> NicheFinder<'a, 'tcx> {

let niche = layout.largest_niche?;

if niche.offset == Size::ZERO {
return None;
}

if niche.size(self.tcx) == layout.size {
Some(NicheKind::Full(niche))
} else {
Expand Down Expand Up @@ -295,7 +298,7 @@ impl<'a, 'tcx> NicheChecker<'a, 'tcx> {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
enum NicheKind {
Full(Niche),
// We need the full Size of the type in order to do the transmute-to-MU approach
Expand Down

0 comments on commit 086c91c

Please sign in to comment.