@@ -12,7 +12,10 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
1212use rustc_target:: abi:: call:: { FnAbi , PassMode } ;
1313use rustc_target:: abi:: { BackendRepr , RegKind } ;
1414
15- use crate :: errors:: { AbiErrorDisabledVectorTypeCall , AbiErrorDisabledVectorTypeDef } ;
15+ use crate :: errors:: {
16+ AbiErrorDisabledVectorTypeCall , AbiErrorDisabledVectorTypeDef ,
17+ AbiErrorUnsupportedVectorTypeCall , AbiErrorUnsupportedVectorTypeDef ,
18+ } ;
1619
1720fn uses_vector_registers ( mode : & PassMode , repr : & BackendRepr ) -> bool {
1821 match mode {
@@ -25,11 +28,15 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2528 }
2629}
2730
31+ /// Checks whether a certain function ABI is compatible with the target features currently enabled
32+ /// for a certain function.
33+ /// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
34+ /// with `None` if no feature is known that would make the ABI compatible.
2835fn do_check_abi < ' tcx > (
2936 tcx : TyCtxt < ' tcx > ,
3037 abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
3138 target_feature_def : DefId ,
32- mut emit_err : impl FnMut ( & ' static str ) ,
39+ mut emit_err : impl FnMut ( Option < & ' static str > ) ,
3340) {
3441 let Some ( feature_def) = tcx. sess . target . features_for_correct_vector_abi ( ) else {
3542 return ;
@@ -42,15 +49,15 @@ fn do_check_abi<'tcx>(
4249 let feature = match feature_def. iter ( ) . find ( |( bits, _) | size. bits ( ) <= * bits) {
4350 Some ( ( _, feature) ) => feature,
4451 None => {
45- emit_err ( "<no available feature for this size>" ) ;
52+ emit_err ( None ) ;
4653 continue ;
4754 }
4855 } ;
4956 let feature_sym = Symbol :: intern ( feature) ;
5057 if !tcx. sess . unstable_target_features . contains ( & feature_sym)
5158 && !codegen_attrs. target_features . iter ( ) . any ( |x| x. name == feature_sym)
5259 {
53- emit_err ( feature) ;
60+ emit_err ( Some ( & feature) ) ;
5461 }
5562 }
5663 }
@@ -67,12 +74,21 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6774 } ;
6875 do_check_abi ( tcx, abi, instance. def_id ( ) , |required_feature| {
6976 let span = tcx. def_span ( instance. def_id ( ) ) ;
70- tcx. emit_node_span_lint (
71- ABI_UNSUPPORTED_VECTOR_TYPES ,
72- CRATE_HIR_ID ,
73- span,
74- AbiErrorDisabledVectorTypeDef { span, required_feature } ,
75- ) ;
77+ if let Some ( required_feature) = required_feature {
78+ tcx. emit_node_span_lint (
79+ ABI_UNSUPPORTED_VECTOR_TYPES ,
80+ CRATE_HIR_ID ,
81+ span,
82+ AbiErrorDisabledVectorTypeDef { span, required_feature } ,
83+ ) ;
84+ } else {
85+ tcx. emit_node_span_lint (
86+ ABI_UNSUPPORTED_VECTOR_TYPES ,
87+ CRATE_HIR_ID ,
88+ span,
89+ AbiErrorUnsupportedVectorTypeDef { span } ,
90+ ) ;
91+ }
7692 } )
7793}
7894
@@ -111,12 +127,21 @@ fn check_call_site_abi<'tcx>(
111127 return ;
112128 } ;
113129 do_check_abi ( tcx, callee_abi, caller. def_id ( ) , |required_feature| {
114- tcx. emit_node_span_lint (
115- ABI_UNSUPPORTED_VECTOR_TYPES ,
116- CRATE_HIR_ID ,
117- span,
118- AbiErrorDisabledVectorTypeCall { span, required_feature } ,
119- ) ;
130+ if let Some ( required_feature) = required_feature {
131+ tcx. emit_node_span_lint (
132+ ABI_UNSUPPORTED_VECTOR_TYPES ,
133+ CRATE_HIR_ID ,
134+ span,
135+ AbiErrorDisabledVectorTypeCall { span, required_feature } ,
136+ ) ;
137+ } else {
138+ tcx. emit_node_span_lint (
139+ ABI_UNSUPPORTED_VECTOR_TYPES ,
140+ CRATE_HIR_ID ,
141+ span,
142+ AbiErrorUnsupportedVectorTypeCall { span } ,
143+ ) ;
144+ }
120145 } ) ;
121146}
122147
0 commit comments