From 1b8e228a2c5d8f63ffa28c1fcef68f64a0408900 Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 1 Sep 2010 07:08:02 +0000 Subject: Bugs with 1- empty bitfields, 2- anonymous bitfields, 3- result type of reading a small unsigned bitfield git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1496 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Cutil.ml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cparser/Cutil.ml') diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index c7c5e30..cb241e5 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -409,6 +409,16 @@ let unsigned_ikind_of = function | ILong | IULong -> IULong | ILongLong | IULongLong -> IULongLong +(* Conversion to signed ikind *) + +let signed_ikind_of = function + | IBool -> IBool + | IChar | ISChar | IUChar -> ISChar + | IInt | IUInt -> IInt + | IShort | IUShort -> IShort + | ILong | IULong -> ILong + | ILongLong | IULongLong -> ILongLong + (* Some classification functions over types *) let is_void_type env t = @@ -559,6 +569,22 @@ let pointer_arithmetic_ok env ty = | TVoid _ | TFun _ -> false | _ -> not (incomplete_type env ty) +(** The type of [x.fld]. Normally, it's the type of the field [fld], + but if it is an unsigned bitfield of size < length of its type, + its type is the corresponding signed int. *) + +let type_of_member env fld = + match fld.fld_bitfield with + | None -> fld.fld_typ + | Some w -> + match unroll env fld.fld_typ with + | TInt(ik, attr) -> + if w < sizeof_ikind ik * 8 + then TInt(signed_ikind_of ik, attr) + else fld.fld_typ + | _ -> + assert false + (** Special types *) let find_matching_unsigned_ikind sz = -- cgit v1.2.3