Skip to content

Commit 57305ce

Browse files
authored
1 parent be039f6 commit 57305ce

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/kani/DynTrait/encode_utf8.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
/// This test checks that CBMC's unwinding terminates on a program that involves
5+
/// dyn trait and `char::encode_utf8` (a minimal reproducer from
6+
/// https://github.com/model-checking/kani/issues/1767)
7+
8+
pub trait Trait {
9+
fn f(&self);
10+
}
11+
12+
struct Foo {}
13+
14+
impl Trait for Foo {
15+
fn f(&self) {
16+
let _ = 'x'.encode_utf8(&mut [0; 4]);
17+
}
18+
}
19+
20+
pub struct Formatter {}
21+
22+
fn nn(_x: &u8, _f: &Formatter) {}
23+
24+
pub struct ArgumentV1 {
25+
formatter: fn(&u8, &Formatter) -> (),
26+
}
27+
28+
#[kani::proof]
29+
#[kani::unwind(2)]
30+
fn dyn_trait_with_encode_utf8() {
31+
let f = Foo {};
32+
let a = [ArgumentV1 { formatter: nn }];
33+
34+
let _output = &f as &dyn Trait;
35+
let formatter = Formatter {};
36+
37+
let mut iter = a.iter();
38+
let _ = (iter.next().unwrap().formatter)(&5, &formatter);
39+
}

0 commit comments

Comments
 (0)