From 3bf5dcea0935b280189d04c34e84e46fb07f87e7 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 17 Aug 2018 10:58:05 +0200 Subject: Check for bit-fields in __builtin_offsetof __builtin_offsetof(struct s, f) is an error if f is a bit-field. --- cparser/Elab.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 5f785c04..668b65d8 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -1839,7 +1839,10 @@ let elab_expr ctx loc env a = | _ -> fatal_error "request for member '%s' in something not a structure or union" mem in let rec offset_of_list acc env ty = function | [] -> acc,ty - | fld::rest -> let off = offsetof env ty fld in + | fld::rest -> + if fld.fld_bitfield <> None then + error "cannot compute offset of bit-field '%s'" fld.fld_name; + let off = offsetof env ty fld in offset_of_list (acc+off) env fld.fld_typ rest in let offset_of_member (env,off_accu,ty) mem = match mem,unroll env ty with -- cgit