Skip to content

Commit 872b4a5

Browse files
authored
fixes implicit coercion in Primus Lisp monoid operators (#1301)
Arithmetic and bitwise operators in Primus Lisp accept bitvectors of arbitrary lengths and performs implicit coercion of the operands to the greatest sort. However, the first argument was accidentally removed from the coercion, which is now fixed. In addition, the coercion procedure was missing an opportunity to perform the coercion statically, which is done in the new implementation.
1 parent b0c8614 commit 872b4a5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plugins/primus_lisp/primus_lisp_semantic_primitives.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,23 @@ module Primitives(CT : Theory.Core) = struct
345345

346346
type 'a bitv = 'a Theory.Bitv.t Theory.Value.sort
347347

348+
let coerce s x =
349+
if Theory.Value.Sort.same (Theory.Value.sort x) s then !!x
350+
else match const x with
351+
| Some x -> const_int s x
352+
| None -> CT.cast s CT.b0 !!x
353+
348354
let monoid s sf df init xs =
349355
with_nbitv s xs @@ fun s xs -> match xs with
350356
| [] -> forget@@const_int s init
351357
| x :: xs ->
352-
KB.List.fold ~init:x xs ~f:(fun res x ->
358+
let* init = coerce s x in
359+
KB.List.fold ~init xs ~f:(fun res x ->
353360
match const res, const x with
354361
| Some res, Some x ->
355362
const_int s@@sf res x
356363
| _ ->
357-
CT.cast s CT.b0 !!x >>= fun x ->
364+
let* x = coerce s x in
358365
df !!res !!x) |>
359366
forget
360367

0 commit comments

Comments
 (0)