aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Bitfields.ml
diff options
context:
space:
mode:
Diffstat (limited to 'cparser/Bitfields.ml')
-rw-r--r--cparser/Bitfields.ml13
1 files changed, 7 insertions, 6 deletions
diff --git a/cparser/Bitfields.ml b/cparser/Bitfields.ml
index 696a9a8d..7a00f719 100644
--- a/cparser/Bitfields.ml
+++ b/cparser/Bitfields.ml
@@ -50,8 +50,7 @@ let bitfield_table =
(Hashtbl.create 57: (ident * string, bitfield_info) Hashtbl.t)
let is_bitfield structid fieldname =
- try Some (Hashtbl.find bitfield_table (structid, fieldname))
- with Not_found -> None
+ Hashtbl.find_opt bitfield_table (structid, fieldname)
(* Mapping struct/union identifier -> list of members after transformation,
including the carrier fields, but without the bit fields.
@@ -189,10 +188,12 @@ let rec transf_union_members env id count = function
{ fld_name = carrier; fld_typ = carrier_typ; fld_bitfield = None; fld_anonymous = false;}
:: transf_union_members env id (count + 1) ms)
-let transf_composite env su id attr ml =
+let transf_composite env loc su id attr ml =
if List.for_all (fun f -> f.fld_bitfield = None) ml then
(attr, ml)
else begin
+ if find_custom_attributes ["packed";"__packed__"] attr <> [] then
+ Diagnostics.error loc "bitfields in packed structs not allowed";
let ml' =
match su with
| Struct -> transf_struct_members env id 1 ml
@@ -550,7 +551,7 @@ and transf_init env i =
(* Declarations *)
-let transf_decl env (sto, id, ty, init_opt) =
+let transf_decl env loc (sto, id, ty, init_opt) =
(sto, id, ty,
match init_opt with None -> None | Some i -> Some(transf_init env i))
@@ -559,12 +560,12 @@ let transf_decl env (sto, id, ty, init_opt) =
let transf_stmt env s =
Transform.stmt
~expr:(fun loc env ctx e -> transf_exp env ctx e)
- ~decl:transf_decl
+ ~decl:(fun env (sto, id, ty, init_opt) -> transf_decl env s.sloc (sto, id, ty, init_opt))
env s
(* Functions *)
-let transf_fundef env f =
+let transf_fundef env loc f =
Transform.fundef transf_stmt env f
(* Programs *)