On 21.02.2024 17:14, Michael Matz wrote:
> On Wed, 21 Feb 2024, 'Jan Beulich' via X86-64 System V Application Binary Interface wrote:
>
>> searching through the ABI text I can't spot any statement as to it being
>> caller or callee to sign- or zero-extend sub-32-bit values when passing
>> or returning,
>
> Yes, it was intentionally not specified to be in the caller ...
>
>> with two exceptions: There's a footnote for bool, and
>> there's another one for the hidden argument of variadic functions.
>
> ... which originally inadvertedly created a problem for these two (given
> the C promotion rules for variadic unnamed arguments, and confusion about
> which parts of a bool can be relied upon), and so were made explicit.
>
> (Note that not specifying it for the caller implies that the callee
> _needs_ to be able to deal with it, be it by extension or by using
> appropriately short forms of instructions if possible; there's no need to
> specify that explicitely in the psABI).
Hmm, for the avoidance of doubt or (as may have happened here) even
misunderstanding, I think it would have been better to explicitly say
this, even if (like for the two cases mentioned) only in a clarifying
footnote.
>> These two are consistent in leaving it to the callee, and that's also
>> how gcc behaves. Clang, otoh, appears to be assuming that some suitable
>> extension was done by the caller.
>
> For which? varargs and bool?
I've taken the text for these two only for reference, the observed issue is
with ...
> Maybe, those came later to the psABI and
> merely codified existing behaviour (of GCC). If clang also expects
> sext/zext on e.g. short named arguments to have happened in the caller I'd
> say they have a bug.
... this kind of parameters, as in e.g.
void vtest(int, ...);
void test(int i, unsigned char uc) {
vtest(i, uc);
}
int test2(int i, unsigned char uc) {
return i + uc;
}
Clang behavior there appears to be pretty stable over a wide range of
versions.
Jan