Skip to content

Kani generates int constants that cannot fit into their bitwidth on some regressions #996

Open

Description

@danielsn

Enabling the assertion in here causes a whole bunch of regression failures.

    pub fn int_constant<T>(i: T, typ: Type) -> Self
    where
        T: Into<BigInt>,
    {
        assert!(typ.is_integer());
        let i = i.into();
        //TODO: This check fails on some regressions
        // if i != 0 && i != 1 {
        //     assert!(
        //         typ.min_int() <= i && i <= typ.max_int(),
        //         "{} {} {} {:?}",
        //         i,
        //         typ.min_int(),
        //         typ.max_int(),
        //         typ
        //     );
        // }
        expr!(IntConstant(i), typ)
    }

Activity

  1. danielsn commented on Mar 30, 2022

    @danielsn
    ContributorAuthor

    We can also re-enable the should_panic tests in irep_id.rs once this is fixed

  2. added
    [C] Bug
    on Mar 30, 2022
  3. adpaco commented on Mar 30, 2022

    @adpaco
    Contributor

    Can you please write which regressions were failing?

  4. danielsn commented on Mar 30, 2022

    @danielsn
    ContributorAuthor
    failures:
        [kani] kani/BitwiseEqualOperators/main.rs
        [kani] kani/Cast/main.rs
        [kani] kani/CodegenConstValue/bigints.rs
        [kani] kani/CopyIntrinsics/main.rs
        [kani] kani/Count/Unstable/Ctlz/main.rs
        [kani] kani/Count/Unstable/Cttz/main.rs
        [kani] kani/DynTrait/std_lib_add_duplicate.rs
        [kani] kani/Intrinsics/Assert/zero_valid.rs
        [kani] kani/Intrinsics/Rotate/rotate_right.rs
        [kani] kani/Invariants/enum.rs
        [kani] kani/PointerOffset/Stable/main.rs
        [kani] kani/PointerOffset/Unstable/main.rs
        [kani] kani/Pointers_OtherTypes/main.rs
        [kani] kani/Vectors/push_u8.rs
        [kani] kani/Vectors/vector_extend.rs
        [kani] kani/Vectors/vector_extend_in_new.rs
        [kani] kani/Vectors/vector_extend_loop.rs
        [kani] kani/VolatileIntrinsics/main.rs
        [kani] kani/i32-Unary-/main.rs
    
  5. danielsn commented on Mar 30, 2022

    @danielsn
    ContributorAuthor

    Looking at the examples, it seems that its mostly a case of the unsigned max value attempting to be put into a signed integer.

  6. danielsn commented on Mar 30, 2022

    @danielsn
    ContributorAuthor

    e.g.

    thread 'rustc' panicked at 'Cannot fit value into bits. value 255 width: 8 signed: true', cprover_bindings/src/irep/irep_id.rs:843:9
    
  7. danielsn commented on Mar 30, 2022

    @danielsn
    ContributorAuthor
    thread 'rustc' panicked at 'Cannot fit value into bits. value 18446744073709551614 width: 64 signed: true', cprover_bindings/src/irep/irep_id.rs:843:9
    
  8. self-assigned this
    on Apr 18, 2022
  9. added
    [F] Soundness
    and removed on Apr 20, 2022
  10. removed
    [F] Soundness
    on Apr 22, 2022
  11. adpaco commented on Apr 22, 2022

    @adpaco
    Contributor

    We agreed that there are no soundness concerns (after #1063, of course) because the discriminant values are being correctly encoded in CBMC so they work as expected. Proof of this is for example the test case we have for discriminant values including negative ones in tests/kani/Intrinsics/discriminant_value.rs:

    // An enum that assigns constant values (one of them negative) to all variants
    enum Ordering {
        Less = -1,
        Equal = 0,
        Greater = 1,
    }
    
    #[kani::proof]
    fn test_constants_enum() {
        // Check that the values are equal to the constants assigned
        assert!(discriminant_value(&Ordering::Less) == -1);
        assert!(discriminant_value(&Ordering::Equal) == 0);
        assert!(discriminant_value(&Ordering::Greater) == 1);
    }
  12. self-assigned this
    on May 5, 2022
  13. moved this to Todo in Kani v0.3on May 18, 2022
  14. removed their assignment
    on Jan 24, 2025
  15. added theissue type on Apr 1, 2026
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

    [C] Bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions