Skip to content

checked arithmetic not treated as constant in debug builds #38074

Closed
@BurntSushi

Description

@BurntSushi

This code produces a compiler error with rustc foo.rs but compiles successfully with rustc -O foo.rs:

#![feature(platform_intrinsics, repr_simd)]

extern "platform-intrinsic" {
    fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
}

#[repr(simd)]
#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
struct u64x2(u64, u64);

fn main() {
    let a = u64x2(1, 2);
    let r: u64x2 = unsafe { simd_shuffle2(a, a, [0-0, 0-0]) };
    assert_eq!(r.0, 1);
    assert_eq!(r.1, 1);
}

The error is:

$ rustc shuffle.rs 
error[E0526]: shuffle indices are not constant
  --> shuffle.rs:14:29
   |
14 |     let r: u64x2 = unsafe { simd_shuffle2(a, a, [0-0, 0-0]) };
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions