Skip to content

Explicit wrapping behavior is reported as verification failure #480

Closed

Description

@tedinski

I tried this code:

fn simple_addition1(a: u32, b: u32) -> u32 {
    return a + b;
}
fn simple_addition2(a: u32, b: u32) -> u32 {
    return a.wrapping_add(b);
}

fn main() {
    let a: u32 = __nondet();
    let b: u32 = __nondet();
    simple_addition(a, b);
}

With version 1 we get the expected failure:

** Results:
/home/ubuntu/rmc/rmc-docs/src/tutorial/kinds-of-failure/tests/overflow.rs function simple_addition
[simple_addition.assertion.1] line 6 attempt to compute `move _3 + move _4`, which would overflow: FAILURE
[simple_addition.overflow.1] line 6 arithmetic overflow on unsigned + in var_3 + var_4: FAILURE

** 2 of 2 failed (2 iterations)
VERIFICATION FAILED

This includes both Rust's dynamic assertion, and RMC's overflow check.

With version 2 we still get an overflow failure that probably should be suppressed:

** Results:
/home/ubuntu/rmc/library/core/src/num/uint_macros.rs function core::num::<impl u32>::wrapping_add
[core::num::<impl u32>::wrapping_add.overflow.1] line 1111 arithmetic overflow on unsigned + in var_3 + var_4: FAILURE

** 1 of 1 failed (2 iterations)
VERIFICATION FAILED

The dynamic assertion is correctly removed, but not the RMC overflow check.

The root cause is:

ompiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/intrinsic.rs:            "wrapping_add" => codegen_intrinsic_binop!(plus),

We're treating wrapping_add as identical to an ordinary add. I'm not sure if CBMC has an instrinsic or flag or something we can attached to signal this overflow is acceptable.

Activity

  1. added
    [C] Bug
    on Sep 13, 2021
  2. self-assigned this
    on Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions