Skip to content

transmute + tuple access + eq on repr(simd)'s inner value seems UB to valgrind #113465

Open
@celinval

Description

@celinval

I tried this code:

#![feature(repr_simd)]
use std::mem::transmute;

#[derive(Clone, Debug)]
#[repr(simd)]
struct CustomSimd<T, const LANES: usize>([T; LANES]);

fn main() {
    let mut input : CustomSimd<u8, 10> = CustomSimd([0u8; 10]);
    input.0[0] = u8::MAX;
    let data = unsafe { transmute::<_, CustomSimd<u8, 10>>(input).0 };
    assert_eq!(data, [u8::MAX, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}

I expected to see this happen: I expected this test to succeed since the destination type is the same as the source type.

Instead, this happened: This test fails. When running it with valgrind, I get errors such as:

Conditional jump or move depends on uninitialised value(s)

Meta

I used the playground version:

Nightly channel
Build using the Nightly version: 1.72.0-nightly
(2023-07-06 85bf07972a1041b9e253)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-SIMDArea: SIMD (Single Instruction Multiple Data)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions