Skip to content

Commit 10ee80c

Browse files
committed
Write dummy return value on unimplemented simd_{insert,extract}
Fixes #919
1 parent 9fd8b84 commit 10ee80c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/intrinsics/simd.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
127127
fx.mir.span,
128128
"`simd_insert` is not yet implemented. Calling this function will panic.",
129129
);
130-
crate::trap::trap_unimplemented(fx, "`simd_insert` is not yet implemented");
130+
let val = crate::trap::trap_unimplemented_ret_value(fx, ret.layout(), "`simd_insert` is not yet implemented");
131+
ret.write_cvalue(fx, val);
131132
};
132133

133134
simd_extract, (c v, o idx) {
@@ -138,7 +139,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
138139
fx.mir.span,
139140
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
140141
);
141-
crate::trap::trap_unimplemented(fx, "`#[rustc_arg_required_const(..)]` is not yet supported.");
142+
let val = crate::trap::trap_unimplemented_ret_value(fx, ret.layout(), "`#[rustc_arg_required_const(..)]` is not yet supported.");
143+
ret.write_cvalue(fx, val);
142144
return;
143145
};
144146

src/trap.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub fn trap_unreachable(
7575
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
7676
}
7777

78+
/// Like `trap_unreachable` but returns a fake value of the specified type.
79+
///
80+
/// Trap code: user65535
81+
pub fn trap_unreachable_ret_value<'tcx>(
82+
fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>,
83+
dest_layout: TyLayout<'tcx>,
84+
msg: impl AsRef<str>,
85+
) -> CValue<'tcx> {
86+
trap_unreachable(fx, msg);
87+
CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
88+
}
89+
7890
/// Use this when something is unimplemented, but `libcore` or `libstd` requires it to codegen.
7991
/// Unlike `trap_unreachable` this will not fill the current block, so you **must** add instructions
8092
/// to it afterwards.
@@ -89,10 +101,10 @@ pub fn trap_unimplemented(
89101
fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
90102
}
91103

92-
/// Like `trap_unreachable` but returns a fake value of the specified type.
104+
/// Like `trap_unimplemented` but returns a fake value of the specified type.
93105
///
94106
/// Trap code: user65535
95-
pub fn trap_unreachable_ret_value<'tcx>(
107+
pub fn trap_unimplemented_ret_value<'tcx>(
96108
fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>,
97109
dest_layout: TyLayout<'tcx>,
98110
msg: impl AsRef<str>,

0 commit comments

Comments
 (0)