Skip to content

Commit 56b12e4

Browse files
committed
Add tests for loops, remove empty Conditional statements
1 parent 096bdd5 commit 56b12e4

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

native-verifier/src/fol.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ fn vir_statement_to_fol_statements(
3232

3333
vec![FolStatement::Assume(eq)]
3434
}
35+
Statement::Conditional(cond) => {
36+
if !(cond.then_branch.is_empty() && cond.else_branch.is_empty()) {
37+
log::warn!(
38+
"Conditional statement with non-empty branches, guard: {:?}",
39+
cond.guard
40+
);
41+
}
42+
vec![]
43+
}
3544
Statement::MethodCall(method_call) => {
3645
let method_decl = known_methods
3746
.get(&method_call.method_name)

native-verifier/src/smt_lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ impl SMTTranslatable for MethodDecl {
357357
// we assume these to be correct by default and collect their signatures
358358
if self.body.is_none() {
359359
smt.methods.insert(self.name.clone(), self.clone());
360+
} else {
361+
unimplemented!("Method bodies are not yet supported");
360362
}
361363
}
362364
}
@@ -430,11 +432,7 @@ impl SMTTranslatable for Expression {
430432
ConstantValue::Int(i64) => i64.to_string(),
431433
ConstantValue::BigInt(s) => s.clone(),
432434
},
433-
Expression::MagicWand(magic_wand) => format!(
434-
"(=> {} {})", // TODO: is this correct?
435-
magic_wand.left.to_smt(),
436-
magic_wand.right.to_smt()
437-
),
435+
Expression::MagicWand(magic_wand) => unimplemented!("Magic wands"),
438436
Expression::PredicateAccessPredicate(_access) => {
439437
// TODO: access predicates for predicates
440438
warn!("PredicateAccessPredicate not supported");

prusti-server/src/backend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::dump_viper_program;
2+
use backend_common::VerificationResult;
23
use prusti_common::{
34
config,
45
vir::{LoweringContext, ToViper},
@@ -38,7 +39,7 @@ impl<'a> Backend<'a> {
3839
})
3940
}
4041
Backend::Lithium(lithium) => {
41-
Stopwatch::start("prusti-server", "verifierication");
42+
Stopwatch::start("prusti-server", "vir verification");
4243
lithium.verify(program)
4344
}
4445
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// compile-flags: -Pviper_backend=Lithium
2+
3+
use prusti_contracts::*;
4+
5+
const N: i32 = 10;
6+
7+
#[requires(i <= N)]
8+
#[ensures(result == N)]
9+
fn wrong_invariant(i: i32) -> i32 {
10+
let mut ret = i;
11+
while ret < N {
12+
body_invariant!(ret == i); //~ ERROR loop invariant might not hold
13+
ret += 1;
14+
}
15+
ret
16+
}
17+
18+
#[requires(i <= N)]
19+
#[ensures(result == N)] //~ ERROR might not hold
20+
fn weak_invariant(i: i32) -> i32 {
21+
let mut ret = i;
22+
while ret < N {
23+
body_invariant!(ret <= N);
24+
ret += 1;
25+
}
26+
ret
27+
}
28+
29+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -Pviper_backend=Lithium
2+
3+
use prusti_contracts::*;
4+
5+
const N: i32 = 10;
6+
7+
#[requires(i <= N)]
8+
#[ensures(result == N)]
9+
fn test(i: i32) -> i32 {
10+
let mut ret = i;
11+
while ret < N {
12+
body_invariant!(ret < N);
13+
ret += 1;
14+
}
15+
ret
16+
}
17+
18+
fn main() {
19+
assert!(test(3) == N);
20+
}

0 commit comments

Comments
 (0)