Skip to content

Commit 6a9413a

Browse files
authored
Merge pull request #1625 from GaloisInc/heapster/array-borrow-check
Change Borrowed Array input permissions check
2 parents 10fbb84 + ad75241 commit 6a9413a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -1960,21 +1960,10 @@ simplImplIn (SImpl_LLVMArrayEmpty _ ap) =
19601960
simplImplIn (SImpl_LLVMArrayBorrowed x bp ap) =
19611961
if bvIsZero (llvmArrayLen ap) then
19621962
error "simplImplIn: SImpl_LLVMArrayBorrowed: empty array permission"
1963-
else if not totallyBorrowed then
1963+
else if not (llvmArrayIsBorrowed ap) then
19641964
error "simplImplIn: SImpl_LLVMArrayBorrowed: array permission not completely borrowed"
19651965
else
19661966
distPerms1 x (ValPerm_Conj1 $ Perm_LLVMBlock bp)
1967-
where
1968-
-- If all the subtractions below could be empty, then we've subtracted the
1969-
-- whole array
1970-
totallyBorrowed = all (bvCouldEqual (bvInt 0)) (bvRangeLength <$> remaining)
1971-
1972-
remaining =
1973-
-- iteratively subtract each borrow from the total range of array indices
1974-
foldr (\b xs -> xs >>= (`bvRangeDelete` llvmArrayBorrowCells b))
1975-
[llvmArrayCells ap]
1976-
(llvmArrayBorrows ap)
1977-
19781967

19791968
simplImplIn (SImpl_LLVMArrayFromBlock x bp) =
19801969
distPerms1 x $ ValPerm_LLVMBlock bp

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

+18
Original file line numberDiff line numberDiff line change
@@ -4795,7 +4795,25 @@ llvmArrayBorrowRangeDelete borrow rng =
47954795
| otherwise =
47964796
error "llvmArrayBorrowRangeDelete: found non unit new_range for FieldBorrow"
47974797

4798+
-- | Return whether or not the borrows in @ap@ cover the range of cells [0, len). Specifically,
4799+
-- if the borrowed cells (as ranges) can be arranged in as a sequence of non-overlapping but contiguous
4800+
-- ranges (in the sense of @bvCouldEqual@) that extends at least as far as @len@ (in the sense of @bvLeq@)
4801+
llvmArrayIsBorrowed ::
4802+
(HasCallStack, 1 <= w, KnownNat w) =>
4803+
LLVMArrayPerm w ->
4804+
Bool
4805+
llvmArrayIsBorrowed ap =
4806+
go (bvInt 0) (llvmArrayBorrowCells <$> llvmArrayBorrows ap)
4807+
where
4808+
end = bvRangeEnd (llvmArrayCells ap)
4809+
4810+
go off borrows
4811+
| bvLeq end off
4812+
= True
4813+
| Just i <- findIndex (permForOff off) borrows
4814+
= go (bvAdd off (bvRangeLength (borrows!!i))) (deleteNth i borrows)
47984815

4816+
permForOff o b = bvCouldEqual o (bvRangeOffset b)
47994817

48004818
-- | Test if a byte offset @o@ statically aligns with a statically-known offset
48014819
-- into some array cell, i.e., whether

0 commit comments

Comments
 (0)