Skip to content

Commit

Permalink
Make simd_extract panic at runtime on non-const index again
Browse files Browse the repository at this point in the history
This is necessary to compile packed_simd
  • Loading branch information
bjorn3 committed Nov 23, 2020
1 parent d2eeed4 commit e99f78a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/intrinsics/simd.rs
Expand Up @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions src/trap.rs
Expand Up @@ -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)
}

0 comments on commit e99f78a

Please sign in to comment.