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

Compilation error when using loop contracts in const fn #3586

Closed
qinheping opened this issue Oct 9, 2024 · 1 comment
Closed

Compilation error when using loop contracts in const fn #3586

qinheping opened this issue Oct 9, 2024 · 1 comment
Assignees
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@qinheping
Copy link
Contributor

I tried this code:

// SPDX-License-Identifier: Apache-2.0 OR MIT

// kani-flags: -Z loop-contracts

//! Check if loop contracts is correctly applied.

#![feature(stmt_expr_attributes)]
#![feature(proc_macro_hygiene)]

pub const BASE: usize = count_zero(&[]);

#[kani::proof]
pub fn check_counter() {
    assert_eq!(count_zero(&[1, 2]), 0)
}

const fn count_zero(slice: &[u8]) -> usize {
    let mut counter: usize = 0;
    let mut index: usize = 0;

    #[kani::loop_invariant(counter < slice.len())]
    while index < slice.len() {
        if slice[index] == 0 {
           counter += 1;
        }
        index += 1;
    }

    counter
}

with Kani version: #3151

I expected to see this happen: correctly compile.

Instead, this happened:

   |
55 | kani_core::kani_lib!(kani);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code: ', /library/kani/src/lib.rs:55:1
   |
@qinheping qinheping added the [C] Bug This is a bug. Something isn't working. label Oct 9, 2024
@qinheping qinheping self-assigned this Oct 9, 2024
@qinheping
Copy link
Contributor Author

Resolved in #3151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

No branches or pull requests

1 participant