LoongArch-Documentation
LoongArch-Documentation copied to clipboard
ambiguous corner cases in calling convention regarding zero-length arrays
Consider such cases:
Case 1:
struct f
{
double x[0]; /* This is a GNU extension. */
double a;
double b;
};
Case 2:
struct f
{
float x[0];
float b;
};
Case 3:
struct f
{
double x[0];
float b;
};
Current calling convention doc is not clear on "if f::x
is considered a member", "if f::x
is considered a floating-point member", and "if f::x
is considered one float
(or double
) member". Note that we are saying:
Empty structures are ignored by C compilers which support them as a non-standard extension
But it does not cover "empty" arrays.
And current GCC trunk is doing strange things (IMO). For Case 2, it passes b
in FAR. But for Case 3, it passes b
in GAR.
In my opinion the most "clear" solution is to ignore the empty arrays (and bitfields: https://gcc.gnu.org/PR102024) altogether with empty aggreates. But that will requires to update GCC behavior, fortunately we still have an oppertunity to do this before GCC 12 release (if we move fast). CC GCC maintainers: @ChenghuaXu @chenglulu
Another solution is to document the current GCC behavior clearly in the doc. ~~But I don't know to write it~~ (as I consider the current behavior "strange").
I've created #49 to cover these corner cases, based on the behavior of GCC trunk. But again, maybe the status quo of GCC is not perfect.
Please note that if you'd like to change GCC behavior it's better to do it ASAP. Once GCC 12 is released, you'll need to write some really boring code to emit -Wpsabi warnings for any ABI change.
GCC patch proposed at https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593397.html.