Skip to content

Commit 50a9311

Browse files
moratorium08dc-mak
authored andcommitted
Use size_t instead of sint for offsetof
1 parent c67c26d commit 50a9311

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

lib/compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ module C_vars = struct
802802
return (IT (SizeOf scty, Memory.size_sbt, loc))
803803
| CNExpr_offsetof (tag, member) ->
804804
let@ _ = lookup_struct loc tag env in
805-
return (IT (OffsetOf (tag, member), Memory.sint_sbt, loc))
805+
return (IT (OffsetOf (tag, member), Memory.size_sbt, loc))
806806
| CNExpr_array_shift (base, ty_annot, index) ->
807807
let@ base = self base in
808808
let@ ct = infer_scty ~pred_loc:loc ~ptr:base `Array_shift ty_annot in

lib/wellTyped.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,9 @@ module WIT = struct
865865
let@ _ty = get_struct_member_type loc tag member in
866866
let@ decl = get_struct_decl loc tag in
867867
let o = Option.get (Memory.member_offset decl member) in
868-
let rs = Option.get (BT.is_bits_bt Memory.sint_bt) in
868+
let rs = Option.get (BT.is_bits_bt Memory.size_bt) in
869869
let@ () = ensure_z_fits_bits_type loc rs (Z.of_int o) in
870-
return (IT (OffsetOf (tag, member), Memory.sint_bt, loc))
870+
return (IT (OffsetOf (tag, member), Memory.size_bt, loc))
871871
| Aligned t ->
872872
let@ t_t = check loc (Loc ()) t.t in
873873
let@ t_align = check loc Memory.uintptr_bt t.align in

tests/cn/offsetof_type.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct s
2+
{
3+
int x;
4+
int y;
5+
};
6+
7+
int main()
8+
{
9+
// C standard defines offsetof to have a size_t type, which we map to u64
10+
/*@ assert (offsetof(s, y) == 4u64); @*/
11+
}

tests/cn/offsetof_type.c.coq

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
return code: 0
2+
[1/1] tests/cn/offsetof_type.c:
3+
CN verify: SUCCESS
4+
Coq compile: SUCCESS
5+
6+
All 1 tests passed!

tests/cn/offsetof_type.c.verify

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
return code: 0
2+
[1/1]: main -- pass

0 commit comments

Comments
 (0)