@@ -176,7 +176,36 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
176176 signature. fn_ty ( ) ,
177177 ) ;
178178
179- if signature. intrinsic ( ) . is_none ( ) {
179+ if let Some ( intrinsic) = signature. intrinsic ( ) {
180+ if intrinsic. is_target_specific ( ) {
181+ let ( llvm_arch, _) = name[ 5 ..] . split_once ( '.' ) . unwrap ( ) ;
182+ let target_arch = self . tcx . sess . target . arch . as_ref ( ) ;
183+
184+ let is_correct_arch = match llvm_arch {
185+ "aarch64" => matches ! ( target_arch, "aarch64" | "arm64ec" ) ,
186+ "amdgcn" => target_arch == "amdgpu" ,
187+ "arm" | "bpf" | "hexagon" => target_arch == llvm_arch,
188+ "loongarch" => matches ! ( target_arch, "loongarch32" | "loongarch64" ) ,
189+ "mips" => target_arch. starts_with ( "mips" ) ,
190+ "nvvm" => target_arch == "nvptx64" ,
191+ "ppc" => matches ! ( target_arch, "powerpc" | "powerpc64" ) ,
192+ "riscv" => matches ! ( target_arch, "riscv32" | "riscv64" ) ,
193+ "s390" => target_arch == "s390x" ,
194+ "spv" => target_arch == "spirv" ,
195+ "wasm" => matches ! ( target_arch, "wasm32" | "wasm64" ) ,
196+ "x86" => matches ! ( target_arch, "x86" | "x86_64" ) ,
197+ _ => true , // fallback for unknown archs
198+ } ;
199+
200+ if !is_correct_arch {
201+ self . tcx . dcx ( ) . emit_fatal ( errors:: IntrinsicWrongArch {
202+ name,
203+ target_arch,
204+ span : span ( ) ,
205+ } ) ;
206+ }
207+ }
208+ } else {
180209 // Don't apply any attributes to intrinsics, they will be applied by AutoUpgrade
181210 fn_abi. apply_attrs_llfn ( self , llfn, instance) ;
182211 }
0 commit comments