Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fd68e9d
More lemmas about list append
xavierleroy Jun 6, 2021
88589fa
More lemmas about `align`
xavierleroy Jun 7, 2021
4fe221a
Add `floor` and some properties
xavierleroy Jul 26, 2021
a8b197e
Native support for bitfields, first stage
xavierleroy May 17, 2021
32aad7a
Native support for bitfields, second stage
xavierleroy May 20, 2021
319c53f
Test layout of structs with bitfields
xavierleroy May 21, 2021
06caba5
Handle big-endian architectures for bitfield accesses
xavierleroy May 21, 2021
294a07e
Update clightgen for the new representation of struct members
xavierleroy May 31, 2021
73e7945
Interactions between bitfields and packed structs
xavierleroy May 31, 2021
3c2c8b2
On error, always print a diff, even if it contains nonprintable chara…
xavierleroy Jun 5, 2021
9536bdb
Handle bitfields in static initialization
xavierleroy Jun 5, 2021
078b874
Add support for bitfields in union types
xavierleroy Jun 6, 2021
aa2dc8e
Watch out for signedness of bitfields
xavierleroy Jun 7, 2021
b37d718
Introduce Ctypes.{field_offset_stable,union_field_offset_stable}
xavierleroy Jun 10, 2021
57b630f
Int.sign_ext_shr_shl: weaker hypothesis
xavierleroy Jun 10, 2021
a47c8b0
Add Ctypes.link_match_program_gen
xavierleroy Jun 10, 2021
8e53fba
Revise semantics of assignment w.r.t. the return value of an assignment
xavierleroy Jun 8, 2021
8ae201f
Intelligent choice of signedness for bitfields of enum types
xavierleroy Jun 11, 2021
6036c1b
Split bitfield initialization test in two
xavierleroy Jun 11, 2021
f053574
Tweak the layout and staticlayout tests
xavierleroy Jun 11, 2021
091c718
Ignore unnamed members (padding) when computing alignment of struct/u…
xavierleroy Jun 11, 2021
5f8bc05
More careful testing of struct alignment in the presence of padding b…
xavierleroy Jun 11, 2021
0149d1e
Make proofs compatible with older Coq versions
xavierleroy Jun 11, 2021
17f590d
Revised the correctness proof for initializers.
xavierleroy Jun 16, 2021
51e0ab7
Ignore the volatile modifier on bitfield accesses
xavierleroy Jun 24, 2021
458176f
C2C: warn when accessing a bit field of volatile-qualified type
xavierleroy Jun 24, 2021
2dce4f1
Remove the cparser/Bitfields emulation pass; update the -fbitfields o…
xavierleroy Jun 24, 2021
836d9ac
Wrong struct layout for zero-width bit fields
xavierleroy Jul 23, 2021
41509a2
Wrong constraints on bit fields of type _Bool
xavierleroy Jul 23, 2021
f05bf4f
Revert use of `Val.offset_ptr` to evaluate constant Efield expressions
xavierleroy Jul 23, 2021
901a0f3
Bit-field testing: add _Bool fields and zero-width padding fields
xavierleroy Jul 24, 2021
6e14580
Interactions between bitfields and packed structs, continued
xavierleroy Jul 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arm/Asmgenproof1.v
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ Proof.
split. unfold rs2; Simpl. unfold rs1; Simpl.
unfold Val.shr, Val.shl; destruct (rs x0); auto.
change (Int.ltu (Int.repr 24) Int.iwordsize) with true; simpl.
f_equal. symmetry. apply (Int.sign_ext_shr_shl 8). compute; auto.
f_equal. symmetry. apply (Int.sign_ext_shr_shl 8). compute; intuition congruence.
intros. unfold rs2, rs1; Simpl.
(* Ocast16signed *)
destruct Archi.thumb2_support.
Expand All @@ -1231,7 +1231,7 @@ Proof.
split. unfold rs2; Simpl. unfold rs1; Simpl.
unfold Val.shr, Val.shl; destruct (rs x0); auto.
change (Int.ltu (Int.repr 16) Int.iwordsize) with true; simpl.
f_equal. symmetry. apply (Int.sign_ext_shr_shl 16). compute; auto.
f_equal. symmetry. apply (Int.sign_ext_shr_shl 16). compute; intuition congruence.
intros. unfold rs2, rs1; Simpl.
(* Oaddimm *)
generalize (addimm_correct x x0 i k rs m).
Expand Down
39 changes: 34 additions & 5 deletions cfrontend/C2C.ml
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ let checkFunctionType env tres targs =
end
end

let rec convertTyp env t =
let rec convertTyp env ?bitwidth t =
match t with
| C.TVoid a -> Tvoid
| C.TInt(ik, a) ->
Expand Down Expand Up @@ -643,7 +643,21 @@ let rec convertTyp env t =
| C.TUnion(id, a) ->
Tunion(intern_string id.name, convertAttr a)
| C.TEnum(id, a) ->
convertIkind Cutil.enum_ikind (convertAttr a)
let ik =
match bitwidth with
| None -> Cutil.enum_ikind
| Some w ->
let info = Env.find_enum env id in
let representable sg =
List.for_all (fun (_, v, _) -> Cutil.int_representable v w sg)
info.Env.ei_members in
if representable false then
Cutil.unsigned_ikind_of Cutil.enum_ikind
else if representable true then
Cutil.signed_ikind_of Cutil.enum_ikind
else
Cutil.enum_ikind in
convertIkind ik (convertAttr a)

and convertParams env = function
| [] -> Tnil
Expand Down Expand Up @@ -679,9 +693,16 @@ let rec convertTypAnnotArgs env = function
convertTypAnnotArgs env el)

let convertField env f =
if f.fld_bitfield <> None then
unsupported "bit field in struct or union (consider adding option [-fbitfields])";
(intern_string f.fld_name, convertTyp env f.fld_typ)
let id = intern_string f.fld_name
and ty = convertTyp env ?bitwidth: f.fld_bitfield f.fld_typ in
match f.fld_bitfield with
| None -> Member_plain(id, ty)
| Some w ->
match ty with
| Tint(sz, sg, attr) ->
Member_bitfield(id, sz, sg, attr, Z.of_uint w, f.fld_name = "")
| _ ->
fatal_error "bitfield must have type int"

let convertCompositedef env su id attr members =
if Cutil.find_custom_attributes ["packed";"__packed__"] attr <> [] then
Expand Down Expand Up @@ -784,6 +805,11 @@ let convertFloat f kind =

(** Expressions *)

let check_volatile_bitfield env e =
if Cutil.is_bitfield env e
&& List.mem AVolatile (Cutil.attributes_of_type env e.etyp) then
warning Diagnostics.Unnamed "access to a volatile bit field, the 'volatile' qualifier is ignored"

let ezero = Eval(Vint(coqint_of_camlint 0l), type_int32s)

let ewrap = function
Expand All @@ -798,6 +824,7 @@ let rec convertExpr env e =
| C.EUnop((C.Oderef|C.Odot _|C.Oarrow _), _)
| C.EBinop(C.Oindex, _, _, _) ->
let l = convertLvalue env e in
check_volatile_bitfield env e;
ewrap (Ctyping.evalof l)

| C.EConst(C.CInt(i, k, _)) ->
Expand Down Expand Up @@ -867,6 +894,7 @@ let rec convertExpr env e =
if Cutil.is_composite_type env e2.etyp
&& List.mem AVolatile (Cutil.attributes_of_type env e2.etyp) then
warning Diagnostics.Unnamed "assignment of a value of volatile composite type, the 'volatile' qualifier is ignored";
check_volatile_bitfield env e1;
ewrap (Ctyping.eassign e1' e2')
| C.EBinop((C.Oadd_assign|C.Osub_assign|C.Omul_assign|C.Odiv_assign|
C.Omod_assign|C.Oand_assign|C.Oor_assign|C.Oxor_assign|
Expand All @@ -887,6 +915,7 @@ let rec convertExpr env e =
| _ -> assert false in
let e1' = convertLvalue env e1 in
let e2' = convertExpr env e2 in
check_volatile_bitfield env e1;
ewrap (Ctyping.eassignop op' e1' e2')
| C.EBinop(C.Ocomma, e1, e2, _) ->
ewrap (Ctyping.ecomma (convertExpr env e1) (convertExpr env e2))
Expand Down
Loading