Make simd_extract panic at runtime on non-const index again

This is necessary to compile packed_simd
This commit is contained in:
bjorn3 2020-11-23 11:48:53 +01:00
parent d2eeed4ff5
commit e99f78af08
2 changed files with 20 additions and 1 deletions

View File

@ -146,10 +146,17 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
idx_const
} else {
fx.tcx.sess.span_fatal(
fx.tcx.sess.span_warn(
span,
"Index argument for `simd_extract` is not a constant",
);
let res = crate::trap::trap_unimplemented_ret_value(
fx,
ret.layout(),
"Index argument for `simd_extract` is not a constant",
);
ret.write_cvalue(fx, res);
return;
};
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));

View File

@ -67,3 +67,15 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg:
let true_ = fx.bcx.ins().iconst(types::I32, 1);
fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
}
/// Like `trap_unimplemented` but returns a fake value of the specified type.
///
/// Trap code: user65535
pub(crate) fn trap_unimplemented_ret_value<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
dest_layout: TyAndLayout<'tcx>,
msg: impl AsRef<str>,
) -> CValue<'tcx> {
trap_unimplemented(fx, msg);
CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
}