@@ -202,6 +202,8 @@ struct
202202 | `Index (_ ,o ) -> `Index (Idx. top () , of_exp o)
203203 | `Field (f ,o ) -> `Field (f, of_exp o)
204204
205+ let eight = Z. of_int 8
206+
205207 let to_index ?typ (offs : t ): Idx.t =
206208 let idx_of_int x =
207209 Idx. of_int (Cilfacade. ptrdiff_ikind () ) (Z. of_int x)
@@ -211,22 +213,24 @@ struct
211213 | `Field (field , o ) ->
212214 let field_as_offset = Field (field, NoOffset ) in
213215 let bits_offset, _size = GoblintCil. bitsOffset (TComp (field.fcomp, [] )) field_as_offset in
214- let bits_offset = idx_of_int bits_offset in
216+ let bits_offset = Z. of_int bits_offset in
217+ (* Interval of floor and ceil division in case bitfield offset. *)
218+ let bytes_offset = Idx. of_interval (Cilfacade. ptrdiff_ikind () ) Z. (fdiv bits_offset eight, cdiv bits_offset eight) in
215219 let remaining_offset = offset_to_index_offset ~typ: field.ftype o in
216- GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. add bits_offset remaining_offset
220+ GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. add bytes_offset remaining_offset
217221 | `Index (x , o ) ->
218- let (item_typ, item_size_in_bits ) =
222+ let (item_typ, item_size_in_bytes ) =
219223 match Option. map unrollType typ with
220224 | Some TArray (item_typ , _ , _ ) ->
221- let item_size_in_bits = bitsSizeOf item_typ in
222- (Some item_typ, idx_of_int item_size_in_bits )
225+ let item_size_in_bytes = Cilfacade. bytesSizeOf item_typ in
226+ (Some item_typ, idx_of_int item_size_in_bytes )
223227 | _ ->
224228 (None , Idx. top () )
225229 in
226230 (* Binary operations on offsets should not generate overflow warnings in SV-COMP *)
227- let bits_offset = GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. mul item_size_in_bits x in
231+ let bytes_offset = GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. mul item_size_in_bytes x in
228232 let remaining_offset = offset_to_index_offset ?typ:item_typ o in
229- GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. add bits_offset remaining_offset
233+ GobRef. wrap AnalysisState. executing_speculative_computations true @@ fun () -> Idx. add bytes_offset remaining_offset
230234 in
231235 offset_to_index_offset ?typ offs
232236
0 commit comments