@@ -5,10 +5,9 @@ use super::{CachedLlbb, FunctionCx, LocalRef};
55
66use crate :: base;
77use crate :: common:: { self , IntPredicate } ;
8- use crate :: errors:: {
9- CmseCallInputsStackSpill , CmseCallOutputStackSpill , CompilerBuiltinsCannotCall ,
10- } ;
8+ use crate :: errors:: CompilerBuiltinsCannotCall ;
119use crate :: meth;
10+ use crate :: mir:: cmse;
1211use crate :: traits:: * ;
1312use crate :: MemFlags ;
1413
@@ -836,58 +835,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
836835 // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
837836 let callee = self . codegen_operand ( bx, func) ;
838837
839- let fn_sig = callee. layout . ty . fn_sig ( bx. tcx ( ) ) . skip_binder ( ) ;
840-
841- if let rustc_target:: spec:: abi:: Abi :: CCmseNonSecureCall = fn_sig. abi {
842- let mut accum = 0u64 ;
843-
844- for arg_def in fn_sig. inputs ( ) . iter ( ) {
845- let layout = bx. layout_of ( * arg_def) ;
846-
847- let align = layout. layout . align ( ) . abi . bytes ( ) ;
848- let size = layout. layout . size ( ) . bytes ( ) ;
849-
850- accum += size;
851- accum = accum. next_multiple_of ( Ord :: max ( 4 , align) ) ;
852- }
853-
854- // the available argument space is 16 bytes (4 32-bit registers) in total
855- let available_space = 16 ;
856-
857- if accum > available_space {
858- let err = CmseCallInputsStackSpill { span, func_span : func. span ( self . mir ) } ;
859- bx. tcx ( ) . dcx ( ) . emit_err ( err) ;
860- }
861-
862- let mut ret_layout = bx. layout_of ( fn_sig. output ( ) ) ;
863-
864- // unwrap any `repr(transparent)` wrappers
865- loop {
866- if ret_layout. is_transparent :: < Bx > ( ) {
867- match ret_layout. non_1zst_field ( bx) {
868- None => break ,
869- Some ( ( _, layout) ) => ret_layout = layout,
870- }
871- } else {
872- break ;
873- }
874- }
875-
876- let valid_2register_return_types =
877- [ bx. tcx ( ) . types . i64 , bx. tcx ( ) . types . u64 , bx. tcx ( ) . types . f64 ] ;
878-
879- // A Composite Type larger than 4 bytes is stored in memory at an address
880- // passed as an extra argument when the function was called. That is not allowed
881- // for cmse_nonsecure_entry functions.
882- let is_valid_output = ret_layout. layout . size ( ) . bytes ( ) <= 4
883- || valid_2register_return_types. contains ( & ret_layout. ty ) ;
884-
885- if !is_valid_output {
886- let err = CmseCallOutputStackSpill { span, func_span : func. span ( self . mir ) } ;
887- bx. tcx ( ) . dcx ( ) . emit_err ( err) ;
888- }
889- }
890-
891838 let ( instance, mut llfn) = match * callee. layout . ty . kind ( ) {
892839 ty:: FnDef ( def_id, args) => (
893840 Some (
@@ -923,6 +870,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
923870 let sig = callee. layout . ty . fn_sig ( bx. tcx ( ) ) ;
924871 let abi = sig. abi ( ) ;
925872
873+ // emit errors if cmse ABI conditions are violated
874+ cmse:: validate_cmse_abi ( bx, & sig. skip_binder ( ) , span, func. span ( self . mir ) ) ;
875+
926876 let extra_args = & args[ sig. inputs ( ) . skip_binder ( ) . len ( ) ..] ;
927877 let extra_args = bx. tcx ( ) . mk_type_list_from_iter ( extra_args. iter ( ) . map ( |op_arg| {
928878 let op_ty = op_arg. node . ty ( self . mir , bx. tcx ( ) ) ;
0 commit comments