@@ -92,7 +92,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
9292 if let Rvalue :: Cast ( CastKind :: Transmute , op, ty) = rvalue {
9393 if let Some ( niche) = self . get_niche ( * ty) {
9494 with_no_trimmed_paths ! ( debug!(
95- "Found place {op:?}: {ty:?} with niche due to Transmute"
95+ "Found place {op:?}: {ty:?} with niche {niche:?} due to Transmute: {:?}" ,
96+ self . body. stmt_at( location)
9697 ) ) ;
9798 self . places . push ( ( op. clone ( ) , niche) ) ;
9899 }
@@ -114,9 +115,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
114115 }
115116
116117 let ty = place. ty ( self . body , self . tcx ) . ty ;
117- if ty == self . tcx . types . bool {
118- // LLVM defeats our attempts to insert niche checks for bools by truncating all our
119- // loads to an i1.
118+ // bool is actually an i1 to LLVM which means a bool local can never be invalid.
119+ if ty == self . tcx . types . bool && place. projection . is_empty ( ) {
120120 return ;
121121 }
122122 let Some ( niche) = self . get_niche ( ty) else {
@@ -136,7 +136,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
136136 }
137137
138138 with_no_trimmed_paths ! ( debug!(
139- "Found place {place:?}: {ty:?} with niche due to {context:?}"
139+ "Found place {place:?}: {ty:?} with niche {niche:?} due to {:?}" ,
140+ self . body. stmt_at( location)
140141 ) ) ;
141142 self . places . push ( ( Operand :: Copy ( * place) , niche) ) ;
142143
@@ -153,6 +154,10 @@ impl<'a, 'tcx> NicheFinder<'a, 'tcx> {
153154
154155 let niche = layout. largest_niche ?;
155156
157+ if niche. offset == Size :: ZERO {
158+ return None ;
159+ }
160+
156161 if niche. size ( self . tcx ) == layout. size {
157162 Some ( NicheKind :: Full ( niche) )
158163 } else {
@@ -295,7 +300,7 @@ impl<'a, 'tcx> NicheChecker<'a, 'tcx> {
295300 }
296301}
297302
298- #[ derive( Clone , Copy ) ]
303+ #[ derive( Clone , Copy , Debug ) ]
299304enum NicheKind {
300305 Full ( Niche ) ,
301306 // We need the full Size of the type in order to do the transmute-to-MU approach
0 commit comments