Sat 04 Aug 2012 12:48:57 PM UTC, original submission:
The current ABI documentation [1] reads:
- Return values: [...] 8-bit return values are zero/sign-extended to 16 bits by the called function [...]
avr-gcc up to 4.2 actually performed that promotion. However, that promotion was not per design, it was just a missed optimization in the compiler (and thus is not suposed to work reliably) and since 4.3 (including respective WinAVR releases) that promotion is no more performed.
There were off-list e-mail threads "AVR GCC 8-bit return values" from 2011-04-02 and "[off-list]: Updating avr-gcc ABI" from 2011-04-20 between Eric, Jörg, Denis and me with the conclusion that the above clause shall be dropped from the ABI.
The changed promotion behavior affects assembler code that calls C function with an 8-bit integer return value and expects that the return value is promoted to 16 bits.
Even the older versions <= 4.2 of the compiler that perform the promotion won't make use of that: Suppose a caller that calls a function returning 8-bit, and the caller needs a 16-bit value. Then the caller performs that extention explicitly and does not rely on the callee returning a 16-bit integer. Sample code:
The ABI document should mention that the promotion performed by the compiler changed with 4.2 -> 4.3 and the promotion up to 4.2 does not work reliably.
Moreover (and unrelated to promotion) the ABI should mention that T-flag in SREG is used the same way like R0 aka. _tmp_reg_.
|