@@ -18,6 +18,7 @@ use rustc_codegen_ssa::traits::TypeMembershipCodegenMethods;
1818use rustc_data_structures:: fx:: FxIndexSet ;
1919use rustc_middle:: ty:: { Instance , Ty } ;
2020use rustc_sanitizers:: { cfi, kcfi} ;
21+ use rustc_session:: lint:: builtin:: { DEPRECATED_LLVM_INTRINSIC , UNKNOWN_LLVM_INTRINSIC } ;
2122use rustc_target:: callconv:: FnAbi ;
2223use smallvec:: SmallVec ;
2324use tracing:: debug;
@@ -216,22 +217,32 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
216217 let can_upgrade =
217218 unsafe { llvm:: LLVMRustUpgradeIntrinsicFunction ( llfn, & mut new_llfn, false ) } ;
218219
219- if can_upgrade {
220- // not all intrinsics are upgraded to some other intrinsics, most are upgraded to instruction sequences
221- if let Some ( new_llfn) = new_llfn {
222- self . tcx . dcx ( ) . emit_note ( errors:: DeprecatedIntrinsicWithReplacement {
223- name,
224- replacement : str:: from_utf8 ( & llvm:: get_value_name ( new_llfn) ) . unwrap ( ) ,
225- span : span ( ) ,
220+ // we can emit diagnostics for local crates only
221+ if let Some ( instance) = instance
222+ && let Some ( local_def_id) = instance. def_id ( ) . as_local ( )
223+ {
224+ let hir_id = self . tcx . local_def_id_to_hir_id ( local_def_id) ;
225+ let span = self . tcx . def_span ( local_def_id) ;
226+
227+ if can_upgrade {
228+ // not all intrinsics are upgraded to some other intrinsics, most are upgraded to instruction sequences
229+ let msg = if let Some ( new_llfn) = new_llfn {
230+ format ! (
231+ "Using deprecated intrinsic `{name}`, `{}` can be used instead" ,
232+ str :: from_utf8( & llvm:: get_value_name( new_llfn) ) . unwrap( )
233+ )
234+ } else {
235+ format ! ( "Using deprecated intrinsic `{name}`" )
236+ } ;
237+ self . tcx . node_lint ( DEPRECATED_LLVM_INTRINSIC , hir_id, |d| {
238+ d. primary_message ( msg) . span ( span) ;
239+ } ) ;
240+ } else {
241+ // This is either plain wrong, or this can be caused by incompatible LLVM versions, we let the user decide
242+ self . tcx . node_lint ( UNKNOWN_LLVM_INTRINSIC , hir_id, |d| {
243+ d. primary_message ( format ! ( "Invalid LLVM Intrinsic `{name}`" ) ) . span ( span) ;
226244 } ) ;
227- } else if self . tcx . sess . opts . verbose {
228- // At least for now, we are only emitting notes for deprecated intrinsics with no direct replacement
229- // because they are used quite a lot in stdarch. After the stdarch uses has been removed, we can make
230- // this always emit a note (or even an warning)
231- self . tcx . dcx ( ) . emit_note ( errors:: DeprecatedIntrinsic { name, span : span ( ) } ) ;
232245 }
233- } else {
234- self . tcx . dcx ( ) . emit_fatal ( errors:: InvalidIntrinsic { name, span : span ( ) } ) ;
235246 }
236247 }
237248
0 commit comments