Skip to content

Commit

Permalink
Add tests for loops, remove empty Conditional statements
Browse files Browse the repository at this point in the history
  • Loading branch information
JakuJ committed Feb 27, 2023
1 parent 096bdd5 commit 56b12e4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
9 changes: 9 additions & 0 deletions native-verifier/src/fol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ fn vir_statement_to_fol_statements(

vec![FolStatement::Assume(eq)]
}
Statement::Conditional(cond) => {
if !(cond.then_branch.is_empty() && cond.else_branch.is_empty()) {
log::warn!(
"Conditional statement with non-empty branches, guard: {:?}",
cond.guard
);
}
vec![]
}
Statement::MethodCall(method_call) => {
let method_decl = known_methods
.get(&method_call.method_name)
Expand Down
8 changes: 3 additions & 5 deletions native-verifier/src/smt_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ impl SMTTranslatable for MethodDecl {
// we assume these to be correct by default and collect their signatures
if self.body.is_none() {
smt.methods.insert(self.name.clone(), self.clone());
} else {
unimplemented!("Method bodies are not yet supported");
}
}
}
Expand Down Expand Up @@ -430,11 +432,7 @@ impl SMTTranslatable for Expression {
ConstantValue::Int(i64) => i64.to_string(),
ConstantValue::BigInt(s) => s.clone(),
},
Expression::MagicWand(magic_wand) => format!(
"(=> {} {})", // TODO: is this correct?
magic_wand.left.to_smt(),
magic_wand.right.to_smt()
),
Expression::MagicWand(magic_wand) => unimplemented!("Magic wands"),
Expression::PredicateAccessPredicate(_access) => {
// TODO: access predicates for predicates
warn!("PredicateAccessPredicate not supported");
Expand Down
3 changes: 2 additions & 1 deletion prusti-server/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::dump_viper_program;
use backend_common::VerificationResult;
use prusti_common::{
config,
vir::{LoweringContext, ToViper},
Expand Down Expand Up @@ -38,7 +39,7 @@ impl<'a> Backend<'a> {
})
}
Backend::Lithium(lithium) => {
Stopwatch::start("prusti-server", "verifierication");
Stopwatch::start("prusti-server", "vir verification");
lithium.verify(program)
}
}
Expand Down
29 changes: 29 additions & 0 deletions prusti-tests/tests/verify/fail/native/while.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// compile-flags: -Pviper_backend=Lithium

use prusti_contracts::*;

const N: i32 = 10;

#[requires(i <= N)]
#[ensures(result == N)]
fn wrong_invariant(i: i32) -> i32 {
let mut ret = i;
while ret < N {
body_invariant!(ret == i); //~ ERROR loop invariant might not hold
ret += 1;
}
ret
}

#[requires(i <= N)]
#[ensures(result == N)] //~ ERROR might not hold
fn weak_invariant(i: i32) -> i32 {
let mut ret = i;
while ret < N {
body_invariant!(ret <= N);
ret += 1;
}
ret
}

fn main() {}
20 changes: 20 additions & 0 deletions prusti-tests/tests/verify/pass/native/while.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// compile-flags: -Pviper_backend=Lithium

use prusti_contracts::*;

const N: i32 = 10;

#[requires(i <= N)]
#[ensures(result == N)]
fn test(i: i32) -> i32 {
let mut ret = i;
while ret < N {
body_invariant!(ret < N);
ret += 1;
}
ret
}

fn main() {
assert!(test(3) == N);
}

0 comments on commit 56b12e4

Please sign in to comment.