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