[PATCH] D16808: [MCU] PR26438: Fix assertion failure on function returning an empty struct or union
David Kreitzer via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 3 09:07:55 PST 2016
DavidKreitzer added a comment.
Denis, can you please explain your rationale for choosing to return 0-sized aggregates in memory for MCU? It doesn't match gcc behavior. For example,
int g;
union U {} u;
union U f(int a, int b, int c) { g = a + b + c; return u; }
void f1() { f(1, 2, 3); }
Produces this, where all three incoming arguments are in registers. With your patch, %eax will be used for the return value pointer.
f:
addl %eax, %edx
subl $4, %esp
addl %edx, %ecx
movl %ecx, g
popl %eax
ret
(Using i586-intel-elfiamcu-gcc 5.2.1 20150820)
HJ, even though a strict reading of the ABI suggests that a 0-size aggregate should be returned in register, it would be a good idea to make this more explicit in the ABI here, by adding the underlined text, for example.
> **Returning Values**
> Table 2.4 lists the location used to return a value for each fundamental data type.
> Aggregate types (structs and unions) are returned as follows:
> • Short aggregate types no larger than 8 bytes, __including 0-length aggregate types,__ are returned in %edx:%eax.
> The most significant 32 bits are returned in %edx. The least significant 32
> bits are returned in %eax.
> • Other aggregate types are returned in memory.
http://reviews.llvm.org/D16808
More information about the cfe-commits
mailing list