@@ -134,18 +134,21 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
134
134
AggregateKind :: Adt ( def_id, variant_index, ..) => {
135
135
match self . tcx . def_kind ( def_id) {
136
136
DefKind :: Struct => ( Some ( target_idx) , None ) ,
137
- DefKind :: Enum => ( Some ( target_idx) , Some ( variant_index) ) ,
137
+ DefKind :: Enum => (
138
+ self . map . apply ( target_idx, TrackElem :: Variant ( variant_index) ) ,
139
+ Some ( variant_index) ,
140
+ ) ,
138
141
_ => ( None , None ) ,
139
142
}
140
143
}
141
144
_ => ( None , None ) ,
142
145
} ;
143
- if let Some ( target ) = variant_target {
146
+ if let Some ( variant_target_idx ) = variant_target {
144
147
for ( field_index, operand) in operands. iter ( ) . enumerate ( ) {
145
- if let Some ( field) = self
146
- . map ( )
147
- . apply ( target , TrackElem :: Field ( Field :: from_usize ( field_index) ) )
148
- {
148
+ if let Some ( field) = self . map ( ) . apply (
149
+ variant_target_idx ,
150
+ TrackElem :: Field ( Field :: from_usize ( field_index) ) ,
151
+ ) {
149
152
let result = self . handle_operand ( operand, state) ;
150
153
state. insert_idx ( field, result, self . map ( ) ) ;
151
154
}
@@ -154,6 +157,11 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
154
157
if let Some ( variant_index) = variant_index
155
158
&& let Some ( discr_idx) = self . map ( ) . apply ( target_idx, TrackElem :: Discriminant )
156
159
{
160
+ // We are assigning the discriminant as part of an aggregate.
161
+ // This discriminant can only alias a variant field's value if the operand
162
+ // had an invalid value for that type.
163
+ // Using invalid values is UB, so we are allowed to perform the assignment
164
+ // without extra flooding.
157
165
let enum_ty = target. ty ( self . local_decls , self . tcx ) . ty ;
158
166
if let Some ( discr_val) = self . eval_discriminant ( enum_ty, variant_index) {
159
167
state. insert_value_idx ( discr_idx, FlatSet :: Elem ( discr_val) , & self . map ) ;
0 commit comments