Skip to content

Commit

Permalink
Some changes had accidentally been reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Nov 22, 2023
1 parent 0c3cea7 commit 4b451cf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
46 changes: 32 additions & 14 deletions library/kani/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,54 @@ macro_rules! implies {
}

#[doc(hidden)]
pub trait DecoupleLifetime<'a> {
pub trait Pointer<'a> {
type Inner;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner;
unsafe fn decouple_lifetime(self) -> &'a Self::Inner;

unsafe fn assignable(self) -> &'a mut Self::Inner;
}

impl<'a, 'b, T> DecoupleLifetime<'a> for &'b T {
impl<'a, 'b, T> Pointer<'a> for &'b T {
type Inner = T;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner {
std::mem::transmute(*self)
unsafe fn decouple_lifetime(self) -> &'a Self::Inner {
std::mem::transmute(self)
}

unsafe fn assignable(self) -> &'a mut Self::Inner {
std::mem::transmute(self as *const T)
}
}

impl<'a, 'b, T> DecoupleLifetime<'a> for &'b mut T {
impl<'a, 'b, T> Pointer<'a> for &'b mut T {
type Inner = T;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner {
*std::mem::transmute::<&'_ &'b mut T, &'_ &'a T>(self)
unsafe fn decouple_lifetime(self) -> &'a Self::Inner {
std::mem::transmute(self as *mut T)
}

unsafe fn assignable(self) -> &'a mut Self::Inner {
std::mem::transmute(self)
}
}

impl<'a, T> DecoupleLifetime<'a> for *const T {
impl<'a, T> Pointer<'a> for *const T {
type Inner = T;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner {
&**self as &'a T
unsafe fn decouple_lifetime(self) -> &'a Self::Inner {
&*self as &'a T
}

unsafe fn assignable(self) -> &'a mut Self::Inner {
std::mem::transmute(self)
}
}

impl<'a, T> DecoupleLifetime<'a> for *mut T {
impl<'a, T> Pointer<'a> for *mut T {
type Inner = T;
unsafe fn decouple_lifetime(&self) -> &'a Self::Inner {
&**self as &'a T
unsafe fn decouple_lifetime(self) -> &'a Self::Inner {
&*self as &'a T
}

unsafe fn assignable(self) -> &'a mut Self::Inner {
std::mem::transmute(self)
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/kani_macros/src/sysroot/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ impl<'a> ContractConditionsHandler<'a> {
let wrapper_args = make_wrapper_args(attr.len());

quote!(
#(let #wrapper_args = unsafe { kani::DecoupleLifetime::decouple_lifetime(&#attr) };)*
#(let #wrapper_args = unsafe { kani::Pointer::decouple_lifetime(#attr) };)*
#(#inner)*
)
}
Expand Down Expand Up @@ -605,7 +605,7 @@ impl<'a> ContractConditionsHandler<'a> {
ContractConditionsData::Modifies { attr } => {
quote!(
let result = #call_to_prior;
#(*#attr = kani::any();)*
#(*unsafe { kani::Pointer::assignable(#attr) } = kani::any();)*
result
)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/function-contract/assigns_pass.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERIFICATION:- FAILED
VERIFICATION:- SUCCESSFUL

0 comments on commit 4b451cf

Please sign in to comment.