Skip to content

Commit b03ca7f

Browse files
committed
Separate integers into signed and unsigned.
This is necessary to reflect the ARM APIs accurately, since some functions explicitly take an unsigned parameter and a signed one, of the same integer shape, so the no-duplicates check will fail unless we distinguish.
1 parent f578735 commit b03ca7f

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

src/librustc_platform_intrinsics/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct Intrinsic {
3030

3131
#[derive(Clone, Hash, Eq, PartialEq)]
3232
pub enum Type {
33-
Integer(u8),
33+
Integer(/* signed */ bool, u8),
3434
Float(u8),
3535
Pointer(Box<Type>),
3636
Vector(Box<Type>, u8),
@@ -40,7 +40,8 @@ pub enum IntrinsicDef {
4040
Named(&'static str),
4141
}
4242

43-
fn i(width: u8) -> Type { Type::Integer(width) }
43+
fn i(width: u8) -> Type { Type::Integer(true, width) }
44+
fn u(width: u8) -> Type { Type::Integer(false, width) }
4445
fn f(width: u8) -> Type { Type::Float(width) }
4546
fn v(x: Type, length: u8) -> Type { Type::Vector(Box::new(x), length) }
4647

src/librustc_trans/trans/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
927927
fn ty_to_type(ccx: &CrateContext, t: &intrinsics::Type) -> Type {
928928
use intrinsics::Type::*;
929929
match *t {
930-
Integer(x) => Type::ix(ccx, x as u64),
930+
Integer(_signed, x) => Type::ix(ccx, x as u64),
931931
Float(x) => {
932932
match x {
933933
32 => Type::f32(ccx),

src/librustc_typeck/check/intrinsic.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,15 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
456456
};
457457

458458
match *expected {
459-
Integer(bits) => match (bits, &t.sty) {
460-
(8, &ty::TyInt(ast::TyI8)) | (8, &ty::TyUint(ast::TyU8)) |
461-
(16, &ty::TyInt(ast::TyI16)) | (16, &ty::TyUint(ast::TyU16)) |
462-
(32, &ty::TyInt(ast::TyI32)) | (32, &ty::TyUint(ast::TyU32)) |
463-
(64, &ty::TyInt(ast::TyI64)) | (64, &ty::TyUint(ast::TyU64)) => {},
459+
Integer(signed, bits) => match (signed, bits, &t.sty) {
460+
(true, 8, &ty::TyInt(ast::TyI8)) | (false, 8, &ty::TyUint(ast::TyU8)) |
461+
(true, 16, &ty::TyInt(ast::TyI16)) | (false, 16, &ty::TyUint(ast::TyU16)) |
462+
(true, 32, &ty::TyInt(ast::TyI32)) | (false, 32, &ty::TyUint(ast::TyU32)) |
463+
(true, 64, &ty::TyInt(ast::TyI64)) | (false, 64, &ty::TyUint(ast::TyU64)) => {},
464464
_ => simple_error(&format!("`{}`", t),
465-
&format!("`i{n}` or `u{n}`", n = bits)),
465+
&format!("`{}{n}`",
466+
if signed {"i"} else {"u"},
467+
n = bits)),
466468
},
467469
Float(bits) => match (bits, &t.sty) {
468470
(32, &ty::TyFloat(ast::TyF32)) |

src/test/compile-fail/simd-intrinsic-declaration-type.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,38 @@ struct f32x4(f32, f32, f32, f32);
2525
#[repr(simd)]
2626
struct i64x2(i64, i64);
2727

28-
// signed vs. unsigned doesn't matter
29-
mod i {
30-
use i16x8;
28+
// correct signatures work well
29+
mod right {
30+
use {i16x8, u16x8};
3131
extern "platform-intrinsic" {
3232
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8;
33+
fn x86_mm_adds_epu16(x: u16x8, y: u16x8) -> u16x8;
3334
}
3435
}
35-
mod u {
36-
use u16x8;
36+
// but incorrect ones don't.
37+
38+
mod signedness {
39+
use {i16x8, u16x8};
40+
// signedness matters
3741
extern "platform-intrinsic" {
3842
fn x86_mm_adds_epi16(x: u16x8, y: u16x8) -> u16x8;
43+
//~^ ERROR intrinsic argument 1 has wrong type
44+
//~^^ ERROR intrinsic argument 2 has wrong type
45+
//~^^^ ERROR intrinsic return value has wrong type
46+
fn x86_mm_adds_epu16(x: i16x8, y: i16x8) -> i16x8;
47+
//~^ ERROR intrinsic argument 1 has wrong type
48+
//~^^ ERROR intrinsic argument 2 has wrong type
49+
//~^^^ ERROR intrinsic return value has wrong type
3950
}
4051
}
41-
// but lengths do
52+
// as do lengths
4253
extern "platform-intrinsic" {
4354
fn x86_mm_adds_epi16(x: i8x16, y: i32x4) -> i64x2;
4455
//~^ ERROR intrinsic argument 1 has wrong type
4556
//~^^ ERROR intrinsic argument 2 has wrong type
4657
//~^^^ ERROR intrinsic return value has wrong type
4758
}
48-
// and so does int vs. float
59+
// and so does int vs. float:
4960
extern "platform-intrinsic" {
5061
fn x86_mm_max_ps(x: i32x4, y: i32x4) -> i32x4;
5162
//~^ ERROR intrinsic argument 1 has wrong type

0 commit comments

Comments
 (0)