Skip to content

Commit 70a56da

Browse files
committed
[Editorial] Restructure the section on functions and calling conventions
- Reorganize it into separate subsections for function definitions, parameter conventions, and return-value conventions. - Cross-reference the alignment requirement on non-static member functions, since it's easy to miss. - Be explicit about the handling of this and VTT parameters. The wording for empty parameters and return values leaves much to be desired, but I've left it as-is to make this a more purely editorial change. a# Please enter the commit message for your changes. Lines starting
1 parent e2966f8 commit 70a56da

File tree

1 file changed

+166
-102
lines changed

1 file changed

+166
-102
lines changed

abi.html

Lines changed: 166 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ <h2> Contents </h2>
3939
<li> <a href=#guards> 2.8 Initialization Guard Variables </a>
4040
<li> <a href=#rtti> 2.9 Run-Time Type Information (RTTI) </a>
4141
</ul>
42-
<li> <a href=#calls> Chapter 3: Function Calling Conventions and APIs </a>
42+
<li> <a href=#calls> Chapter 3: Code Emission and APIs </a>
4343
<ul>
44-
<li> <a href=#normal-call> 3.1 Non-virtual Function Calling Conventions </a>
45-
<li> <a href=#vcall> 3.2 Virtual Function Calling Conventions </a>
44+
<li> <a href=#functions> 3.1 Functions</a>
45+
<li> <a href=#vcall> 3.2 Virtual Calls</a>
4646
<li> <a href=#obj-ctor> 3.3 Construction and Destruction APIs</a>
4747
<li> <a href=#demangler> 3.4 Demangler API</a>
4848
</ul>
@@ -2793,15 +2793,11 @@ <h4><a href="#exception-matching-algorithm"> 2.9.8 The Exception Handler Matchin
27932793

27942794
<p> <hr> <p>
27952795
<a name="calls">
2796-
<h2><a href="#calls"> Chapter 3: Function Calling Conventions and APIs </a></h2>
2797-
<p> <hr> <p>
2796+
<h2><a href="#calls"> Chapter 3: Code Emission and APIs </a></h2>
2797+
<p> <hr>
27982798

27992799
<p>
2800-
In general, the calling conventions for C++ in this ABI
2801-
follow those specified by the underlying processor-specific ABI for C,
2802-
whenever there is an analogous construct in C.
2803-
This chapter specifies exceptions required by C++-specific semantics,
2804-
or by features without analogues in C.
2800+
This chapter describes how to define and call functions.
28052801
It also specifies the APIs of a variety of runtime utility routines
28062802
required to be part of the support library of an ABI-conforming
28072803
implementation for use by compiled code.
@@ -2810,96 +2806,137 @@ <h2><a href="#calls"> Chapter 3: Function Calling Conventions and APIs </a></h2>
28102806
which defines a large number of runtime utility routine APIs.
28112807

28122808
<p>
2813-
<a name="normal-call">
2814-
<h3><a href="#normal-call"> 3.1 Non-Virtual Function Calling Conventions </a></h3>
2809+
<a name="functions">
2810+
<h3><a href="#functions">3.1 Functions</a></h3>
28152811
</a>
28162812

28172813
<p>
2818-
<a name="value-parameter">
2819-
<h4><a href="#value-parameter"> 3.1.1 Value Parameters </a></h4>
2814+
In general, the calling conventions and rules for defining C++
2815+
functions in this ABI follow those specified for functions of
2816+
the corresponding type in the base C ABI. The corresponding type
2817+
is mostly determined by translating C++ constructs to their
2818+
obvious C analogues. This section specifies the behavior of
2819+
of features without analogues in C, as well as some exceptions
2820+
and extra rules required by C++-specific semantics.
28202821

28212822
<p>
2822-
In general, C++ value parameters are handled just like C parameters.
2823-
This includes class type parameters passed wholly or partially in registers.
2824-
There are, however, some special cases.
2825-
</p>
2826-
<ol type="1">
2827-
<li>
2828-
<p>
2829-
If the parameter type is <a href="#non-trivial">non-trivial for the
2830-
purposes of calls</a>, the caller must allocate space for a temporary
2831-
and pass that temporary by reference. Specifically:
2832-
</p>
2833-
<ul>
2834-
<li>Space is allocated by the caller in the usual manner for a temporary,
2835-
typically on the stack.</li>
2836-
<li>The caller evaluates the argument in the space provided.</li>
2837-
<li>The function is called, passing the address of the temporary as the
2838-
appropriate argument. In the callee, the address passed is used
2839-
as the address of the parameter variable.</li>
2840-
<li>If the type has a non-trivial destructor, the caller calls that
2841-
destructor after control returns to it (including when the caller
2842-
throws an exception), at the end of enclosing full-expression.
2843-
<li>If necessary (e.g. if the temporary was allocated on the heap),
2844-
the caller deallocates space after return and destruction.
2845-
</ul>
2823+
<a name="function-defs">
2824+
<h4><a href="#function-defs">3.1.1 Function Definitions</a></h4>
28462825

