Skip to content

Missing checks in division/remainder operators for vector expressions #7367

Closed

Description

@adpaco

CBMC version: 5.69.1 (+ this Kani branch)
Operating system: ubuntu-20.04
Exact command line resulting in the issue: Default kani command the example

#![feature(repr_simd, platform_intrinsics)]

#[repr(simd)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct i32x2(i32, i32);

extern "platform-intrinsic" {
    fn simd_div<T>(x: T, y: T) -> T;
    fn simd_rem<T>(x: T, y: T) -> T;
}

#[kani::proof]
fn test_normal() {
    let val_1: i32 = kani::any();
    let val_2: i32 = kani::any();
    kani::assume(val_1 == i32::MIN);
    kani::assume(val_2 == -1);
    let result: i32 = val_1 / val_2;
}

#[kani::proof]
fn test_simd() {
    let val_1 = kani::any();
    kani::assume(val_1 == i32::MIN);
    let values_1 = i32x2(val_1, val_1);
    let val_2 = kani::any();
    kani::assume(val_2 == -1);
    let values_2 = i32x2(val_2, val_2);
    let result = unsafe { simd_div(values_1, values_2) };
}

What behaviour did you expect: Expected the properties to be checked to be the same for both / (or %) and simd_div (or simd_rem).
What happened instead: The properties checked aren't the same for both / (or %) and simd_div (or simd_rem). In particular, when I run the program above in Kani, I see the following verification output for test_normal:

RESULTS:
Check 1: test_normal.assertion.1
         - Status: SUCCESS
         - Description: "attempt to divide by zero"
         - Location: tests/kani/Intrinsics/SIMD/Operators/div_rem.rs:19:23 in function test_normal

Check 2: test_normal.assertion.2
         - Status: FAILURE
         - Description: "attempt to divide with overflow"
         - Location: tests/kani/Intrinsics/SIMD/Operators/div_rem.rs:19:23 in function test_normal

Check 3: test_normal.division-by-zero.1
         - Status: SUCCESS
         - Description: "division by zero"
         - Location: tests/kani/Intrinsics/SIMD/Operators/div_rem.rs:19:23 in function test_normal

And the following verification output for test_simd:

Check 1: division-by-zero.1
         - Status: SUCCESS
         - Description: "division by zero"

Check 2: division-by-zero.2
         - Status: SUCCESS
         - Description: "division by zero"

There are several concerns here:

  • The overflow check is missing when using the vector operator.
  • The "attempt to divide by zero" check is missing when using the vector operator.

Note that Kani tweaks the output a little bit in this example. In particular, for properties with class division-by-zero it omits the variables, the original outputs are:

Check 3: test_normal.division-by-zero.1
         - Status: SUCCESS
         - Description: "division by zero in var_10 / var_11"
         - Location: tests/kani/Intrinsics/SIMD/Operators/div_rem.rs:19:23 in function test_normal
Check 1: division-by-zero.1
         - Status: SUCCESS
         - Description: "division by zero in var_16[0] / var_17[0]"

Check 2: division-by-zero.2
         - Status: SUCCESS
         - Description: "division by zero in var_16[1] / var_17[1]"

That makes sense since we're working with a 2-member vector: the division-by-zero property is replicated for each component of the vector.

Anyway, I was expecting the overflow and "attempt to divide by zero" checks to be generated for vector operators as they do for the regular operators. This applies to both division (regular: / - vector: simd_div) and remainder (regular: % - vector: simd_rem) operations.

Activity

  1. self-assigned this
    on Nov 22, 2022
  2. added
    aws
    Kani
    on Nov 22, 2022
  3. tautschnig commented on Nov 22, 2022

    @tautschnig
    Collaborator

    It seems all the missing properties are ones generated by Kani. Closing for time being, but please do reopen in case you expected CBMC to create those checks by itself.

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

Metadata

Metadata

Assignees

Labels

Kaniaws

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions