Skip to content

Commit 43f4581

Browse files
committed
[inferbo] Initialize locations for arrays within struct typed variables
1 parent fd0a4e6 commit 43f4581

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

infer/src/bufferoverrun/bufferOverrunUtils.ml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Sem = BufferOverrunSemantics
1616
module Trace = BufferOverrunTrace
1717
module TraceSet = Trace.Set
1818
module TypModels = BufferOverrunTypModels
19+
module BoField = BufferOverrunField
1920

2021
module ModelEnv = struct
2122
type model_env =
@@ -52,14 +53,37 @@ module Exec = struct
5253
mem
5354

5455

55-
let rec decl_local_loc ({tenv} as model_env) loc typ ~inst_num ~represents_multiple_values
56+
let rec decl_local_struct_fields_loc: ModelEnv.model_env -> Loc.t -> Struct.fields -> Dom.Mem.t * int -> Dom.Mem.t * int =
57+
fun model_env loc fields (mem, inst_num) ->
58+
match fields with
59+
| field :: tl -> (
60+
match field with
61+
| (fn, typ, _) -> (
62+
match typ.desc with
63+
| Tarray {elt= _; length; stride} ->
64+
let loc = BoField.Field {prefix= loc; fn; typ = (Some typ)} in
65+
let stride = Option.map ~f:IntLit.to_int_exn stride in
66+
let (mem, inst_num) = decl_local_array model_env loc typ ~length ?stride ~inst_num
67+
~represents_multiple_values:false ~dimension:1 mem
68+
in
69+
(mem, inst_num)
70+
| _ -> decl_local_struct_fields_loc model_env loc tl (mem, inst_num)))
71+
| [] -> (mem, inst_num)
72+
and decl_local_loc ({tenv} as model_env) loc typ ~inst_num ~represents_multiple_values
5673
~dimension mem =
5774
match typ.Typ.desc with
5875
| Typ.Tarray {elt= typ; length; stride} ->
5976
let stride = Option.map ~f:IntLit.to_int_exn stride in
6077
decl_local_array model_env loc typ ~length ?stride ~inst_num ~represents_multiple_values
6178
~dimension mem
6279
| Typ.Tstruct typname -> (
80+
let mem = (
81+
match Tenv.lookup tenv typname with
82+
| Some {fields} ->
83+
let (mem, _) = decl_local_struct_fields_loc model_env loc fields (mem, 1) in mem
84+
| None -> mem
85+
)
86+
in
6387
match TypModels.dispatch tenv typname with
6488
| Some (CArray {element_typ; length}) ->
6589
decl_local_array model_env loc element_typ ~length:(Some length) ~inst_num

0 commit comments

Comments
 (0)