@@ -585,20 +585,33 @@ 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 `field_idx` is `Some` it indicates the ADT is a union
593
+ if let AggregateKind :: Adt ( _, _, _, _, field_idx) = * * kind
594
+ && field_idx. is_some ( )
595
+ {
596
+ return None ;
597
+ } ;
598
+ Value :: Aggregate {
599
+ fields : fields
600
+ . iter ( )
601
+ . map ( |field| {
602
+ self . eval_operand ( field) . map_or ( Value :: Uninit , Value :: Immediate )
603
+ } )
604
+ . collect ( ) ,
605
+ variant : match * * kind {
606
+ AggregateKind :: Adt ( _, variant, _, _, _) => variant,
607
+ AggregateKind :: Array ( _)
608
+ | AggregateKind :: Tuple
609
+ | AggregateKind :: Closure ( _, _)
610
+ | AggregateKind :: Coroutine ( _, _)
611
+ | AggregateKind :: CoroutineClosure ( _, _) => VariantIdx :: new ( 0 ) ,
612
+ } ,
613
+ }
614
+ }
602
615
603
616
Repeat ( ref op, n) => {
604
617
trace ! ( ?op, ?n) ;
0 commit comments