Skip to content

Commit 3bdb983

Browse files
committed
AArch64: normalize function return values of small integer type
According to AAPCS64 (the AArch64 ABI specification), the top bits of the register containing the function result have unspecified value, so we need to sign- or zero-extend the function result before using it, as in the x86 port.
1 parent 3bffda8 commit 3bdb983

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

aarch64/Conventions1.v

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ Qed.
379379

380380
(** ** Normalization of function results *)
381381

382-
(** No normalization needed. *)
383-
384-
Definition return_value_needs_normalization (t: rettype) := false.
382+
(** According to the AAPCS64 ABI specification, "padding bits" in the return
383+
value of a function have unpredictable values and must be ignored.
384+
Consequently, we force normalization of return values of small integer
385+
types (8- and 16-bit integers), so that the top bits (the "padding bits")
386+
are proper sign- or zero-extensions of the small integer value. *)
387+
388+
Definition return_value_needs_normalization (t: rettype) : bool :=
389+
match t with
390+
| Tint8signed | Tint8unsigned | Tint16signed | Tint16unsigned => true
391+
| _ => false
392+
end.

0 commit comments

Comments
 (0)