2847-
<p>
2848-
A C-style variadic argument of a type that is non-trivial for the
2849-
purposes of calls is passed the same way: the address of the temporary
2850-
is passed using the normal variadic mechanism, and <code>va_arg</code> in
2851-
the callee retrieves the address and treats it as a reference to the
2852-
temporary.
2853-
</li>
2854-
<li>
2855-
<p>
2856-
In the case where the parameter type is class
2857-
<code>std::decimal::decimal32</code>,
2858-
<code>std::decimal::decimal64</code>, or
2859-
<code>std::decimal::decimal128</code> as defined in TR 24733, the
2860-
parameter is passed the same as the corresponding native decimal
2861-
floating-point scalar type.
2862-
</p>
2863-
</li>
2864-
</ol>
2826+
<p>
2827+
For the most part, non-static member functions, including constructors
2828+
and destructors, are defined as if they were ordinary functions except
2829+
for the addition of the implicit parameters to the prototype as
2830+
described in the <a href="#parameters">section on parameters</a>.
2831+
2832+
<p>
2833+
The rules for <a href="#member-function-pointers">member function
2834+
pointers</a> may require aligning the first instruction of ordinary
2835+
non-static member functions (i.e. not constructors or destructors)
2836+
to a higher value than the platform would normally require.
2837+
2838+
<a name="parameters">
2839+
<h4><a href="#parameters">3.1.2 Parameters</a></h4>
2840+
</a>
2841+
2842+
<p>
2843+
<a name="this-parameters">
2844+
<h5><a href="#this-parameters">3.1.2.1 <code>this</code> Parameters</a></h5>
2845+
2846+
<p>
2847+
Non-static member functions, including constructors and destructors,
2848+
take an implicit <code>this</code> parameter of pointer type. It is
2849+
passed as if it were the first parameter in the function prototype,
2850+
except as modified for <a href="#non-trivial-return-values">non-trivial
2851+
return values</a>.
2852+
2853+
<p>
2854+
<a name="vtt-parameters">
2855+
<h5><a href="#vtt-parameters">3.1.2.2 <code>VTT</code> Parameters</a></h5>
28652856

28662857
<p>
2867-
<a name="reference-parameter">
2868-
<h4><a href="#reference-parameter"> 3.1.2 Reference Parameters </a></h4>
2858+
Base-subobject constructors and destructors for classes with virtual
2859+
bases take an implicit <a href="#vtable-ctor"><code>VTT</code></a>
2860+
parameter of pointer type. It is passed as if it were the second
2861+
parameter in the function prototype, immediately following the
2862+
<code>this</code> parameter, except as modified for
2863+
<a href="#non-trivial-return-values">non-trivial return values</a>.
2864+
2865+
<p>
2866+
<a name="non-trivial-parameters">
2867+
<h5><a href="#non-trivial-parameters">3.1.2.3 Non-Trivial Parameters</a></h5>
2868+
2869+
<p>
2870+
If a parameter type is a class type that is
2871+
<a href="#non-trivial">non-trivial for the purposes of calls</a>, the
2872+
caller must allocate space for a temporary and pass that temporary by
2873+
reference. Specifically:
2874+
2875+
<ul>
2876+
<li>Space is allocated by the caller in the usual manner for a temporary,
2877+
typically on the stack.</li>
2878+
<li>The caller evaluates the argument in the space provided.</li>
2879+
<li>The function is called, passing the address of the temporary as the
2880+
appropriate argument. In the callee, the address passed is used
2881+
as the address of the parameter variable.</li>
2882+
<li>If the type has a non-trivial destructor, the caller calls that
2883+
destructor after control returns to it (including when the caller
2884+
throws an exception).
2885+
<li>If necessary (e.g. if the temporary was allocated on the heap),
2886+
the caller deallocates space after return and destruction.
2887+
</ul>
2888+
2889+
<p>
2890+
A C-style variadic argument of a type that is non-trivial for the
2891+
purposes of calls is passed the same way: the address of the temporary
2892+
is passed using the normal variadic mechanism, and <code>va_arg</code> in
2893+
the callee retrieves the address and treats it as a reference to the
2894+
temporary.
2895+
2896+
<a name="special-class-parameters">
2897+
<h5><a href="#special-class-parameters">3.1.2.4 Parameters of Special Class Type</a></h5>
2898+
2899+
<p>
2900+
An argument of class
2901+
<code>std::decimal::decimal32</code>,
2902+
<code>std::decimal::decimal64</code>, or
2903+
<code>std::decimal::decimal128</code> as defined in TR 24733
2904+
is passed the same as the corresponding native decimal
2905+
floating-point scalar type.
2906+
2907+
<p>
2908+
<a name="reference-parameters">
2909+
<h5><a href="#reference-parameters">3.1.2.5 Reference Parameters</a></h5>
28692910

