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