Codegen SetDiscriminant after field assignment.
This matches the order in which deaggregation was performed.
This commit is contained in:
parent
feccf469fb
commit
20dd5e09fd
1 changed files with 11 additions and 15 deletions
|
@ -107,21 +107,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
mir::Rvalue::Aggregate(ref kind, ref operands) => {
|
mir::Rvalue::Aggregate(ref kind, ref operands) => {
|
||||||
let (dest, active_field_index) = match **kind {
|
let (variant_index, variant_dest, active_field_index) = match **kind {
|
||||||
mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
|
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
|
||||||
dest.codegen_set_discr(bx, variant_index);
|
let variant_dest = dest.project_downcast(bx, variant_index);
|
||||||
if bx.tcx().adt_def(adt_did).is_enum() {
|
(variant_index, variant_dest, active_field_index)
|
||||||
(dest.project_downcast(bx, variant_index), active_field_index)
|
|
||||||
} else {
|
|
||||||
(dest, active_field_index)
|
|
||||||
}
|
}
|
||||||
}
|
_ => (VariantIdx::from_u32(0), dest, None),
|
||||||
mir::AggregateKind::Generator(..) => {
|
|
||||||
dest.codegen_set_discr(bx, VariantIdx::from_u32(0));
|
|
||||||
(dest, None)
|
|
||||||
}
|
|
||||||
_ => (dest, None),
|
|
||||||
};
|
};
|
||||||
|
if active_field_index.is_some() {
|
||||||
|
assert_eq!(operands.len(), 1);
|
||||||
|
}
|
||||||
for (i, operand) in operands.iter().enumerate() {
|
for (i, operand) in operands.iter().enumerate() {
|
||||||
let op = self.codegen_operand(bx, operand);
|
let op = self.codegen_operand(bx, operand);
|
||||||
// Do not generate stores and GEPis for zero-sized fields.
|
// Do not generate stores and GEPis for zero-sized fields.
|
||||||
|
@ -129,13 +124,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
let field_index = active_field_index.unwrap_or(i);
|
let field_index = active_field_index.unwrap_or(i);
|
||||||
let field = if let mir::AggregateKind::Array(_) = **kind {
|
let field = if let mir::AggregateKind::Array(_) = **kind {
|
||||||
let llindex = bx.cx().const_usize(field_index as u64);
|
let llindex = bx.cx().const_usize(field_index as u64);
|
||||||
dest.project_index(bx, llindex)
|
variant_dest.project_index(bx, llindex)
|
||||||
} else {
|
} else {
|
||||||
dest.project_field(bx, field_index)
|
variant_dest.project_field(bx, field_index)
|
||||||
};
|
};
|
||||||
op.val.store(bx, field);
|
op.val.store(bx, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dest.codegen_set_discr(bx, variant_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue