Skip to content

Kani fails with l2_rename_values case struct' not handled` #1257

Closed

Description

@zhassan-aws

I tried this code:

fn plus_one(cnt: i32) -> i32 {
    cnt + 1
}

#[kani::proof]
fn main() {
    let cnt = 0;
    let queue: Vec<Box<dyn Fn(i32) -> i32>> = vec![Box::new(plus_one)];
    //let queue: Vec<Box<dyn Fn(i32) -> i32>> = vec![Box::new(|cnt| plus_one(cnt))];
    let cnt_plus_one = queue[0](cnt);
    assert_eq!(cnt_plus_one, 1);
}

using the following command line invocation:

kani test.rs

with Kani version: 6f84f809042

I expected to see this happen: Verification successful

Instead, this happened:

$ kani test.rs 
Checking harness main...
l2_rename_rvalues case `struct' not handled

The commented version, which wraps the function call in a closure:

    let queue: Vec<Box<dyn Fn(i32) -> i32>> = vec![Box::new(|cnt| plus_one(cnt))];

works.

Activity

  1. added
    [C] Bug
    on Jun 7, 2022
  2. zhassan-aws commented on Jun 7, 2022

    @zhassan-aws
    ContributorAuthor
  3. tautschnig commented on Jun 8, 2022

    @tautschnig
    Member

    See my comment posted in diffblue/cbmc#6911: it appears that Kani is producing a struct expression (not a struct-typed symbol!) as the left-hand side of an assignment.

  4. zhassan-aws commented on Jun 8, 2022

    @zhassan-aws
    ContributorAuthor

    Thanks for debugging this, @tautschnig!

  5. tedinski commented on Aug 26, 2022

    @tedinski
    Contributor

    Bad code can be found by searching for FnDefSingleton in the gen-c output: (from various places)

      (struct std::boxed::Box<fn(i32) -> i32 {plus_one}>){ .1=nondet_5(), .0={ ._marker=nondet_6(), .pointer={ .pointer=&FnDefSingleton } } }
       = 
        (struct std::boxed::Box<fn(i32) -> i32 {plus_one}>){ .1=nondet_5(), .0={ ._marker=nondet_6(), .pointer={ .pointer=(struct plus_one::FnDefStruct *)var_4 } } };
    
      &FnDefSingleton
       =
        ((struct std::boxed::Box<fn(i32) -> i32 {plus_one}>){ .1=nondet_5(), .0={ ._marker=nondet_6(), .pointer={ .pointer=&FnDefSingleton } } }).0.pointer.pointer;
    
      (struct std::boxed::Box<fn(i32) -> i32 {plus_one}>){ .1=nondet_5(), .0={ ._marker=nondet_6(), .pointer={ .pointer=&FnDefSingleton } } }
       =
        std::boxed::Box::<fn(i32) -> i32 {plus_one}>::new(FnDefSingleton);
        
    
  6. 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[F] Crash

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions