RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct

Michael Matz via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 29 07:13:29 PST 2016


Hi,

On Fri, 26 Feb 2016, H.J. Lu wrote:

> >> It is clear to me now.  Let's go with
> >>
> >> ---
> >> An empty type is a type where it and all of its subobjects (recursively)
> >> are of class, structure, union, or array type.  No memory slot nor
> >> register should be used to pass or return an object of empty type that's
> >> trivially copyable.
> >> ---
> >>
> >> Any comments?
> >
> > Yes. "trivially copyable" is the wrong restriction. See
> > http://mentorembedded.github.io/cxx-abi/abi.html#normal-call for the
> > actual Itanium C++ ABI rule.
> 
> I looked it up.  " trivially copyable" is covered by C++ ABI.
> 
> > It's also completely nonsensical to mention this as a special case in
> > relation to empty types. The special case applies to all function
> > parameters, irrespective of whether they're empty -- this rule applies
> > *long* before you consider whether the type is empty. For instance, in
> > the x86-64 psABI, this should go right at the start of section 2.2.3
> > ("Parameter Passing and Returning Values"). But please don't add it
> > there -- it's completely redundant, as section 5.1 already says that
> > the Itanium C++ ABI is used, so it's not necessary to duplicate rules
> > from there.
> 
> Here is the final wording:
> 
> An empty type is a type where it and all of its subobjects (recursively)
> are of class, structure, union, or array type.  No memory slot nor register
> should be used to pass or return an object of empty type.
> 
> Footnote: Array of empty type can only passed by reference in C and C++.
> 
> Michael, can you put it in x86-64 psABI?  I will update i386 and IA MCU
> psABIs.

Not without further discussion, sorry.  If we want to invoke the C++ ABI 
to not have to worry about trivially copyable (and yeah, of course it  
would be placed better at the beginning for the whole argument passing 
section), then we need to also look at its other rules.  In particular at:

----
3.1.3 Empty Parameters 
* 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.
----

So, in C++, empty classes will be passed as above, not as no registers.  
The new rule would create a conflict between "no registers/slots" and "the 
single byte parameter slot".

Have you thought about this?

(I'll also note that putting in this rule might interact with "2.2 POD 
Data Types / If the base ABI does not specify rules for empty classes, 
then an empty class has size and alignment 1." because we now do specify 
rules for empty classes, though not for size and alignment explicitely).

Also this insistence that all of "trivially copyable" is 
already quite nicely specified in the C++ ABI is still not really relevant 
because C++ _is not the only language out there_.  I'm not sure how often 
I have to repeat this until people get it.


Ciao,
Michael.


More information about the cfe-commits mailing list