Skip to content

Commit 2e97cd7

Browse files
Merge pull request #479 from goblint/no_cilint
Adapt to new CIL with CInt instead of CInt64
2 parents 9ea24ff + 93ff630 commit 2e97cd7

28 files changed

+102
-111
lines changed

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
5858
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
5959
# also remember to generate/adjust goblint.opam.locked!
6060
pin-depends: [
61-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#83835348d20b3f51f1e8e505480b773c9fa5f96b" ]
61+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#64f3010e56563cf78ab3f4535b8614ef8f4e3abf" ]
6262
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
6363
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
6464
# quoter workaround reverted for release, so no pin needed

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ version: "dev"
9494
pin-depends: [
9595
[
9696
"goblint-cil.1.8.2"
97-
"git+https://github.com/goblint/cil.git#83835348d20b3f51f1e8e505480b773c9fa5f96b"
97+
"git+https://github.com/goblint/cil.git#64f3010e56563cf78ab3f4535b8614ef8f4e3abf"
9898
]
9999
[
100100
"apron.v0.9.13"

goblint.opam.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
22
# also remember to generate/adjust goblint.opam.locked!
33
pin-depends: [
4-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#83835348d20b3f51f1e8e505480b773c9fa5f96b" ]
4+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#64f3010e56563cf78ab3f4535b8614ef8f4e3abf" ]
55
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
66
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
77
# quoter workaround reverted for release, so no pin needed

src/analyses/arinc.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct
136136
let is_return_code_type exp = Cilfacade.typeOf exp |> unrollTypeDeep |> function
137137
| TEnum(ei, _) when ei.ename = "T13" -> true
138138
| _ -> false
139-
let return_code_is_success = function 0L | 1L -> true | _ -> false
139+
let return_code_is_success z = Cilint.is_zero_cilint z || Cilint.compare_cilint z Cilint.one_cilint = 0
140140
let str_return_code i = if return_code_is_success i then "SUCCESS" else "ERROR"
141141
let str_return_dlval (v,o as dlval) =
142142
sprint d_lval (Lval.CilLval.to_lval dlval) ^ "_" ^ string_of_int v.vdecl.line |>
@@ -195,7 +195,7 @@ struct
195195
let add_one str_rhs = add_edges env @@ ArincUtil.Assign (str_return_dlval dlval, str_rhs) in
196196
let add_top () = add_edges ~r:(str_return_dlval dlval) env @@ ArincUtil.Nop in
197197
match stripCasts rval with
198-
| Const CInt64(i,_,_) -> add_one @@ str_return_code i
198+
| Const CInt(i,_,_) -> add_one @@ str_return_code i
199199
(* | Lval rlval ->
200200
iterMayPointTo ctx (AddrOf rlval) (fun rdlval -> add_return_dlval env `Read rdlval; add_one @@ str_return_dlval rdlval) *)
201201
| _ -> add_top ()
@@ -212,8 +212,8 @@ struct
212212
let check a b tv =
213213
(* we are interested in a comparison between some lval lval (which has the type of the return code enum) and a value of that enum (which gets converted to an Int by CIL) *)
214214
match a, b with
215-
| Lval lval, Const CInt64(i,_,_)
216-
| Const CInt64(i,_,_), Lval lval when is_return_code_type (Lval lval) ->
215+
| Lval lval, Const CInt(i,_,_)
216+
| Const CInt(i,_,_), Lval lval when is_return_code_type (Lval lval) ->
217217
(* let success = return_code_is_success i = tv in (* both must be true or false *) *)
218218
(* ignore(printf "if %s: %a = %B (line %i)\n" (if success then "success" else "error") d_plainexp exp tv (!Tracing.current_loc).line); *)
219219
(match env.node with

src/analyses/base.ml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,10 @@ struct
509509

510510
let convertToQueryLval x =
511511
let rec offsNormal o =
512+
let ik = Cilfacade.ptrdiff_ikind () in
512513
let toInt i =
513-
match IdxDom.to_int i with
514-
| Some x ->
515-
(* TODO: Handle values outside of int64 *)
516-
let x = BI.to_int64 x in
517-
Const (CInt64 (x,IInt, None))
514+
match IdxDom.to_int @@ ID.cast_to ik i with
515+
| Some x -> Const (CInt (x,ik, None))
518516
| _ -> mkCast (Const (CStr "unknown")) intType
519517

520518
in
@@ -690,10 +688,10 @@ struct
690688
(* query functions were no help ... now try with values*)
691689
match (if get_bool "exp.lower-constants" then constFold true exp else exp) with
692690
(* Integer literals *)
693-
(* seems like constFold already converts CChr to CInt64 *)
691+
(* seems like constFold already converts CChr to CInt *)
694692
| Const (CChr x) -> eval_rv a gs st (Const (charConstToInt x)) (* char becomes int, see Cil doc/ISO C 6.4.4.4.10 *)
695-
| Const (CInt64 (num,ikind,str)) ->
696-
(match str with Some x -> M.tracel "casto" "CInt64 (%s, %a, %s)\n" (Int64.to_string num) d_ikind ikind x | None -> ());
693+
| Const (CInt (num,ikind,str)) ->
694+
(match str with Some x -> M.tracel "casto" "CInt (%s, %a, %s)\n" (Cilint.string_of_cilint num) d_ikind ikind x | None -> ());
697695
`Int (ID.cast_to ikind (IntDomain.of_const (num,ikind,str)))
698696
(* String literals *)
699697
| Const (CStr x) -> `Address (AD.from_string x) (* normal 8-bit strings, type: char* *)
@@ -723,8 +721,8 @@ struct
723721
let cast_ok = function
724722
| Addr a ->
725723
begin
726-
match Cil.isInteger (sizeOf t), Cil.isInteger (sizeOf (get_type_addr a)) with
727-
| Some i1, Some i2 -> Int64.compare i1 i2 <= 0
724+
match Cil.getInteger (sizeOf t), Cil.getInteger (sizeOf (get_type_addr a)) with
725+
| Some i1, Some i2 -> Cilint.compare_cilint i1 i2 <= 0
728726
| _ ->
729727
if contains_vla t || contains_vla (get_type_addr a) then
730728
begin
@@ -1689,7 +1687,7 @@ struct
16891687
let lval_t = Cilfacade.typeOf rval in
16901688
let char_array_hack () =
16911689
let rec split_offset = function
1692-
| Index(Const(CInt64(i, _, _)), NoOffset) -> (* ...[i] *)
1690+
| Index(Const(CInt(i, _, _)), NoOffset) -> (* ...[i] *)
16931691
Index(zero, NoOffset), Some i (* all i point to StartOf(string) *)
16941692
| NoOffset -> NoOffset, None
16951693
| Index(exp, offs) ->
@@ -1706,7 +1704,7 @@ struct
17061704
in
17071705
match last_index lval, stripCasts rval with
17081706
| Some (lv, i), Const(CChr c) when c<>'\000' -> (* "abc" <> "abc\000" in OCaml! *)
1709-
let i = i64_to_int i in
1707+
let i = Cilint.int_of_cilint i in
17101708
(* ignore @@ printf "%a[%i] = %c\n" d_lval lv i c; *)
17111709
let s = try Hashtbl.find char_array lv with Not_found -> Bytes.empty in (* current string for lv or empty string *)
17121710
if i >= Bytes.length s then ((* optimized b/c Out_of_memory *)

src/analyses/deadlock.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct
7878
let rec conv_offset x =
7979
match x with
8080
| `NoOffset -> `NoOffset
81-
| `Index (Const (CInt64 (i,ikind,s)),o) -> `Index (IntDomain.of_const (i,ikind,s), conv_offset o)
81+
| `Index (Const (CInt (i,ikind,s)),o) -> `Index (IntDomain.of_const (i,ikind,s), conv_offset o)
8282
| `Index (_,o) -> `Index (ValueDomain.IndexDomain.top (), conv_offset o)
8383
| `Field (f,o) -> `Field (f, conv_offset o)
8484

src/analyses/expRelation.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
open Prelude.Ana
66
open Analyses
7+
open Cilint
78

89
module Spec : Analyses.MCPSpec =
910
struct
@@ -57,25 +58,26 @@ struct
5758
Basetype.CilExp.equal (canonize e1) (canonize e2)
5859
| Queries.MayBeLess (e1, e2) when not (isFloat e1) ->
5960
begin
61+
(* Compare the cilint first in the hope that it is cheaper than the LVal comparison *)
6062
match e1, e2 with
61-
| BinOp(PlusA, Lval l1, Const(CInt64(i,_,_)), _), Lval l2 when (lvalsEq l1 l2 && Int64.compare i Int64.zero > 0) ->
63+
| BinOp(PlusA, Lval l1, Const(CInt(i,_,_)), _), Lval l2 when (compare_cilint i zero_cilint > 0 && lvalsEq l1 l2) ->
6264
false (* c > 0 => (! x+c < x) *)
63-
| Lval l1, BinOp(PlusA, Lval l2, Const(CInt64(i,_,_)), _) when (lvalsEq l1 l2 && Int64.compare i Int64.zero < 0) ->
65+
| Lval l1, BinOp(PlusA, Lval l2, Const(CInt(i,_,_)), _) when (compare_cilint i zero_cilint < 0 && lvalsEq l1 l2) ->
6466
false (* c < 0 => (! x < x+c )*)
65-
| BinOp(MinusA, Lval l1, Const(CInt64(i,_,_)), _), Lval l2 when (lvalsEq l1 l2 && Int64.compare i Int64.zero < 0) ->
67+
| BinOp(MinusA, Lval l1, Const(CInt(i,_,_)), _), Lval l2 when (compare_cilint i zero_cilint < 0 && lvalsEq l1 l2) ->
6668
false (* c < 0 => (! x-c < x) *)
67-
| Lval l1, BinOp(MinusA, Lval l2, Const(CInt64(i,_,_)), _) when (lvalsEq l1 l2 && Int64.compare i Int64.zero > 0) ->
69+
| Lval l1, BinOp(MinusA, Lval l2, Const(CInt(i,_,_)), _) when (compare_cilint i zero_cilint > 0 && lvalsEq l1 l2) ->
6870
false (* c < 0 => (! x < x-c) *)
6971
| _ ->
7072
true
7173
end
7274
| Queries.MayBeEqual (e1,e2) when not (isFloat e1) ->
7375
begin
7476
match e1,e2 with
75-
| BinOp(PlusA, Lval l1, Const(CInt64(i,_,_)), _), Lval l2
76-
| Lval l2, BinOp(PlusA, Lval l1, Const(CInt64(i,_,_)), _)
77-
| BinOp(MinusA, Lval l1, Const(CInt64(i,_,_)), _), Lval l2
78-
| Lval l2, BinOp(MinusA, Lval l1, Const(CInt64(i,_,_)), _) when (lvalsEq l1 l2) && Int64.compare i Int64.zero <> 0 ->
77+
| BinOp(PlusA, Lval l1, Const(CInt(i,_,_)), _), Lval l2
78+
| Lval l2, BinOp(PlusA, Lval l1, Const(CInt(i,_,_)), _)
79+
| BinOp(MinusA, Lval l1, Const(CInt(i,_,_)), _), Lval l2
80+
| Lval l2, BinOp(MinusA, Lval l1, Const(CInt(i,_,_)), _) when compare_cilint i zero_cilint <> 0 && (lvalsEq l1 l2) ->
7981
false
8082
| _ -> true
8183
end

src/analyses/fileUse.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ struct
8888
let check a b tv =
8989
(* ignore(printf "check: %a = %a, %B\n" d_plainexp a d_plainexp b tv); *)
9090
match a, b with
91-
| Const (CInt64(i, kind, str)), Lval lval
92-
| Lval lval, Const (CInt64(i, kind, str)) ->
91+
| Const (CInt(i, kind, str)), Lval lval
92+
| Lval lval, Const (CInt(i, kind, str)) ->
9393
(* ignore(printf "branch(%s==%i, %B)\n" v.vname (Int64.to_int i) tv); *)
9494
let k = D.key_from_lval lval in
95-
if i = Int64.zero && tv then (
95+
if Cilint.compare_cilint i Cilint.zero_cilint = 0 && tv then (
9696
(* ignore(printf "error-branch\n"); *)
9797
D.error k m
9898
)else

src/analyses/flag.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ struct
5454
let x = var.vname in if List.mem x !noflags then () else
5555
(* let _ = print_endline ( List.fold_left (fun acc a -> a ^ ", " ^ acc) "" !flags ) in *)
5656
(match rval with
57-
| Const (CInt64 (i,_,_)) -> if List.mem x !flags then
57+
| Const (CInt(i,_,_)) -> if List.mem x !flags then
5858
let v = Hashtbl.find vars x in
5959
(* let _ = print_endline ( "assign" ^ (Int64.to_string i)) in *)
6060
(* let _ = print_endline ( x ^ " has values " ^ VSet.fold (fun e str -> (Val.short 50 e) ^", " ^str ) v " ") in *)
61-
if (VSet.mem (Val.of_int i) v) then () else
61+
if (VSet.mem (Val.of_int (Cilint.int64_of_cilint i)) v) then () else (* dubious, but was already like this *)
6262
if (VSet.cardinal v < flagmax) then
6363
(* let _ = print_endline ( "add") in *)
64-
Hashtbl.replace vars x (VSet.add (Val.of_int i) v)
64+
Hashtbl.replace vars x (VSet.add (Val.of_int (Cilint.int64_of_cilint i)) v) (* dubious, but was already like this *)
6565
else begin
6666
(* let _ = print_endline ( "remove") in *)
6767
flags := listrem x !flags;
@@ -71,7 +71,7 @@ struct
7171
end
7272
else begin
7373
flags := x ::!flags;
74-
Hashtbl.add vars x (VSet.add (Val.of_int i) (VSet.empty ()) )
74+
Hashtbl.add vars x (VSet.add (Val.of_int (Cilint.int64_of_cilint i)) (VSet.empty ())) (* dubious, but was already like this *)
7575
end
7676
| _ ->
7777
noflags := x::!noflags; if List.mem x !flags then begin

src/analyses/malloc_null.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct
2323
let rec conv_offset x =
2424
match x with
2525
| `NoOffset -> `NoOffset
26-
| `Index (Const (CInt64 (i,ik,s)),o) -> `Index (IntDomain.of_const (i,ik,s), conv_offset o)
26+
| `Index (Const (CInt (i,ik,s)),o) -> `Index (IntDomain.of_const (i,ik,s), conv_offset o)
2727
| `Index (_,o) -> `Index (IdxDom.top (), conv_offset o)
2828
| `Field (f,o) -> `Field (f, conv_offset o)
2929

0 commit comments

Comments
 (0)