Skip to content

Projection mismatch when declaring array-based SIMD #2264

Closed as not planned
Closed as not planned

Description

@matthiaskrgr

I tried this code:

#![feature(repr_simd, platform_intrinsics)]

extern "platform-intrinsic" {
    fn simd_as<T, U>(x: T) -> U;
}

#[derive(Copy, Clone)]
#[repr(simd)]
struct V<T>([T; 2]);

#[kani::proof]
fn main() {
    unsafe {
        let u = V::<u32>([u32::MIN, u32::MAX]);
        let i: V<i16> = simd_as(u);
    }
}

using the following command line invocation:


with Kani version: 0.22.0

I expected to see this happen: explanation

Instead, this happened: explanation

warning: unused variable: `i`
  --> generic-as.rs:15:13
   |
15 |         let i: V<i16> = simd_as(u);
   |             ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

 WARN kani_compiler::codegen_cprover_gotoc::codegen::place Unexpected type mismatch in projection:
Expr { value: Index { array: Expr { value: Symbol { identifier: "main::1::var_1::u" }, typ: Vector { typ: Unsignedbv { width: 32 }, size: 2 }, location: None }, index: Expr { value: IntConstant(0), typ: CInteger(SizeT), location: None } }, typ: Unsignedbv { width: 32 }, location: None }
Expr type
Unsignedbv { width: 32 }
Type from MIR
StructTag("tag-[_18349839772473174998; 2]")
warning: Found the following unsupported constructs:
             - Projection mismatch (1)
             - simd_as (1)

         Verification will fail if one or more of these constructs is reachable.
         See https://model-checking.github.io/kani/rust-feature-support.html for more details.

warning: 2 warnings emitted

