@@ -92,7 +92,7 @@ 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: {:?}" , self . body . stmt_at ( location )
9696 ) ) ;
9797 self . places . push ( ( op. clone ( ) , niche) ) ;
9898 }
@@ -114,9 +114,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
114114 }
115115
116116 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.
117+ // bool is actually an i1 to LLVM which means a bool local can never be invalid.
118+ if ty == self . tcx . types . bool && place. projection . is_empty ( ) {
120119 return ;
121120 }
122121 let Some ( niche) = self . get_niche ( ty) else {
@@ -136,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NicheFinder<'a, 'tcx> {
136135 }
137136
138137 with_no_trimmed_paths ! ( debug!(
139- "Found place {place:?}: {ty:?} with niche due to {context :?}"
138+ "Found place {place:?}: {ty:?} with niche {niche:?} due to {:?}" , self . body . stmt_at ( location )
140139 ) ) ;
141140 self . places . push ( ( Operand :: Copy ( * place) , niche) ) ;
142141
@@ -153,6 +152,10 @@ impl<'a, 'tcx> NicheFinder<'a, 'tcx> {
153152
154153 let niche = layout. largest_niche ?;
155154
155+ if niche. offset == Size :: ZERO {
156+ return None ;
157+ }
158+
156159 if niche. size ( self . tcx ) == layout. size {
157160 Some ( NicheKind :: Full ( niche) )
158161 } else {
@@ -295,7 +298,7 @@ impl<'a, 'tcx> NicheChecker<'a, 'tcx> {
295298 }
296299}
297300
298- #[ derive( Clone , Copy ) ]
301+ #[ derive( Clone , Copy , Debug ) ]
299302enum NicheKind {
300303 Full ( Niche ) ,
301304 // We need the full Size of the type in order to do the transmute-to-MU approach
0 commit comments