Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

ambiguous corner cases in calling convention regarding zero-length arrays #48

Open
xry111 opened this issue Apr 19, 2022 · 3 comments
Open

Comments

@xry111
Copy link
Contributor

xry111 commented Apr 19, 2022

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").

xry111 added a commit to xry111/LoongArch-Documentation that referenced this issue Apr 19, 2022
xry111 added a commit to xry111/LoongArch-Documentation that referenced this issue Apr 19, 2022
xry111 added a commit to xry111/LoongArch-Documentation that referenced this issue Apr 19, 2022
@xry111
Copy link
Contributor Author

xry111 commented Apr 19, 2022

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.

@xry111
Copy link
Contributor Author

xry111 commented Apr 19, 2022

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.

xry111 added a commit to xry111/LoongArch-Documentation that referenced this issue Apr 19, 2022
@xry111
Copy link
Contributor Author

xry111 commented Apr 20, 2022

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant