Skip to content

Commit

Permalink
Fixes incorrect type calculation of bitv *_extend ops
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Nov 6, 2024
1 parent 8f5d2c8 commit f46d245
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ast/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ let rec ty (hte : t) : Ty.t =
ty1
| Triop (ty, _, _, _, _) -> ty
| Relop (ty, _, _, _) -> ty
| Cvtop (Ty_bitv n, (Zero_extend m | Sign_extend m), _) -> Ty_bitv (n + m)
| Cvtop (_, (Zero_extend m | Sign_extend m), hte) -> (
match ty hte with Ty_bitv n -> Ty_bitv (n + m) | _ -> assert false )
| Cvtop (ty, _, _) -> ty
| Naryop (ty, _, _) -> ty
| Extract (_, h, l) -> Ty_bitv ((h - l) * 8)
Expand Down
1 change: 1 addition & 0 deletions test/unit/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
test_unop
test_binop
test_triop
test_ty
test_relop
test_cvtop
test_naryop
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_ty.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
open Smtml

let () =
let x = Expr.symbol (Symbol.make (Ty_bitv 32) "x") in
let x = Expr.extract x ~high:2 ~low:0 in
assert (Ty.equal (Expr.ty x) (Ty_bitv 16));
let x = Expr.cvtop (Ty_bitv 32) (Sign_extend 16) x in
assert (Ty.equal (Expr.ty x) (Ty_bitv 32))

0 comments on commit f46d245

Please sign in to comment.