28702911
<p>
28712912
Reference parameters are handled by passing a pointer to the object
28722913
bound to the reference.
28732914

28742915
<p>
2875-
<a name="empty-parameter">
2876-
<h4><a href="#empty-parameter"> 3.1.3 Empty Parameters </a></h4>
2916+
<a name="empty-parameters">
2917+
<h5><a href="#empty-parameters">3.1.2.6 Empty Parameters</a></h5>
28772918

28782919
<p>
2879-
Empty classes will be passed no differently from ordinary classes. If
2880-
passed in registers the NaT bit must not be set on all registers that
2881-
make up the class.
2882-
</p>
2920+
Arguments of empty class types that are not non-trivial for the purposes
2921+
of calls are passed no differently from ordinary classes.
28832922

28842923
<p>
2885-
The contents of the single byte parameter slot are unspecified,
2886-
and the callee may not depend on any particular value.
2887-
On Itanium, the associated NaT bit must not be set
2888-
if the parameter slot is associated with a register.
2889-
2924+
On Itanium, the NaT bit must be set on all registers that are associated
2925+
with the argument.
28902926

28912927
<p>
2892-
<a name="return-value">
2893-
<h4><a href="#return-value"> 3.1.4 Return Values </a></h4>
2928+
<a name="return-values">
2929+
<h4><a href="#return-values">3.1.3 Return Values</a></h4>
28942930

28952931
<p>
2896-
In general, C++ return values are handled just like C return values.
2897-
This includes class type results returned in registers.</p>
2932+
<a name="non-trivial-return-values">
2933+
<h5><a href="#non-trivial-return-values">3.1.3.1 Non-trivial Return Values</a></h5>
28982934

28992935
<p>
2900-
However, if the return type is <a href="#non-trivial">non-trivial for
2901-
the purposes of calls</a>, the caller passes an address as an implicit
2902-
parameter. The callee then constructs the return value into this address.
2936+
If the return type is a class type that is
2937+
<a href="#non-trivial">non-trivial for the purposes of calls</a>,
2938+
the caller passes an address as an implicit parameter.
2939+
The callee then constructs the return value into this address.
29032940
If the return type has a non-trivial destructor, the caller is responsible
29042941
for destroying the temporary when control is returned to it <i>normally</i>.
29052942
If an exception is thrown out of the callee after the return value is
@@ -2908,61 +2945,88 @@ <h4><a href="#return-value"> 3.1.4 Return Values </a></h4>
29082945
return value before propagating the exception to the caller. Thus,
29092946
in general, the caller is responsible for destroying the return value
29102947
after, and only after, the callee returns control to the caller normally.
2911-
</p>
29122948

29132949
<p>
29142950
The address passed need not be of temporary memory; copy elision may
29152951
cause it to point anywhere, including to global or heap-allocated memory.
2952+
29162953
<p>
2954+
C ABIs usually provide treatment for "indirect" return values, e.g. when
2955+
returning a large aggregate that cannot fit in registers. In some cases,
2956+
this treatment may not be suitable for non-trivial C++ return values, such
2957+
as if the convention requires implicit copying or does not permit the
2958+
return value to be constructed at an arbitrary address. If the treatment
2959+
exists and is suitable, it is used for non-trivial return values.
2960+
Otherwise, the pointer is passed as if it were the first parameter in
2961+
the function prototype, preceding all other parameters, including the
2962+
<code>this</code> and <code>VTT</code> parameters.
29172963

