mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-20 19:04:21 +00:00
Improve consistency in LowerIntrinsics
.
In some cases `target` and `arg` are obtained fallibly, and in some cases they are obtained infallibly. This commit changes them all to infallible.
This commit is contained in:
parent
751c8b481b
commit
5445953659
@ -35,20 +35,19 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
sym::forget => {
|
sym::forget => {
|
||||||
if let Some(target) = *target {
|
let target = target.unwrap();
|
||||||
block.statements.push(Statement {
|
block.statements.push(Statement {
|
||||||
source_info: terminator.source_info,
|
source_info: terminator.source_info,
|
||||||
kind: StatementKind::Assign(Box::new((
|
kind: StatementKind::Assign(Box::new((
|
||||||
*destination,
|
*destination,
|
||||||
Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
|
Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
|
||||||
span: terminator.source_info.span,
|
span: terminator.source_info.span,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
const_: Const::zero_sized(tcx.types.unit),
|
const_: Const::zero_sized(tcx.types.unit),
|
||||||
}))),
|
}))),
|
||||||
))),
|
))),
|
||||||
});
|
});
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sym::copy_nonoverlapping => {
|
sym::copy_nonoverlapping => {
|
||||||
let target = target.unwrap();
|
let target = target.unwrap();
|
||||||
@ -121,43 +120,41 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
||||||
if let Some(target) = *target {
|
let target = target.unwrap();
|
||||||
let Ok([lhs, rhs]) = take_array(args) else {
|
let Ok([lhs, rhs]) = take_array(args) else {
|
||||||
bug!("Wrong arguments for {} intrinsic", intrinsic.name);
|
bug!("Wrong arguments for {} intrinsic", intrinsic.name);
|
||||||
};
|
};
|
||||||
let bin_op = match intrinsic.name {
|
let bin_op = match intrinsic.name {
|
||||||
sym::add_with_overflow => BinOp::AddWithOverflow,
|
sym::add_with_overflow => BinOp::AddWithOverflow,
|
||||||
sym::sub_with_overflow => BinOp::SubWithOverflow,
|
sym::sub_with_overflow => BinOp::SubWithOverflow,
|
||||||
sym::mul_with_overflow => BinOp::MulWithOverflow,
|
sym::mul_with_overflow => BinOp::MulWithOverflow,
|
||||||
_ => bug!("unexpected intrinsic"),
|
_ => bug!("unexpected intrinsic"),
|
||||||
};
|
};
|
||||||
block.statements.push(Statement {
|
block.statements.push(Statement {
|
||||||
source_info: terminator.source_info,
|
source_info: terminator.source_info,
|
||||||
kind: StatementKind::Assign(Box::new((
|
kind: StatementKind::Assign(Box::new((
|
||||||
*destination,
|
*destination,
|
||||||
Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
|
Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
|
||||||
))),
|
))),
|
||||||
});
|
});
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sym::size_of | sym::min_align_of => {
|
sym::size_of | sym::min_align_of => {
|
||||||
if let Some(target) = *target {
|
let target = target.unwrap();
|
||||||
let tp_ty = generic_args.type_at(0);
|
let tp_ty = generic_args.type_at(0);
|
||||||
let null_op = match intrinsic.name {
|
let null_op = match intrinsic.name {
|
||||||
sym::size_of => NullOp::SizeOf,
|
sym::size_of => NullOp::SizeOf,
|
||||||
sym::min_align_of => NullOp::AlignOf,
|
sym::min_align_of => NullOp::AlignOf,
|
||||||
_ => bug!("unexpected intrinsic"),
|
_ => bug!("unexpected intrinsic"),
|
||||||
};
|
};
|
||||||
block.statements.push(Statement {
|
block.statements.push(Statement {
|
||||||
source_info: terminator.source_info,
|
source_info: terminator.source_info,
|
||||||
kind: StatementKind::Assign(Box::new((
|
kind: StatementKind::Assign(Box::new((
|
||||||
*destination,
|
*destination,
|
||||||
Rvalue::NullaryOp(null_op, tp_ty),
|
Rvalue::NullaryOp(null_op, tp_ty),
|
||||||
))),
|
))),
|
||||||
});
|
});
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sym::read_via_copy => {
|
sym::read_via_copy => {
|
||||||
let Ok([arg]) = take_array(args) else {
|
let Ok([arg]) = take_array(args) else {
|
||||||
@ -219,17 +216,23 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
sym::discriminant_value => {
|
sym::discriminant_value => {
|
||||||
if let (Some(target), Some(arg)) = (*target, args[0].node.place()) {
|
let target = target.unwrap();
|
||||||
let arg = tcx.mk_place_deref(arg);
|
let Ok([arg]) = take_array(args) else {
|
||||||
block.statements.push(Statement {
|
span_bug!(
|
||||||
source_info: terminator.source_info,
|
terminator.source_info.span,
|
||||||
kind: StatementKind::Assign(Box::new((
|
"Wrong arguments for discriminant_value intrinsic"
|
||||||
*destination,
|
);
|
||||||
Rvalue::Discriminant(arg),
|
};
|
||||||
))),
|
let arg = arg.node.place().unwrap();
|
||||||
});
|
let arg = tcx.mk_place_deref(arg);
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
block.statements.push(Statement {
|
||||||
}
|
source_info: terminator.source_info,
|
||||||
|
kind: StatementKind::Assign(Box::new((
|
||||||
|
*destination,
|
||||||
|
Rvalue::Discriminant(arg),
|
||||||
|
))),
|
||||||
|
});
|
||||||
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
sym::offset => {
|
sym::offset => {
|
||||||
let target = target.unwrap();
|
let target = target.unwrap();
|
||||||
@ -267,7 +270,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||||||
Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty),
|
Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty),
|
||||||
))),
|
))),
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(target) = *target {
|
if let Some(target) = *target {
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
} else {
|
} else {
|
||||||
@ -299,7 +301,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||||||
Rvalue::Aggregate(Box::new(kind), fields.into()),
|
Rvalue::Aggregate(Box::new(kind), fields.into()),
|
||||||
))),
|
))),
|
||||||
});
|
});
|
||||||
|
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
sym::ptr_metadata => {
|
sym::ptr_metadata => {
|
||||||
|
Loading…
Reference in New Issue
Block a user