Skip to content
Snippets Groups Projects
Commit 3b851a8b authored by Valentin Perrelle's avatar Valentin Perrelle Committed by David Bühler
Browse files

[Eva] Several fixes from MR review

parent c2832811
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,7 @@ sig ...@@ -56,7 +56,7 @@ sig
val append : t -> t -> t (* Does not check that the appened offset fits *) val append : t -> t -> t (* Does not check that the appened offset fits *)
val join : t -> t -> t val join : t -> t -> t
val of_cil_offset : (Cil_types.exp -> Ival.t) -> Cil_types.typ -> Cil_types.offset -> t val of_cil_offset : (Cil_types.exp -> Ival.t) -> Cil_types.typ -> Cil_types.offset -> t
val of_ival : Cil_types.typ -> Cil_types.typ -> Ival.t -> t val of_ival : base_typ:Cil_types.typ -> typ:Cil_types.typ -> Ival.t -> t
val of_term_offset : Cil_types.typ -> Cil_types.term_offset -> t val of_term_offset : Cil_types.typ -> Cil_types.term_offset -> t
val is_singleton : t -> bool val is_singleton : t -> bool
end end
...@@ -97,7 +97,8 @@ struct ...@@ -97,7 +97,8 @@ struct
match array_size with match array_size with
| None -> None, None | None -> None, None
| Some size_exp -> | Some size_exp ->
Some Integer.zero, Cil.constFoldToInt size_exp Some Integer.zero,
Option.map Integer.pred (Cil.constFoldToInt size_exp)
let array_range array_size = let array_range array_size =
let l,u = array_bounds array_size in let l,u = array_bounds array_size in
...@@ -119,34 +120,34 @@ struct ...@@ -119,34 +120,34 @@ struct
Index (idx, elem_typ, of_cil_offset oracle elem_typ sub) Index (idx, elem_typ, of_cil_offset oracle elem_typ sub)
| _ -> assert false | _ -> assert false
let rec of_ival base_typ typ ival = let rec of_ival ~base_typ ~typ ival =
if Ival.is_zero ival && type_compatible base_typ typ then if Ival.is_zero ival && type_compatible base_typ typ then
NoOffset typ NoOffset typ
else else
match Cil.unrollType base_typ with match Cil.unrollType base_typ with
| TArray (elem_typ, array_size, _, _) -> | TArray (elem_typ, array_size, _, _) ->
begin try let range, rem =
try
let elem_size = Integer.of_int (Cil.bitsSizeOf elem_typ) in let elem_size = Integer.of_int (Cil.bitsSizeOf elem_typ) in
if Integer.is_zero elem_size then (* array of elements of size 0 *) if Integer.is_zero elem_size then (* array of elements of size 0 *)
if Ival.is_zero ival then (* the whole range is valid *) if Ival.is_zero ival then (* the whole range is valid *)
let sub = of_ival elem_typ typ ival in array_range array_size, ival
Index (array_range array_size, elem_typ, sub)
else (* Non-zero offset cannot represent anything here *) else (* Non-zero offset cannot represent anything here *)
raise Abstract_interp.Error_Top raise Abstract_interp.Error_Top
else else
let range = Ival.scale_div ~pos:true elem_size ival Ival.scale_div ~pos:true elem_size ival,
and range_rem = Ival.scale_rem ~pos:true elem_size ival in Ival.scale_rem ~pos:true elem_size ival
let sub = of_ival elem_typ typ range_rem in
Index (range, elem_typ, sub)
with Cil.SizeOfError (_,_) -> with Cil.SizeOfError (_,_) ->
(* Cil.bitsSizeOf can raise an exception when elements are (* Cil.bitsSizeOf can raise an exception when elements are
themselves array of execution-time size *) themselves array of execution-time size *)
if Ival.is_zero ival then if Ival.is_zero ival then
let sub = of_ival elem_typ typ ival in ival, ival
Index (ival, elem_typ, sub)
else else
raise Abstract_interp.Error_Top raise Abstract_interp.Error_Top
end in
assert_valid_index range array_size;
let sub = of_ival ~base_typ:elem_typ ~typ rem in
Index (range, elem_typ, sub)
| TComp (ci, _, _) -> | TComp (ci, _, _) ->
if not ci.cstruct then if not ci.cstruct then
...@@ -158,11 +159,11 @@ struct ...@@ -158,11 +159,11 @@ struct
| fi :: q -> | fi :: q ->
let offset, width = Cil.fieldBitsOffset fi in let offset, width = Cil.fieldBitsOffset fi in
let l = Integer.(of_int offset) in let l = Integer.(of_int offset) in
let u = Integer.(add l (of_int width)) in let u = Integer.(pred (add l (of_int width))) in
let range = Ival.inject_range (Some l) (Some u) in let range = Ival.inject_range (Some l) (Some u) in
if Ival.is_included ival range then if Ival.is_included ival range then
let sub_ival = Ival.add_singleton_int (Integer.neg l) ival in let sub_ival = Ival.add_singleton_int (Integer.neg l) ival in
Field (fi, of_ival fi.ftype typ sub_ival) Field (fi, of_ival ~base_typ:fi.ftype ~typ sub_ival)
else else
find_field q find_field q
in in
...@@ -170,14 +171,14 @@ struct ...@@ -170,14 +171,14 @@ struct
| _ -> raise Abstract_interp.Error_Top | _ -> raise Abstract_interp.Error_Top
let of_ival base_typ typ ival = let of_ival ~base_typ ~typ ival =
if Ival.is_small_set ival then if Ival.is_small_set ival then
let f i acc = let f i acc =
Bottom.join join acc (`Value (of_ival base_typ typ i)) Bottom.join join acc (`Value (of_ival ~base_typ ~typ i))
in in
Bottom.non_bottom (Ival.fold_enum f ival `Bottom) Bottom.non_bottom (Ival.fold_enum f ival `Bottom)
else else
of_ival base_typ typ ival of_ival ~base_typ ~typ ival
let index_of_term array_size t = (* Exact constant ranges *) let index_of_term array_size t = (* Exact constant ranges *)
match t.Cil_types.term_node with match t.Cil_types.term_node with
...@@ -239,8 +240,8 @@ struct ...@@ -239,8 +240,8 @@ struct
try `Value (TypedOffset.of_cil_offset oracle base_typ offset) try `Value (TypedOffset.of_cil_offset oracle base_typ offset)
with Abstract_interp.Error_Top -> `Top with Abstract_interp.Error_Top -> `Top
let of_ival base_typ typ ival = let of_ival ~base_typ ~typ ival =
try `Value (TypedOffset.of_ival base_typ typ ival) try `Value (TypedOffset.of_ival ~base_typ ~typ ival)
with Abstract_interp.Error_Top -> `Top with Abstract_interp.Error_Top -> `Top
let of_term_offset base_typ toffset = let of_term_offset base_typ toffset =
......
...@@ -28,7 +28,7 @@ sig ...@@ -28,7 +28,7 @@ sig
val append : t -> t -> t (* Does not check that the appened offset fits *) val append : t -> t -> t (* Does not check that the appened offset fits *)
val join : t -> t -> t val join : t -> t -> t
val of_cil_offset : (Cil_types.exp -> Ival.t) -> Cil_types.typ -> Cil_types.offset -> t val of_cil_offset : (Cil_types.exp -> Ival.t) -> Cil_types.typ -> Cil_types.offset -> t
val of_ival : Cil_types.typ -> Cil_types.typ -> Ival.t -> t val of_ival : base_typ:Cil_types.typ -> typ:Cil_types.typ -> Ival.t -> t
val of_term_offset : Cil_types.typ -> Cil_types.term_offset -> t val of_term_offset : Cil_types.typ -> Cil_types.term_offset -> t
val is_singleton : t -> bool val is_singleton : t -> bool
end end
......
...@@ -127,7 +127,7 @@ struct ...@@ -127,7 +127,7 @@ struct
type location = Abstract_offset.typed_offset type location = Abstract_offset.typed_offset
type value = Value.t type value = Value.t
type 'fieldmap memory' = type 'fieldmap memory =
| Raw of bit | Raw of bit
| Scalar of memory_scalar | Scalar of memory_scalar
| Struct of 'fieldmap memory_struct | Struct of 'fieldmap memory_struct
...@@ -140,16 +140,16 @@ struct ...@@ -140,16 +140,16 @@ struct
and 'fieldmap memory_struct = { and 'fieldmap memory_struct = {
struct_value: 'fieldmap; struct_value: 'fieldmap;
struct_info: Cil_types.compinfo; struct_info: Cil_types.compinfo;
struct_padding: bit; (* for missing fields *) struct_padding: bit; (* for missing fields and padding *)
} }
(* unions are handled separately from struct to avoid confusion and error *) (* unions are handled separately from struct to avoid confusion and error *)
and 'fieldmap memory_union = { and 'fieldmap memory_union = {
union_value: 'fieldmap memory'; union_value: 'fieldmap memory;
union_field: Cil_types.fieldinfo; union_field: Cil_types.fieldinfo;
union_padding: bit; union_padding: bit;
} }
and 'fieldmap memory_array = { and 'fieldmap memory_array = {
array_value: 'fieldmap memory'; array_value: 'fieldmap memory;
array_cell_type: Cil_types.typ; array_cell_type: Cil_types.typ;
} }
...@@ -166,7 +166,7 @@ struct ...@@ -166,7 +166,7 @@ struct
end end
module rec Memory : module rec Memory :
Hptmap.V with type t = FieldMap.t memory' = Hptmap.V with type t = FieldMap.t memory =
struct struct
include Datatype.Make ( include Datatype.Make (
struct struct
...@@ -183,14 +183,14 @@ struct ...@@ -183,14 +183,14 @@ struct
to FieldMap and no constants, only functions *) to FieldMap and no constants, only functions *)
and MemorySafe : and MemorySafe :
sig sig
type t = FieldMap.t memory' type t = FieldMap.t memory
val pretty : Format.formatter -> t -> unit val pretty : Format.formatter -> t -> unit
val hash : t -> int val hash : t -> int
val equal : t -> t -> bool val equal : t -> t -> bool
val compare : t -> t -> int val compare : t -> t -> int
end = end =
struct struct
type t = FieldMap.t memory' type t = FieldMap.t memory
let rec pretty fmt = let rec pretty fmt =
let rec leading_indexes acc = function let rec leading_indexes acc = function
......
...@@ -227,7 +227,7 @@ end ...@@ -227,7 +227,7 @@ end
module DomainPrototype = module DomainPrototype =
struct struct
(* The domain is essentially a map from bases to individual memory abstractions *) (* The domain is essentially a map from bases to individual memory abstractions *)
module Initial_Values = struct let v = [] end module Initial_Values = struct let v = [[]] end
module Deps = struct let l = [Ast.self] end module Deps = struct let l = [Ast.self] end
include Hptmap.Make include Hptmap.Make
...@@ -269,7 +269,7 @@ struct ...@@ -269,7 +269,7 @@ struct
let decide _ v1 v2 = let decide _ v1 v2 =
Memory.narrow v1 v2 Memory.narrow v1 v2
in in
let narrow = join ~cache ~symmetric:true ~idempotent:true ~decide in let narrow = join ~cache ~symmetric:false ~idempotent:true ~decide in
fun a b -> `Value (narrow a b) fun a b -> `Value (narrow a b)
let join = let join =
......
...@@ -138,7 +138,6 @@ module Domains = ...@@ -138,7 +138,6 @@ module Domains =
let arg_name = "d1,...,dn" let arg_name = "d1,...,dn"
let help = "Enable a list of analysis domains." let help = "Enable a list of analysis domains."
let default = Datatype.String.Set.of_list ["cvalue"] let default = Datatype.String.Set.of_list ["cvalue"]
(* let default = Datatype.String.Set.singleton "cvalue" *)
end) end)
let () = add_precision_dep Domains.parameter let () = add_precision_dep Domains.parameter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment