diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2017-01-24 10:29:30 +0100 |
---|---|---|
committer | Bernhard Schommer <bernhardschommer@gmail.com> | 2017-01-24 10:29:30 +0100 |
commit | d60b593c8b1d19a4adfdadaeeaa93aa10b9dba53 (patch) | |
tree | 838eef3aa4f09efd467971a51e6c76d49ebb8a59 /cparser/Cutil.ml | |
parent | 47e818992372c1480b1052b64728a33d758637cf (diff) | |
download | compcert-kvx-d60b593c8b1d19a4adfdadaeeaa93aa10b9dba53.tar.gz compcert-kvx-d60b593c8b1d19a4adfdadaeeaa93aa10b9dba53.zip |
New version to support designators.
The c standard allows member designators for offsetof. The current
implementation works by recursively combining the offset of each
of the member designators. For array access the size of the
subtypes is multiplied by the index and for members the offset of
the member is calculated.
Bug 20765
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r-- | cparser/Cutil.ml | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index 30f7294b..f55c1703 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -534,26 +534,23 @@ let sizeof_struct env members = in sizeof_rec 0 members (* Compute the offset of a struct member *) -let offsetof env ty fields = +let offsetof env ty field = let rec sub acc name = function | [] -> List.rev acc | m::rem -> if m.fld_name = name then List.rev acc else sub (m::acc) name rem in - let offset (ofs,ty) field = - match unroll env ty with + match unroll env ty with | TStruct (id,_) -> let str = Env.find_struct env id in let pre = sub [] field.fld_name str.ci_members in begin match sizeof_struct env pre ,alignof env field.fld_typ with | Some s, Some a -> - (ofs + align s a),field.fld_typ + align s a | _ -> assert false end - | _ -> ofs,field.fld_typ - in - let fields = List.rev fields in - fst (List.fold_left offset (0,ty) fields) + | TUnion _ -> 0 + | _ -> assert false (* Simplified version to compute offsets on structs without bitfields *) let struct_layout env members = |