@@ -585,20 +585,32 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
585
585
val. into ( )
586
586
}
587
587
588
- Aggregate ( ref kind, ref fields) => Value :: Aggregate {
589
- fields : fields
590
- . iter ( )
591
- . map ( |field| self . eval_operand ( field) . map_or ( Value :: Uninit , Value :: Immediate ) )
592
- . collect ( ) ,
593
- variant : match * * kind {
594
- AggregateKind :: Adt ( _, variant, _, _, _) => variant,
595
- AggregateKind :: Array ( _)
596
- | AggregateKind :: Tuple
597
- | AggregateKind :: Closure ( _, _)
598
- | AggregateKind :: Coroutine ( _, _)
599
- | AggregateKind :: CoroutineClosure ( _, _) => VariantIdx :: new ( 0 ) ,
600
- } ,
601
- } ,
588
+ Aggregate ( ref kind, ref fields) => {
589
+ // Do not const pop union fields as they can be
590
+ // made to produce values that don't match their
591
+ // underlying layout's type (see ICE #121534).
592
+ // If the last element of the `Adt` tuple
593
+ // is `Some` it indicates the ADT is a union
594
+ if let AggregateKind :: Adt ( _, _, _, _, Some ( _) ) = * * kind {
595
+ return None ;
596
+ } ;
597
+ Value :: Aggregate {
598
+ fields : fields
599
+ . iter ( )
600
+ . map ( |field| {
601
+ self . eval_operand ( field) . map_or ( Value :: Uninit , Value :: Immediate )
602
+ } )
603
+ . collect ( ) ,
604
+ variant : match * * kind {
605
+ AggregateKind :: Adt ( _, variant, _, _, _) => variant,
606
+ AggregateKind :: Array ( _)
607
+ | AggregateKind :: Tuple
608
+ | AggregateKind :: Closure ( _, _)
609
+ | AggregateKind :: Coroutine ( _, _)
610
+ | AggregateKind :: CoroutineClosure ( _, _) => VariantIdx :: new ( 0 ) ,
611
+ } ,
612
+ }
613
+ }
602
614
603
615
Repeat ( ref op, n) => {
604
616
trace ! ( ?op, ?n) ;
0 commit comments