@@ -8,8 +8,11 @@ use std::borrow::Cow;
88
99use cranelift_codegen:: ir:: SigRef ;
1010use cranelift_module:: ModuleError ;
11+ use rustc_codegen_ssa:: errors:: CompilerBuiltinsCannotCall ;
1112use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
1213use rustc_middle:: ty:: layout:: FnAbiOf ;
14+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
15+ use rustc_monomorphize:: is_call_from_compiler_builtins_to_upstream_monomorphization;
1316use rustc_session:: Session ;
1417use rustc_span:: source_map:: Spanned ;
1518use rustc_target:: abi:: call:: { Conv , FnAbi } ;
@@ -372,6 +375,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
372375 ty:: Instance :: expect_resolve ( fx. tcx , ty:: ParamEnv :: reveal_all ( ) , def_id, fn_args)
373376 . polymorphize ( fx. tcx ) ;
374377
378+ if is_call_from_compiler_builtins_to_upstream_monomorphization ( fx. tcx , instance) {
379+ if target. is_some ( ) {
380+ let caller = with_no_trimmed_paths ! ( fx. tcx. def_path_str( fx. instance. def_id( ) ) ) ;
381+ let callee = with_no_trimmed_paths ! ( fx. tcx. def_path_str( def_id) ) ;
382+ fx. tcx . dcx ( ) . emit_err ( CompilerBuiltinsCannotCall { caller, callee } ) ;
383+ } else {
384+ fx. bcx . ins ( ) . trap ( TrapCode :: User ( 0 ) ) ;
385+ return ;
386+ }
387+ }
388+
375389 if fx. tcx . symbol_name ( instance) . name . starts_with ( "llvm." ) {
376390 crate :: intrinsics:: codegen_llvm_intrinsic_call (
377391 fx,
@@ -663,11 +677,7 @@ pub(crate) fn codegen_drop<'tcx>(
663677
664678 let arg_value = drop_place. place_ref (
665679 fx,
666- fx. layout_of ( Ty :: new_ref (
667- fx. tcx ,
668- fx. tcx . lifetimes . re_erased ,
669- TypeAndMut { ty, mutbl : crate :: rustc_hir:: Mutability :: Mut } ,
670- ) ) ,
680+ fx. layout_of ( Ty :: new_mut_ref ( fx. tcx , fx. tcx . lifetimes . re_erased , ty) ) ,
671681 ) ;
672682 let arg_value = adjust_arg_for_abi ( fx, arg_value, & fn_abi. args [ 0 ] , true ) ;
673683
0 commit comments