I've been reading through Clang source code and discovered something interesting about the ARM C++ ABI that I can't seem to understand the justification for. From the an online version of the ARM ABI documentation:
This ABI requires C1 and C2 constructors to return this (instead of being void functions) so that a C3 constructor can tail call the C1 constructor and the C1 constructor can tail call C2.
(and similarly for non-virtual destructors)
I'm not sure what C1
, C2
, and C3
reference here...this section is meant to be a modification of §3.1.5 from the generic (i.e. Itanium) ABI, but that section (at least in this online verison) simply states:
Constructors return void results.
Anyway, I really can't figure out what the purpose of this is: how does making a constructor return this allow tail call optimization, and in what circumstances?
As far I can tell, the only time a constructor could tail call another with the same this
return value would be the case of a derived class with a single base class, a trivial constructor body, no members with non-trivial constructors, and no virtual table pointer. In fact, it seems like it would actually be easier, not harder, to optimize with a tail call with a void
return, because then the restriction of a single base class could be eliminated (in the multiple base class case, the this
pointer returned from the last called constructor will not be the this
pointer of the derived object).
What am I missing here? Is there something about the ARM calling convention that makes the this
return necessary?