What happens to empty classes in the AMD64 ABI?

与世无争的帅哥 提交于 2020-01-15 01:24:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16189106/what-happens-to-empty-classes-in-the-amd64-abi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!