summaryrefslogtreecommitdiff
path: root/cparser/Cutil.ml
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-09-01 07:08:02 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-09-01 07:08:02 +0000
commit1b8e228a2c5d8f63ffa28c1fcef68f64a0408900 (patch)
treeaf62ff7abe9b492c132b53b9215d401544530dd6 /cparser/Cutil.ml
parente99d18c442c40a14e6eaea722cbc7ef0ca6dd26a (diff)
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
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r--cparser/Cutil.ml26
1 files changed, 26 insertions, 0 deletions
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 =