File tree 2 files changed +19
-12
lines changed
heapster-saw/src/Verifier/SAW/Heapster
2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -1960,21 +1960,10 @@ simplImplIn (SImpl_LLVMArrayEmpty _ ap) =
1960
1960
simplImplIn (SImpl_LLVMArrayBorrowed x bp ap) =
1961
1961
if bvIsZero (llvmArrayLen ap) then
1962
1962
error " simplImplIn: SImpl_LLVMArrayBorrowed: empty array permission"
1963
- else if not totallyBorrowed then
1963
+ else if not (llvmArrayIsBorrowed ap) then
1964
1964
error " simplImplIn: SImpl_LLVMArrayBorrowed: array permission not completely borrowed"
1965
1965
else
1966
1966
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
-
1978
1967
1979
1968
simplImplIn (SImpl_LLVMArrayFromBlock x bp) =
1980
1969
distPerms1 x $ ValPerm_LLVMBlock bp
Original file line number Diff line number Diff line change @@ -4795,7 +4795,25 @@ llvmArrayBorrowRangeDelete borrow rng =
4795
4795
| otherwise =
4796
4796
error " llvmArrayBorrowRangeDelete: found non unit new_range for FieldBorrow"
4797
4797
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)
4798
4815
4816
+ permForOff o b = bvCouldEqual o (bvRangeOffset b)
4799
4817
4800
4818
-- | Test if a byte offset @o@ statically aligns with a statically-known offset
4801
4819
-- into some array cell, i.e., whether
You can’t perform that action at this time.
0 commit comments