Question

I'm looking at the AMD64 ABI and it does not appear to specify how to pass empty class types. For empty class member functions, it seems that this is passed as usual, but for empty classes, Clang generates code that appears to simply ignore this class. Is this correct according to the AMD64 ABI?

Was it helpful?

Solution

Whilst it is unclear exactly what the question is, the answer is pretty clear as to what the C++ ABI is:

For the C++ ABI we will use the IA-64 C++ ABI and instantiate it appropriately. The current draft of that ABI is available at:

Link to current location of Itanium ABI spec

This says:

Empty classes will be passed no differently from ordinary classes. If passed in registers the NaT bit must not be set on all registers that make up the class.

The contents of the single byte parameter slot are unspecified, and the callee may not depend on any particular value. On Itanium, the associated NaT bit must not be set if the parameter slot is associated with a register.

Another hint is available here:

A result of an empty class type will be returned as though it were a struct containing a single char, i.e. struct S { char c; };. The actual content of the return register is unspecified. On Itanium, the associated NaT bit must not be set.

So, an empty class should be treated like a struct containing a singe char, but that that single char is never used.

Of course, it's possible that there is a bug in clang with regards to empty classes. Although I doubt it, to be fair.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top