[Bug c++/8861] [3.3/3.4 regression] [ABI] mangling floating point literal in template arg expression

zack@codesourcery.com gcc-bugzilla@gcc.gnu.org
Sun Jun 8 18:08:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8861



------- Additional Comments From zack@codesourcery.com  2003-06-08 18:08 -------
Subject:  PATCH: mangling floating point literal in template
 arg expression


This is an area of the C++ ABI which, as far as I can tell, we have
never gotten right.

The comment above write_template_arg_literal is out-of-date; the
relevant bit of the text currently visible at
http://www.codesourcery.com/cxx-abi/abi.html#mangling reads

     Floating-point literals are encoded using a fixed-length lowercase
     hexadecimal string corresponding to the internal representation
     (IEEE on Itanium), high-order bytes first, without leading
     zeroes. For example: "Lf bf800000 E" is -1.0f on Itanium.

The differences are (a) the hexadecimal value has been corrected,
(b) this is no longer described as an extension.

Now there are a lot of weasel words in that text, but the example
makes it quite clear that what they mean is the *processor*'s internal
representation of the floating-point number.  The idea is clearly to
provide compatibility between compilers for the same architecture,
while not forcing a compiler to have the means to represent a
floating-point number in some foreign format.

Given the test case (which is as simple as I can make it, sorry):

template <int I> struct A {
        A(int);
};

template <int I> void f(A<I+int(-1.0f)>) {}

void g()
{
        f<1>(37);
}

I believe that the mangled name for the call to f<1>() should be one of

        _Z1fILi1EEv1AIXplT_cvingLf3f800000EEE
        _Z1fILi1EEv1AIXplT_Lin1EEE
        _Z1fILi1EEv1AIXmiT_Li1EEE

depending on how much constant folding is supposed to happen.  Current
versions of GCC produce, however:

3.0:    _Z1fILi1EEv1AIXplT_cvingLf00000000080FF3F00000000EEE
3.2:    _Z1fILi1EEv1AIXplT_cvingLf00000000080FF3F00000000EEE
3.3:    _Z1fILi1EEv1AIXplT_cvingLf9000000000000000000000080EEE

which is in the wrong word order, uppercase, and furthermore it's a
raw dump of real.c's internal encoding.

The appended patch causes us to produce

        _Z1fILi1EEv1AIXplT_cvingLf3f800000EEE

unconditionally.  (I do not propose to address the issue of constant-
folding template arguments, should we be currently getting this
wrong.)  Unfortunately it will be very difficult to achieve backward
compatibility with 3.2 (for -fabi-version=1) because that mangling
depended on the internal representation used by the old real.c; we
would have to duplicate it.  I'm not going to check anything in until
we agree what to do about backward compatibility.

The patch has the pleasant side effect of removing a sorry() when
cross compiling.

zw

        PR c++/8861
        * mangle.c (write_template_arg_literal): Correct the mangling
        of floating-point literals.



More information about the Gcc-bugs mailing list