Skip to content

Commit 45b9ba0

Browse files
committed
Move _Bool cast strip from assert to LibraryFunctions
1 parent b235cb9 commit 45b9ba0

File tree

5 files changed

+9
-25
lines changed

5 files changed

+9
-25
lines changed

src/analyses/assert.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ struct
2323
| Some b -> `Lifted b
2424
| None -> `Top
2525
in
26-
let expr =
27-
match e with
28-
| CastE (TInt (IBool, _), expr) -> expr
29-
| Const (CInt (b, IBool, s)) -> Const (CInt (b, IInt, s))
30-
| expr -> expr
31-
in
32-
let expr = CilType.Exp.show expr in
26+
let expr = CilType.Exp.show e in
3327
let warn warn_fn ?annot msg = if check then
3428
if get_bool "dbg.regression" then ( (* This only prints unexpected results (with the difference) as indicated by the comment behind the assert (same as used by the regression test script). *)
3529
let loc = !M.current_loc in

src/analyses/baseInvariant.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,6 @@ struct
855855
inv_exp (Float ftv) exp st
856856

857857
let invariant man st exp tv =
858-
(* TODO: this cast should be supported generally somewhere above *)
859-
let exp =
860-
match exp with
861-
| CastE (TInt (IBool, _), exp) -> exp
862-
| exp -> exp
863-
in
864858
(* The computations that happen here are not computations that happen in the programs *)
865859
(* Any overflow during the forward evaluation will already have been flagged here *)
866860
GobRef.wrap AnalysisState.executing_speculative_computations true

src/cdomain/value/util/wideningThresholds.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ class extractInvariantsVisitor (exps) = object
119119
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) @@ fun () ->
120120
let desc = LibraryFunctions.find f in
121121
begin match desc.special args with
122-
| Assert { exp = CastE (TInt (IBool, _), exp); _ } -> (* TODO: this probably shouldn't be here *)
123-
EH.replace exps exp ();
124-
DoChildren
125122
| Assert { exp; _ } ->
126123
EH.replace exps exp ();
127124
DoChildren

src/cdomains/apron/sharedFunctions.apron.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,6 @@ struct
511511

512512
(** Assert any expression. *)
513513
let assert_inv ask d e negate no_ov =
514-
(* TODO: this cast should be supported generally somewhere above? *)
515-
let e =
516-
match e with
517-
| CastE (TInt (IBool, _), e) -> e
518-
| e -> e
519-
in
520514
let e' =
521515
if exp_is_constraint e then
522516
e

src/util/library/libraryFunctions.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ let intmax_t = lazy (
1616
!res
1717
)
1818

19+
let stripOuterBoolCast = function
20+
| CastE (TInt (IBool, _), e) -> e
21+
| Const (CInt (b, IBool, s)) -> Const (CInt (b, IInt, s))
22+
| e -> e
23+
1924
(** C standard library functions.
2025
These are specified by the C standard. *)
2126
let c_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
@@ -830,9 +835,9 @@ let linux_kernel_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
830835
(** Goblint functions. *)
831836
let goblint_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
832837
("__goblint_unknown", unknown [drop' [w]]);
833-
("__goblint_check", special [__ "exp" []] @@ fun exp -> Assert { exp; check = true; refine = false });
834-
("__goblint_assume", special [__ "exp" []] @@ fun exp -> Assert { exp; check = false; refine = true });
835-
("__goblint_assert", special [__ "exp" []] @@ fun exp -> Assert { exp; check = true; refine = get_bool "sem.assert.refine" });
838+
("__goblint_check", special [__ "exp" []] @@ fun exp -> Assert { exp = stripOuterBoolCast exp; check = true; refine = false });
839+
("__goblint_assume", special [__ "exp" []] @@ fun exp -> Assert { exp = stripOuterBoolCast exp; check = false; refine = true });
840+
("__goblint_assert", special [__ "exp" []] @@ fun exp -> Assert { exp = stripOuterBoolCast exp; check = true; refine = get_bool "sem.assert.refine" });
836841
("__goblint_globalize", special [__ "ptr" []] @@ fun ptr -> Globalize ptr);
837842
("__goblint_split_begin", unknown [drop "exp" []]);
838843
("__goblint_split_end", unknown [drop "exp" []]);

0 commit comments

Comments
 (0)