@@ -102,7 +102,12 @@ object (self)
102102 | Ok (TArray _ ) -> true
103103 | _ -> false
104104
105- method size = sslot.sslot_size
105+ method is_scalar : bool =
106+ match resolve_type self#btype with
107+ | Ok t -> is_scalar t
108+ | _ -> false
109+
110+ method size : int option = sslot.sslot_size
106111
107112 method desc = sslot.sslot_desc
108113
@@ -137,7 +142,9 @@ object (self)
137142 ?(tgtbtype =t_unknown)
138143 (xoffset : xpr_t ): memory_offset_t traceresult =
139144 match xoffset with
140- | XConst (IntConst n ) when n#equal CHNumerical. numerical_zero ->
145+ | XConst (IntConst n)
146+ when n#equal CHNumerical. numerical_zero
147+ && (not self#is_typed || self#is_scalar) ->
141148 Ok NoOffset
142149 | XConst (IntConst n ) when not self#is_typed ->
143150 Ok (ConstantOffset (n, NoOffset ))
@@ -234,6 +241,31 @@ object (self)
234241 match tgtsize with
235242 | Some s -> string_of_int s
236243 | _ -> " ?" in
244+ let check_tgttype_compliance (t : btype_t ) (s : int ) =
245+ match tgtsize, tgtbtype with
246+ | None , None -> true
247+ | Some size , None -> size = s
248+ | Some size , Some (TVoid _ ) -> size = s
249+ | None , Some (TVoid _ ) -> true
250+ | None , Some ty -> btype_equal ty t
251+ | Some size , Some ty -> size = s && btype_equal ty t in
252+ let compliance_failure (t : btype_t ) (s : int ) =
253+ let size_discrepancy size s =
254+ " size discrepancy between tgtsize: "
255+ ^ (string_of_int size)
256+ ^ " and field size: "
257+ ^ (string_of_int s) in
258+ let type_discrepancy ty t =
259+ " type discrepancy between tgttype: "
260+ ^ (btype_to_string ty)
261+ ^ " and field type: "
262+ ^ (btype_to_string t) in
263+ match tgtsize, tgtbtype with
264+ | Some size , Some ty when (size != s) && (not (btype_equal ty t)) ->
265+ (size_discrepancy size s) ^ " and " ^ (type_discrepancy ty t)
266+ | Some size , _ when size != s -> size_discrepancy size s
267+ | _ , Some ty when not (btype_equal ty t) -> type_discrepancy ty t
268+ | _ -> " " in
237269 match xoffset with
238270 | XConst (IntConst n ) ->
239271 let offset = n#toInt in
@@ -266,9 +298,14 @@ object (self)
266298 Ok (Some (FieldOffset
267299 ((finfo.bfname, finfo.bfckey), NoOffset )))
268300 else if offset = 0
269- && (is_scalar fldtype) then
301+ && (is_scalar fldtype)
302+ && (check_tgttype_compliance fldtype sz) then
270303 Ok (Some (FieldOffset
271304 ((finfo.bfname, finfo.bfckey), NoOffset )))
305+ else if offset = 0 && is_scalar fldtype then
306+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
307+ ^ " Scalar type or size is not consistent: "
308+ ^ (compliance_failure fldtype sz)]
272309 else
273310 Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
274311 ^ " Field offset "
@@ -473,25 +510,27 @@ object (self)
473510 end
474511
475512 method add_load
476- ~(offset :int )
513+ ~(baseoffset :int )
514+ ~(offset :memory_offset_t )
477515 ~(size :int option )
478516 ~(typ :btype_t option )
479517 (var : variable_t )
480518 (iaddr :ctxt_iaddress_t ) =
481519 let ty = match typ with Some t -> t | _ -> t_unknown in
482520 let load = StackLoad (var, offset, size, ty) in
483- self#add_access offset iaddr load
521+ self#add_access baseoffset iaddr load
484522
485523 method add_store
486- ~(offset :int )
524+ ~(baseoffset :int )
525+ ~(offset :memory_offset_t )
487526 ~(size :int option )
488527 ~(typ :btype_t option )
489528 ~(xpr :xpr_t option )
490529 (var : variable_t )
491530 (iaddr :ctxt_iaddress_t ) =
492531 let ty = match typ with Some t -> t | _ -> t_unknown in
493532 let store = StackStore (var, offset, size, ty, xpr) in
494- self#add_access offset iaddr store
533+ self#add_access baseoffset iaddr store
495534
496535 method add_block_read
497536 ~(offset :int )
@@ -513,15 +552,13 @@ object (self)
513552 self#add_access offset iaddr store
514553
515554 method private write_xml_stack_slots (node : xml_element_int ) =
516- let slotsnode = xmlElement " stack-slots" in
517555 begin
518556 H. iter (fun _ slot ->
519557 let slotnode = xmlElement " slot" in
520558 begin
521559 slot#write_xml slotnode;
522- slotsnode #appendChildren [slotnode]
560+ node #appendChildren [slotnode]
523561 end ) stackslots;
524- node#appendChildren [slotsnode]
525562 end
526563
527564 method private write_xml_stack_accesses (node : xml_element_int ) =
0 commit comments