Skip to content

Commit

Permalink
Merge pull request #1361 from GaloisInc/T1359
Browse files Browse the repository at this point in the history
Fix off-by-one error in What4 implementation of `(@)`
  • Loading branch information
RyanGlScott authored Jun 7, 2022
2 parents bdbe080 + c37a71b commit 7ac76ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# next

## Bug fixes

* Fix a bug in the What4 backend that could cause applications of `(@)` with
symbolic `Integer` indices to become out of bounds (#1359).

# 2.13.0

## Language changes
Expand Down
17 changes: 7 additions & 10 deletions src/Cryptol/Eval/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ indexFront_int ::
TValue ->
SInteger (What4 sym) ->
SEval (What4 sym) (Value sym)
indexFront_int sym mblen _a xs ix idx
indexFront_int sym mblen _a xs _ix idx
| Just i <- W4.asInteger idx
= lookupSeqMap xs i

Expand Down Expand Up @@ -535,16 +535,13 @@ indexFront_int sym mblen _a xs ix idx
_ -> Nothing
)

-- Maximum possible in-bounds index given `Z m`
-- type information and the length
-- of the sequence. If the sequences is infinite and the
-- integer is unbounded, there isn't much we can do.
-- Maximum possible in-bounds index given the length
-- of the sequence. If the sequence is infinite, there
-- isn't much we can do.
maxIdx =
case (mblen, ix) of
(Nat n, TVIntMod m) -> Just (min (toInteger n) (toInteger m))
(Nat n, _) -> Just n
(_ , TVIntMod m) -> Just m
_ -> Nothing
case mblen of
Nat n -> Just (n - 1)
Inf -> Nothing
indexFront_segs ::
W4.IsSymExprBuilder sym =>
What4 sym ->
Expand Down
7 changes: 7 additions & 0 deletions tests/issues/issue1359.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:set prover=sbv-z3
:safe \a -> sortBy (\c1 c2 -> c2 != ' ') (split`{8} a)
:safe \(a : [64]) (i : Integer) -> (split`{8} a)@(max 0 (min i 7))

:set prover=w4-z3
:safe \a -> sortBy (\c1 c2 -> c2 != ' ') (split`{8} a)
:safe \(a : [64]) (i : Integer) -> (split`{8} a)@(max 0 (min i 7))
5 changes: 5 additions & 0 deletions tests/issues/issue1359.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Loading module Cryptol
Safe
Safe
Safe
Safe

0 comments on commit 7ac76ec

Please sign in to comment.