Skip to content

Commit 12e1d87

Browse files
committed
Try solving for array lifetime/rw modality.
1 parent 9220cec commit 12e1d87

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

heapster-saw/src/Verifier/SAW/Heapster/Implication.hs

+42
Original file line numberDiff line numberDiff line change
@@ -6606,6 +6606,42 @@ borrowedLLVMArrayForArray lhs rhs =
66066606
| otherwise
66076607
= bs_skip ++ bs_lhs
66086608

6609+
-- | TODO: hide the bool parameter
6610+
solveForArray ::
6611+
(1 <= w, KnownNat w, NuMatchingAny1 r) =>
6612+
Bool ->
6613+
[AtomicPerm (LLVMPointerType w)] ->
6614+
Mb vars (LLVMArrayPerm w) ->
6615+
ImplM vars s r ps ps ()
6616+
solveForArray should_fail ps mb_ap =
6617+
getPSubst >>>= \psubst ->
6618+
case partialSubst psubst mb_ap of
6619+
Just _ap -> return ()
6620+
Nothing
6621+
| should_fail ->
6622+
implFailM "goo goo"
6623+
| otherwise ->
6624+
solveForArrayH ps psubst mb_ap
6625+
6626+
solveForArrayH ::
6627+
(1 <= w, KnownNat w, NuMatchingAny1 r) =>
6628+
[AtomicPerm (LLVMPointerType w)] ->
6629+
PartialSubst vars ->
6630+
Mb vars (LLVMArrayPerm w) ->
6631+
ImplM vars s r ps ps ()
6632+
solveForArrayH ps psubst mb_ap
6633+
| Nothing <- partialSubst psubst $ mbLLVMArrayLifetime mb_ap
6634+
, Just l:_ <- atomicPermLifetime <$> ps =
6635+
tryUnifyVars l (mbLLVMArrayLifetime mb_ap) >>>
6636+
solveForArray False ps mb_ap
6637+
solveForArrayH ps psubst mb_ap
6638+
| Nothing <- partialSubst psubst $ mbLLVMArrayRW mb_ap
6639+
, Just l:_ <- atomicPermModality <$> ps =
6640+
tryUnifyVars l (mbLLVMArrayRW mb_ap) >>>
6641+
solveForArray False ps mb_ap
6642+
solveForArrayH ps _ mb_ap =
6643+
solveForArray True ps mb_ap
6644+
66096645

66106646
-- | Prove an LLVM array permission @ap@ from permissions @x:(p1 * ... *pn)@ on
66116647
-- the top of the stack, ensuring that any remaining permissions for @x@ get
@@ -6701,6 +6737,12 @@ proveVarLLVMArrayH x p psubst ps mb_ap
67016737
-- Otherwise, try and build a completely borrowed array that references existing
67026738
-- permissions that cover the range of mb_ap, and recurse (hitting the special
67036739
-- case above).
6740+
proveVarLLVMArrayH x first_p psubst ps mb_ap
6741+
| Nothing <- partialSubst psubst mb_ap =
6742+
solveForArray False ps mb_ap >>>
6743+
getPSubst >>>= \psubst' ->
6744+
proveVarLLVMArrayH x first_p psubst' ps mb_ap
6745+
67046746
proveVarLLVMArrayH x first_p psubst ps mb_ap
67056747
| Just ap <- partialSubst psubst mb_ap
67066748
-- NOTE: borrowedLLVMArrayForArray only returns a single possible covering, though

heapster-saw/src/Verifier/SAW/Heapster/Permissions.hs

+7
Original file line numberDiff line numberDiff line change
@@ -4058,6 +4058,13 @@ atomicPermLifetime (Perm_LLVMArray ap) = Just $ llvmArrayLifetime ap
40584058
atomicPermLifetime (Perm_LLVMBlock bp) = Just $ llvmBlockLifetime bp
40594059
atomicPermLifetime _ = Nothing
40604060

4061+
-- | Get the modality of an atomic perm if it is a field, array, or memblock
4062+
atomicPermModality :: AtomicPerm a -> Maybe (PermExpr RWModalityType)
4063+
atomicPermModality (Perm_LLVMField fp) = Just $ llvmFieldRW fp
4064+
atomicPermModality (Perm_LLVMArray ap) = Just $ llvmArrayRW ap
4065+
atomicPermModality (Perm_LLVMBlock bp) = Just $ llvmBlockRW bp
4066+
atomicPermModality _ = Nothing
4067+
40614068
-- | Get the starting offset of an atomic permission, if it has one. This
40624069
-- includes array permissions which may have some cells borrowed.
40634070
llvmAtomicPermOffset :: AtomicPerm (LLVMPointerType w) ->

0 commit comments

Comments
 (0)