Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SIMD field access #2660

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ impl<'tcx> GotocCtx<'tcx> {
field: FieldIdx,
field_ty: Ty<'tcx>,
) -> Expr {
let field_ty = self.monomorphize(field_ty);
if matches!(field_ty.kind(), ty::Array { .. }) {
// Array based
assert_eq!(field.index(), 0);
Expand Down
50 changes: 50 additions & 0 deletions tests/kani/SIMD/generic_access.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Ensure we can use a generic function to access field of `repr_simd`.
#![feature(portable_simd, repr_simd)]

use std::simd::SimdElement;

mod array_based {
use super::*;

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

fn check_fields<T: SimdElement + PartialEq, const LANES: usize>(
simd: CustomSimd<T, LANES>,
expected: [T; LANES],
) {
assert_eq!(simd.0, expected);
}

#[kani::proof]
fn check_field_access() {
let data: [u8; 16] = kani::any();
let vec = CustomSimd(data.clone());
check_fields(vec, data);
}
}

mod fields_based {
use super::*;

#[repr(simd)]
struct CustomSimd<T: SimdElement>(T, T);

fn check_fields<T: SimdElement + PartialEq, const LANES: usize>(
simd: CustomSimd<T>,
expected: [T; LANES],
) {
assert_eq!(simd.0, expected[0]);
assert_eq!(simd.1, expected[1])
}

#[kani::proof]
fn check_field_access() {
let data: [u8; 16] = kani::any();
let vec = CustomSimd(data[0], data[1]);
check_fields(vec, data);
}
}