[cxx-abi-dev] Mangling of reference temporaries

Richard Smith richardsmith at google.com
Mon May 5 18:07:52 UTC 2014


On 5 May 2014 10:14, John McCall <rjmccall at apple.com> wrote:

> On May 5, 2014, at 10:02 AM, Richard Smith <richardsmith at google.com>
> wrote:
>
> On 5 May 2014 09:13, John McCall <rjmccall at apple.com> wrote:
>
>> On May 4, 2014, at 8:00 PM, David Majnemer <david.majnemer at gmail.com>
>> wrote:
>> > The Itanium ABI does not seem to provide a mangling for reference
>> temporaries.
>> >
>> > Consider the following:
>> > struct A { const int (&x)[3]; };
>> > struct B { const A (&x)[2]; };
>> > template <typename T> B &&b = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
>> > B &temp = b<void>;
>> >
>> > The temporaries created by instantiating b<void> must be the same in
>> all translation units.
>> >
>> > To satisfy this requirement, I propose that we mangle the temporaries
>> in lexical order using a mangling similar to what GCC 4.9 uses and
>> identical to what trunk clang uses.
>>
>> What does GCC do?
>
>
> GCC trunk seems to use
>
>   <special-name> ::= GR <object name> <nonnegative number>
>
> where the first reference temporary gets number 0, and so on. It appears
> to number them through a post-order tree walk of the expression. Older
> versions of GCC did not add a number, IIRC.
>
>
> Okay.  So we have two different manglings out there that both look
> basically the same except for an off-by-one and a major semantic ordering
> difference.  I think we should either standardize on one or the other or
> switch to a different prefix entirely.
>

Looking at the GCC output again, I see:
  * GCC actually does seem to be using lexical order (of the start of the
expression) after all (at least in the std::initializer_list array
temporary case).
  * GCC emits these symbols with internal linkage.

So I don't think there's any compatibility problem with GCC.

Has the clang mangling actually been used in a released compiler, or did it
> just get implemented?
>

Sort of? Until very recently, Clang used the same mangling for all the
temporaries, and added numbers to disambiguate, so we got the current
proposal by accident (except the numbering starts from 1 instead of from 0)
-- at least, in some cases: Clang would number the temporaries in a
different order if they were initialized by constant expressions (because
it happened to emit them in a different order).

Hmm.  Putting a <number> after a <name> requires demangler lookahead,
> doesn’t it?
>

<name> is self-delimiting, so a demangler can walk over it, then read
digits until it sees a non-digit or end-of-mangled-name. (<encoding>s are
only nested if they appear within a <local-name>, which has a terminating
E.) Not sure if that addresses your concern, though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140505/fffc8aa6/attachment-0001.html>


More information about the cxx-abi-dev mailing list