Open llvmbot opened 5 years ago
I absolutely agree, nullptr / nullptr_t makes perfect sense in the language, the weirdness is in 'what is it then?' for places where a more formal definition is needed on its exact nature, class / non class / layout / bits.
C++ defines how it should behave within the language, but the ABI for parameter passing is an entirely separate question. Or would be if we hadn’t sleepwalked into making it a pointer, as Richard points out.
std::nullptr_t
is weird in many ways unfortunately..... Neither GCC or Clang consider it empty class (or even, a class at all, try struct Foo : std::nullptr_t {}
:)
It is in non-aggregate already passed as POINTER, not empty struct, GCC and Clang are in agreement on that, e.g. https://gcc.godbolt.org/z/1DsKOt
:( OK. That's grossly wasteful, but being consistent with that makes sense.
It is in non-aggregate already passed as POINTER, not empty struct, GCC and Clang are in agreement on that, e.g. https://gcc.godbolt.org/z/1DsKOt
I suppose even without official documentation treating it as a pointer is probably the obvious choice.
I am unconvinced; treating it as an empty struct seems more appropriate, considering it comprises only padding bits. And empty structs aren't passed at all.
I suppose even without official documentation treating it as a pointer is probably the obvious choice.
GCC does this correct.
Is this something we have to take GCC's word for (i.e. it got there first/is bigger and unilaterally decided the ABI) or is it derivable from ABI documents? I couldn't see any reference in the psABI.
Extended Description
When you create a trivial aggregate containing
std::nullptr_t
, it does not get passed through RDI/RSI, but gets classified as a memory argE.g.:
GCC does this correct.
More elaborate examples: https://gcc.godbolt.org/z/IxLudk