Skip to content

Commit e99f78a

Browse files
committed
Make simd_extract panic at runtime on non-const index again
This is necessary to compile packed_simd
1 parent d2eeed4 commit e99f78a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/intrinsics/simd.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,17 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
146146
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
147147
idx_const
148148
} else {
149-
fx.tcx.sess.span_fatal(
149+
fx.tcx.sess.span_warn(
150150
span,
151151
"Index argument for `simd_extract` is not a constant",
152152
);
153+
let res = crate::trap::trap_unimplemented_ret_value(
154+
fx,
155+
ret.layout(),
156+
"Index argument for `simd_extract` is not a constant",
157+
);
158+
ret.write_cvalue(fx, res);
159+
return;
153160
};
154161

155162
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));

src/trap.rs

+12
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,15 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg:
6767
let true_ = fx.bcx.ins().iconst(types::I32, 1);
6868
fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
6969
}
70+
71+
/// Like `trap_unimplemented` but returns a fake value of the specified type.
72+
///
73+
/// Trap code: user65535
74+
pub(crate) fn trap_unimplemented_ret_value<'tcx>(
75+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
76+
dest_layout: TyAndLayout<'tcx>,
77+
msg: impl AsRef<str>,
78+
) -> CValue<'tcx> {
79+
trap_unimplemented(fx, msg);
80+
CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
81+
}

0 commit comments

Comments
 (0)