Skip to content

Commit 811868e

Browse files
committed
Auto merge of #28103 - GuillaumeGomez:fix-intrinsic, r=huonw
Fixes #28062
2 parents 8f28c9b + bc024d2 commit 811868e

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/librustc_typeck/check/intrinsic.rs

+7
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
408408
let mut structural_to_nomimal = HashMap::new();
409409

410410
let sig = tcx.no_late_bound_regions(i_ty.ty.fn_sig()).unwrap();
411+
if intr.inputs.len() != sig.inputs.len() {
412+
span_err!(tcx.sess, it.span, E0444,
413+
"platform-specific intrinsic has invalid number of \
414+
arguments: found {}, expected {}",
415+
intr.inputs.len(), sig.inputs.len());
416+
return
417+
}
411418
let input_pairs = intr.inputs.iter().zip(&sig.inputs);
412419
for (i, (expected_arg, arg)) in input_pairs.enumerate() {
413420
match_intrinsic_type_to_type(tcx, &format!("argument {}", i + 1), it.span,

src/librustc_typeck/diagnostics.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,34 @@ PhantomData can also be used to express information about unused type
30183018
parameters. You can read more about it in the API documentation:
30193019
30203020
https://doc.rust-lang.org/std/marker/struct.PhantomData.html
3021-
"##
3021+
"##,
3022+
3023+
E0444: r##"
3024+
A platform-specific intrinsic function has wrong number of arguments.
3025+
Erroneous code example:
3026+
3027+
```
3028+
#[repr(simd)]
3029+
struct f64x2(f64, f64);
3030+
3031+
extern "platform-intrinsic" {
3032+
fn x86_mm_movemask_pd(x: f64x2, y: f64x2, z: f64x2) -> i32;
3033+
// error: platform-specific intrinsic has invalid number of arguments
3034+
}
3035+
```
3036+
3037+
Please refer to the function declaration to see if it corresponds
3038+
with yours. Example:
3039+
3040+
```
3041+
#[repr(simd)]
3042+
struct f64x2(f64, f64);
3043+
3044+
extern "platform-intrinsic" {
3045+
fn x86_mm_movemask_pd(x: f64x2) -> i32; // ok!
3046+
}
3047+
```
3048+
"##,
30223049

30233050
}
30243051

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test number of arguments in platform-specific intrinsic function
12+
// This is the error E0444
13+
14+
#![feature(repr_simd, platform_intrinsics)]
15+
16+
#[repr(simd)]
17+
struct f64x2(f64, f64);
18+
19+
extern "platform-intrinsic" {
20+
fn x86_mm_movemask_pd(x: f64x2, y: f64x2, z: f64x2) -> i32; //~ platform-specific intrinsic
21+
}
22+
23+
pub fn main() {
24+
}

0 commit comments

Comments
 (0)