Skip to content

Commit

Permalink
Test Add ops on GhostInt
Browse files Browse the repository at this point in the history
  • Loading branch information
aakp10 committed Oct 10, 2020
1 parent 584c635 commit 3beeb22
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions prusti-contracts/src/ghost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub unsafe auto trait Ghost {}

macro_rules! implement_ghost_type {
($ghost_type: ident) => {
#[derive(PartialEq, Eq)]
pub struct $ghost_type;
unsafe impl Ghost for $ghost_type{}
};
Expand Down
18 changes: 12 additions & 6 deletions prusti-tests/tests/typecheck/pass/ghost_int.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use prusti_contracts::GhostInt;
use prusti_contracts::*;
use crate::ghost::GhostInt;

fn test4() {
let a = GhostInt;
let b = GhostInt;
let c = a + b;
}
fn test_1() -> GhostInt{
let x = GhostInt::new(10);
let y = GhostInt::new(20);
x + y
}

#[ensures(result == gh1 + gh2)]
fn test_2(gh1: GhostInt, gh2: GhostInt) -> GhostInt{
gh1 + gh2
}

fn main() {}
7 changes: 4 additions & 3 deletions prusti-viper/src/encoder/procedure_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1887,16 +1887,17 @@ impl<'p, 'v: 'p, 'tcx: 'v> ProcedureEncoder<'p, 'v, 'tcx> {
// Is this viper declaration of an Int type encoded in prepare_assign_target method?
// Currently, it's using the destination field from the MIR to accomplish this. I'm not sure how
// destination and location are related here.
let value_field = self.encoder.encode_value_field(dest_ty);
stmts.extend(
self.prepare_assign_target(
dst,
ref_field,
dst.clone(),
value_field.clone(),
location,
vir::AssignKind::Move,
)
);
// N.B. Is encode_value_field the right choice here?
let value_field = self.encoder.encode_value_field(dest_ty);
//let value_field = self.encoder.encode_value_field(dest_ty);
// Step2. assign value = `ghost_val` to the above created destination/ location (unsure about the terminology)
stmts.extend(self.encode_assign_operand(&dst.clone().field(value_field), &args[0], location));
}
Expand Down

0 comments on commit 3beeb22

Please sign in to comment.