1
Fork 0

Fix rust-call ICE in mir-inliner

This commit is contained in:
Michael Goulet 2022-07-02 21:40:33 +00:00
parent 750d6f8545
commit 34063199d8
2 changed files with 12 additions and 5 deletions

View file

@ -180,16 +180,20 @@ impl<'tcx> Inliner<'tcx> {
return Err("failed to normalize return type"); return Err("failed to normalize return type");
} }
if callsite.fn_sig.abi() == Abi::RustCall { if callsite.fn_sig.abi() == Abi::RustCall {
let mut args = args.into_iter(); let (arg_tuple, skipped_args) = match &args[..] {
let _ = args.next(); // Skip `self` argument. [arg_tuple] => (arg_tuple, 0),
let arg_tuple_ty = args.next().unwrap().ty(&caller_body.local_decls, self.tcx); [_, arg_tuple] => (arg_tuple, 1),
assert!(args.next().is_none()); _ => bug!("Expected `rust-call` to have 1 or 2 args"),
};
let arg_tuple_ty = arg_tuple.ty(&caller_body.local_decls, self.tcx);
let ty::Tuple(arg_tuple_tys) = arg_tuple_ty.kind() else { let ty::Tuple(arg_tuple_tys) = arg_tuple_ty.kind() else {
bug!("Closure arguments are not passed as a tuple"); bug!("Closure arguments are not passed as a tuple");
}; };
for (arg_ty, input) in arg_tuple_tys.iter().zip(callee_body.args_iter().skip(1)) { for (arg_ty, input) in
arg_tuple_tys.iter().zip(callee_body.args_iter().skip(skipped_args))
{
let input_type = callee_body.local_decls[input].ty; let input_type = callee_body.local_decls[input].ty;
if !equal_up_to_regions(self.tcx, self.param_env, arg_ty, input_type) { if !equal_up_to_regions(self.tcx, self.param_env, arg_ty, input_type) {
trace!(?arg_ty, ?input_type); trace!(?arg_ty, ?input_type);

View file

@ -1,4 +1,7 @@
// revisions: normal opt
// check-pass // check-pass
//[opt] compile-flags: -Zmir-opt-level=3
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
extern "rust-call" fn foo<T>(_: T) {} extern "rust-call" fn foo<T>(_: T) {}