Checking harness main...
CBMC 5.77.0 (cbmc-5.77.0)
CBMC version 5.77.0 (cbmc-5.77.0) 64-bit x86_64 linux
Reading GOTO program from file /tmp/kani/generic_as.for-main.out
Generating GOTO Program
Adding CPROVER library (x86_64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 16 object bits, 48 offset bits (user-specified)
Starting Bounded Model Checking
aborting path on assume(false) at  thread 0
aborting path on assume(false) at file /tmp/kani/generic-as.rs line 15 column 25 function main thread 0
Runtime Symex: 0.000472428s
size of program expression: 29 steps
slicing removed 19 assignments
Generated 1 VCC(s), 1 remaining after simplification
Runtime Postprocess Equation: 1.8535e-05s
Passing problem to propositional reduction
converting SSA
Runtime Convert SSA: 1.3595e-05s
Running propositional reduction
Post-processing
Runtime Post-process: 3.617e-06s
Solving with MiniSAT 2.2.1 with simplifier
0 variables, 0 clauses
SAT checker: instance is SATISFIABLE
Runtime Solver: 2.2102e-05s
Runtime decision procedure: 5.4061e-05s

RESULTS:
Check 1: unsupported_construct.1
	 - Status: FAILURE
	 - Description: "Projection mismatch is not currently supported by Kani. Please post your example at https://github.com/model-checking/kani/issues/277"

Check 2: main.unsupported_construct.1
	 - Status: UNDETERMINED
	 - Description: "simd_as is not currently supported by Kani. Please post your example at https://github.com/model-checking/kani/issues/new/choose"
	 - Location: generic-as.rs:15:25 in function main


SUMMARY:
 ** 1 of 2 failed (1 undetermined)
Failed Checks: Projection mismatch is not currently supported by Kani. Please post your example at https://github.com/model-checking/kani/issues/277

VERIFICATION:- FAILED
** WARNING: A Rust construct that is not currently supported by Kani was found to be reachable. Check the results for more details.Verification Time: 0.01263466s

cc #277

Activity

  1. added
    [C] Bug
    on Mar 3, 2023
  2. celinval commented on Mar 8, 2023

    @celinval
    Contributor

    Thanks @matthiaskrgr, I believe this is related to #1926. We don't really support portable_simd yet. We should make this error at least more specific until we properly fix it.

  3. added
    [E] Unsupported Construct
    Z-Kani Compiler
    on Mar 8, 2023
  4. self-assigned this
    on Jul 27, 2023
  5. changed the title [-]projection mismatch[/-] [+]Projection mismatch when declaring array-based SIMD[/+] on Jul 27, 2023
  6. celinval commented on Aug 16, 2023

    @celinval
    Contributor

    BTW, we have fixed the original projection mismatch, but the given test still fails due to unsupported simd_as intrinsic.

  7. matthiaskrgr commented on Nov 12, 2023

    @matthiaskrgr
    ContributorAuthor

    Right this no longer ICEs with 0.40, renders this fixed in my eyes, but we can also leave this open to track intrinsic stuff

  8. removed their assignment
    on Jan 24, 2025
  9. added a commit that references this issue on Nov 11, 2025
    ae6c014
  10. added a commit that references this issue on Jan 15, 2026
    caac9bd
  11. added theissue type on Apr 1, 2026
  12. feliperodri commented on Aug 15, 2026

    @feliperodri
    Member

    Status update / re-scope

    Revisiting this against current main (nightly-2026-03-02), the original error here actually splits into two separate problems, and only one of them remains:

    1. Projection mismatch — already fixed.
    The Projection mismatch / StructTag("tag-[T; 2]") error was a symptom of Kani not understanding array-based #[repr(simd)]. That was resolved by #2633 ("Add support to array-based SIMD"):
    codegen_simd_field now reinterpret-casts the SIMD vector to its inner array type, so projecting/indexing an array-based SIMD type no longer mismatches. This is in main today.

    2. simd_as — still unimplemented (the real remaining work).
    The reproducer's actual intrinsic, simd_as, has never been implemented in Kani. It falls through to the generic unimplemented path, so the harness fails with:

    simd_as is not currently supported by Kani.
    

    So this issue should be re-scoped to: implement the simd_as SIMD intrinsic.

    Modernized reproducer (extern "platform-intrinsic" is long gone):

    #![feature(repr_simd, core_intrinsics)]
    use std::intrinsics::simd::simd_as;
    
    #[derive(Copy, Clone)]
    #[repr(simd)]
    struct Vu32([u32; 2]);
    
    #[derive(Copy, Clone)]
    #[repr(simd)]
    struct Vi32([i32; 2]);
    
    #[kani::proof]
    fn check() {
        unsafe {
            let u = Vu32([0, u32::MAX]);
            let i: Vi32 = simd_as(u);
            // simd_as is a per-lane `as` cast: expect [0, -1]
            let lanes: [i32; 2] = std::mem::transmute(i);
            assert_eq!(lanes, [0, -1]);
        }
    }

    Implementation sketch: simd_as is an element-wise numeric cast, buildable with Expr::vector_expr(dst_vec_ty, lanes) where each lane is src.index_array(i).cast_to(dst_elem_ty). The one subtlety is that Rust's float→int as saturates (NaN → 0, out-of-range → clamp), which a plain CBMC cast doesn't do — that path should reuse Kani's existing scalar as saturation logic. Int↔int, int→float, and float→float lanes are straightforward.

    Note: PR #4467 attempted this but only touched projection-mismatch detection (already handled by #2633) and did not add simd_as, so it's being closed.

  13. feliperodri commented on Sep 25, 2026

    @feliperodri
    Member

    Triaged against main (de756c9, nightly-2026-09-23, Kani 0.68.0). the projection-mismatch crash is gone. The reproducer itself no longer builds (extern "platform-intrinsic" and #![feature(platform_intrinsics)] were removed from rustc), and the modern equivalent — u32x2::cast::<i16>() via portable_simd — completes with Failed Checks: simd_as is not currently supported by Kani. Closing the crash; simd_as support is a separate feature gap.

    Closing as no longer reproducible — please reopen if you can still hit it on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Z-Kani Compiler[C] Bug[E] Unsupported Construct

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions