Skip to content

Commit 9b881b7

Browse files
committed
Take the sign into account for int to ptr cast.
Casting from an integer constant to pointer on 64 bit architectures did not take the signedness into account and always interpreted the integer as unsigned which causes some incompatibility with libc implementations.
1 parent 6ca9f9b commit 9b881b7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

cfrontend/Cop.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ Definition classify_cast (tfrom tto: type) : classify_cast_cases :=
140140
| Tfloat F64 _, Tfloat F32 _ => cast_case_s2f
141141
| Tfloat F32 _, Tfloat F64 _ => cast_case_f2s
142142
(* To pointer types *)
143-
| Tpointer _ _, Tint _ _ _ =>
144-
if Archi.ptr64 then cast_case_i2l Unsigned else cast_case_pointer
143+
| Tpointer _ _, Tint _ si _ =>
144+
if Archi.ptr64 then cast_case_i2l si else cast_case_pointer
145145
| Tpointer _ _, Tlong _ _ =>
146146
if Archi.ptr64 then cast_case_pointer else cast_case_l2i I32 Unsigned
147147
| Tpointer _ _, (Tpointer _ _ | Tarray _ _ _ | Tfunction _ _ _) => cast_case_pointer

cfrontend/Ctyping.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ Proof.
987987
classify_cast (Tint i s a) t2 <> cast_case_default).
988988
{
989989
unfold classify_cast. destruct t2; try congruence. destruct f; congruence.
990+
destruct Archi.ptr64; congruence.
990991
}
991992
destruct i; auto.
992993
Qed.

0 commit comments

Comments
 (0)