mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
check_align: we can still check low alignments on MSVC
This commit is contained in:
@@ -12,9 +12,6 @@
|
||||
|
||||
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
|
||||
fn is_enabled(&self, sess: &Session) -> bool {
|
||||
if sess.target.max_reliable_alignment() < Align::MAX {
|
||||
return false;
|
||||
}
|
||||
sess.ub_checks()
|
||||
}
|
||||
|
||||
@@ -87,6 +84,33 @@ fn insert_alignment_check<'tcx>(
|
||||
))),
|
||||
});
|
||||
|
||||
// If this target does not have reliable alignment, further limit the mask by anding it with
|
||||
// the mask for the highest reliable alignment.
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
if let max_align = tcx.sess.target.max_reliable_alignment()
|
||||
&& max_align < Align::MAX
|
||||
{
|
||||
let max_mask = max_align.bytes() - 1;
|
||||
let max_mask = Operand::Constant(Box::new(ConstOperand {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
const_: Const::Val(
|
||||
ConstValue::Scalar(Scalar::from_target_usize(max_mask, &tcx)),
|
||||
tcx.types.usize,
|
||||
),
|
||||
}));
|
||||
stmts.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
alignment_mask,
|
||||
Rvalue::BinaryOp(
|
||||
BinOp::BitAnd,
|
||||
Box::new((Operand::Copy(alignment_mask), max_mask)),
|
||||
),
|
||||
))),
|
||||
});
|
||||
}
|
||||
|
||||
// BitAnd the alignment mask with the pointer
|
||||
let alignment_bits =
|
||||
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
|
||||
|
||||
Reference in New Issue
Block a user