Itanium ABI: mangling issue with external names in template args (gcc vs. ABI)
| Bugzilla Link | 22621 |
| Resolution | FIXED |
| Resolved on | Feb 18, 2015 01:47 |
| Version | trunk |
| OS | Windows NT |
| CC | @majnemer,@rjmccall,@rnk |
Extended Description
The following example from the ABI (5.1.5)
void foo(char) {}
template <void (&)(char)> struct CB {};
void bar(CB
produces the following mangling for bar():
_Z3bar2CBILZ3foocEE
According to the ABI the 'Z' in the middle is supposed to be preceded by an underscore, foo being a name with external linkage.
There's a FIXME comment in CXXNameMangler::mangleTemplateArg() in ItaniumMangle.cpp saying that gcc leaves out the underscore. This is why clang does so, too.
Is the priority to conform to the ABI or to be as compatible with gcc as possible?
Fixed in r229644.
I checked what GCC does, and they emit a compatibility alias from the underscore mangling to the non-underscore mangling since GCC 4.5. See my test case at the end and try putting it into http://gcc.godbolt.org for various versions of GCC. The .set directive is introduced in 4.5.3. Therefore, I think we can safely change Clang to match the ABI here.
$ cat t.cpp
char foo;
template <char &> struct CB {};
void bar(CB
rnk@gimbleroad ~/llvm/build $ gcc -c t.cpp -S -o - -O2 .file "t.cpp" .text .p2align 4,,15 .globl _Z3bar2CBILZ3fooEE .type _Z3bar2CBILZ3fooEE, @function _Z3bar2CBILZ3fooEE: .LFB0: .cfi_startproc rep ret .cfi_endproc .LFE0: .size _Z3bar2CBILZ3fooEE, .-_Z3bar2CBILZ3fooEE .globl _Z3bar2CBIL_Z3fooEE .set _Z3bar2CBIL_Z3fooEE,_Z3bar2CBILZ3fooEE .globl foo .bss .type foo, @object .size foo, 1 foo: .zero 1 .ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2" .section .note.GNU-stack,"",@progbits
assigned to @majnemer