29182964
<p>
2919-
If the C ABI uses a special rule for "indirect" return values, e.g. when
2920-
the return type is too large to fit in registers, that rule is used to
2921-
pass the pointer. Otherwise the pointer is passed as the first parameter,
2922-
preceding all other parameters (including the <code>this</code> and
2923-
<code>VTT</code> parameters).
2924-
</p>
2965+
<a name="special-class-return-values">
2966+
<h5><a href="#special-class-return-values">3.1.3.2 Return Values of Special Class Type</a></h5>
29252967

29262968
<p>
2927-
Reference return values are returned as if pointers to the object bound
2928-
to the reference.
2929-
</p>
2969+
A return value of class
2970+
<code>std::decimal::decimal32</code>,
2971+
<code>std::decimal::decimal64</code>, or
2972+
<code>std::decimal::decimal128</code> as defined in TR 24733 is
2973+
returned the same as the corresponding native decimal floating-point
2974+
scalar type.
29302975

29312976
<p>
2932-
Another exception is that a return value type of class
2933-
<code>std::decimal::decimal32</code>,
2934-
<code>std::decimal::decimal64</code>, or
2935-
<code>std::decimal::decimal128</code> as defined in TR 24733 is
2936-
returned the same as the corresponding native decimal floating-point
2937-
scalar type.
2938-
</p>
2977+
<a name="reference-return-values">
2978+
<h5><a href="#reference-return-values">3.1.3.3 Reference Return Values</a></h5>
2979+
2980+
<p>
2981+
A return value of reference type is returned as a pointer to the object
2982+
bound to the reference.
2983+
2984+
<p>
2985+
<a name="empty-return-values">
2986+
<h5><a href="#emptty-return-values">3.1.3.4 Empty Return Values</a></h5>
29392987

29402988
<p>
2941-
A result of an empty class type will be returned as though it were
2942-
a struct containing a single char,
2943-
i.e. <code>struct S { char c; };</code>.
2944-
The actual content of the return register is unspecified.
2945-
On Itanium, the associated NaT bit must not be set.
2989+
A return value of an empty class type that is not non-trivial for
2990+
the purposes of calls will be returned as though it were the
2991+
following C type:
2992+
2993+
<pre>struct { char c; };</pre>
29462994

2995+
<p>
2996+
On Itanium, the NaT bit must not be set for any register associated with
2997+
this return value.
29472998

29482999
<p>
29493000
<a name="return-value-ctor">
2950-
<h4><a href="#return-value-ctor"> 3.1.5 Constructor Return Values </a></h4>
3001+
<h5><a href="#return-value-ctor">3.1.3.5 Constructor Return Values</a></h5>
29513002

29523003
<p>
29533004
Constructors return <code>void</code> results.
29543005

3006+
<p>
3007+
Some platforms are known to modify this rule to specify that constructors
3008+
return a pointer to <code>this</code>. This may permit more efficient
3009+
code generation in the caller.
29553010

29563011
<p>
29573012
<a name="return-value-dtor">
2958-
<h4><a href="#return-value-dtor"> 3.1.5 Destructor Return Values </a></h4>
3013+
<h5><a href="#return-value-dtor">3.1.3.6 Destructor Return Values</a></h5>
29593014

29603015
<p>
29613016
Destructors return <code>void</code> results.
29623017

3018+
<p>
3019+
Some platforms are known to modify this rule to specify that destructors
3020+
return a pointer to <code>this</code>. This may permit more efficient
3021+
code generation in the caller. This modified rule does not apply to
3022+
deleting destructors. It also does not apply when making a virtual call
3023+
to a complete-object destructor, so that
3024+
<a href="#vtable-components"><code>this</code>-adjustment thunks</a>
3025+
do not need to adjust the return value after the call.
3026+
29633027
<p>
29643028
<a name="vcall">
2965-
<h3><a href="#vcall"> 3.2 Virtual Function Calling Conventions </a></h3>
3029+
<h3><a href="#vcall">3.2 Virtual Calls</a></h3>
29663030
</a>
29673031

29683032
<p>
@@ -3018,7 +3082,7 @@ <h4><a href="#vcall-general"> 3.2.1 General </a></h4>
30183082

30193083
<p>
30203084
<a name="vcall.vtable">
3021-
<h4><a href="#vcall.vtable"> 3.2.2 Virtual Table Components </a>x</h4>
3085+
<h4><a href="#vcall.vtable"> 3.2.2 Virtual Table Components </a></h4>
30223086

30233087
<p>
30243088
For each virtual function declared in a class C,

0 commit comments

Comments
 (0)