@ -48,8 +48,7 @@ module type S = sig
Tenv . t -> Typ . Procname . t -> CFG . node -> Typ . t -> PowLoc . t -> ? dyn_length : Exp . t
-> Dom . Mem . astate -> Dom . Mem . astate
val structural_copy :
Tenv . t -> Typ . t -> tgt_locs : PowLoc . t -> src_locs : PowLoc . t -> Dom . Mem . astate -> Dom . Mem . astate
val set_dyn_length : Tenv . t -> Typ . t -> PowLoc . t -> Itv . t -> Dom . Mem . astate -> Dom . Mem . astate
end
module Check : sig
@ -171,23 +170,22 @@ module Make (CFG : ProcCfg.S) = struct
init_fields typ locs 1 ? dyn_length mem
let rec structural_copy tenv typ ~ tgt_locs ~ src_locs mem =
match typ with
| { Typ . desc = Tint _ } | { Typ . desc = Tfloat _ } | { Typ . desc = Tvoid } | { Typ . desc = Tptr _ } ->
let v = Dom . Mem . find_heap_set src_locs mem in
Dom . Mem . strong_update_heap tgt_locs v mem
| { Typ . desc = Tarray { elt } } ->
let tgt_locs = Dom . Val . get_all_locs ( Dom . Mem . find_heap_set tgt_locs mem ) in
let src_locs = Dom . Val . get_all_locs ( Dom . Mem . find_heap_set src_locs mem ) in
structural_copy tenv elt ~ tgt_locs ~ src_locs mem
| { Typ . desc = Tstruct typename } -> (
let rec set_dyn_length tenv typ locs dyn_length mem =
match typ . Typ . desc with
| Tstruct typename -> (
match Tenv . lookup tenv typename with
| Some str ->
List . fold str . Typ . Struct . fields ~ init : mem ~ f : ( fun mem ( fn , typ , _ ) ->
let tgt_locs = PowLoc . append_field tgt_locs ~ fn in
let src_locs = PowLoc . append_field src_locs ~ fn in
structural_copy tenv typ ~ tgt_locs ~ src_locs mem )
| None ->
| Some { fields } when not ( List . is_empty fields )
-> (
let field_name , field_typ , _ = List . last_exn fields in
let field_loc = PowLoc . append_field locs ~ fn : field_name in
match field_typ . Typ . desc with
| Tarray { length = Some length } ->
let length = Itv . plus ( Itv . of_int_lit length ) dyn_length in
let v = Dom . Mem . find_set field_loc mem | > Dom . Val . set_array_size length in
Dom . Mem . strong_update_heap field_loc v mem
| _ ->
set_dyn_length tenv field_typ field_loc dyn_length mem )
| _ ->
mem )
| _ ->
mem