Skip to content

Commit

Permalink
Fix off-by-one error in What4 implementation of (@)
Browse files Browse the repository at this point in the history
In the case where the index is a symbolic `Integer` and the sequence is of
length `n`, the What4 backend mistakenly chose `n` to be the largest possible
index. This corrects it to instead be `n - 1`.

Fixes #1359.
  • Loading branch information
RyanGlScott committed Jun 2, 2022
1 parent 9e59289 commit c37a71b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion src/Cryptol/Eval/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ indexFront_int sym mblen _a xs _ix idx
-- isn't much we can do.
maxIdx =
case mblen of
Nat n -> Just n
Nat n -> Just (n - 1)
Inf -> Nothing
indexFront_segs ::
W4.IsSymExprBuilder 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 c37a71b

Please sign in to comment.