Skip to content

Commit 6e14580

Browse files
committed
Interactions between bitfields and packed structs, continued
Reject bitfields in packed structs, like before. If we let them through, the resulting CompCert C code implements a strange layout (alignment of regular fields is reduced but alignment of bitfields is unchanged) that is quite different from that of GCC. It's better to reject.
1 parent 901a0f3 commit 6e14580

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cparser/PackedStructs.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let transf_field_decl mfa swapped loc env struct_id f =
6464
(* Register as byte-swapped if needed *)
6565
if swapped then begin
6666
if f.fld_bitfield <> None then
67-
fatal_error loc "cannot byte-swap a bitfield";
67+
error loc "byte-swapped bit fields are not supported";
6868
let (can_swap, must_swap) = can_byte_swap env f.fld_typ in
6969
if not can_swap then
7070
fatal_error loc "cannot byte-swap field of type '%a'"
@@ -74,6 +74,8 @@ let transf_field_decl mfa swapped loc env struct_id f =
7474
end;
7575
(* Reduce alignment if requested *)
7676
if mfa = 0 then f else begin
77+
if f.fld_bitfield <> None then
78+
error loc "bit fields in packed structs are not supported";
7779
let al = safe_alignof loc env f.fld_typ in
7880
{ f with fld_typ =
7981
change_attributes_type env (set_alignas_attr (min mfa al)) f.fld_typ }

0 commit comments

Comments
 (0)