<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - GCC ABI incompatibility visible in forward_as_tuple"
href="https://llvm.org/bugs/show_bug.cgi?id=23034">23034</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>GCC ABI incompatibility visible in forward_as_tuple
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>Axel.Naumann@cern.ch
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=14103" name="attach_14103" title="Reproducer. Apologies for its preprocessed size :-(">attachment 14103</a> <a href="attachment.cgi?id=14103&action=edit" title="Reproducer. Apologies for its preprocessed size :-(">[details]</a></span>
Reproducer. Apologies for its preprocessed size :-(
With $ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
(and other 4.8.1 from RedHat)
and $ clang --version
clang version 3.7.0 (trunk 233280)
I get
clang++ -std=c++11 -c clanggcc.cxx -o clang.o
g++ -std=c++11 clanggcc.cxx clang.o -o a.out
./a.out
gcc: &rval=0x7fff3c1b2700
gcc: &c_str()=0xcec028
tpl: &c_str()=0xcec028
tpl: c_str()=a
clang: &rval=0x7fff3c1b2718
clang: &c_str()=0xcec028
make: *** [test] Segmentation fault
with attached code.
The linker uses GCC's version of forward_as_tuple. GCC sets %rsi and %rdi to
call it; clang only sets %rdi. The implementation of forward_as_tuple compiled
by GCC needs both %rsi and %rdi.
And yes - not part of this test but clang's implementation of forward_as_tuple
only needs %rdi - so clang is consistent but incompatible with GCC.
Assembly of the relevant part of the GCC call:
0x00000000004009e6 <+86>: callq 0x400ab1
<std::move<std::string&>(std::string&)>
0x00000000004009eb <+91>: mov %rax,%rdx
0x00000000004009ee <+94>: lea -0x10(%rbp),%rax
0x00000000004009f2 <+98>: mov %rdx,%rsi
0x00000000004009f5 <+101>: mov %rax,%rdi
0x00000000004009f8 <+104>: callq 0x400b94
<std::forward_as_tuple<std::string>(std::string&&)>
...and for clang:
0x0000000000400d4f <+95>: callq 0x400ab1
<std::move<std::string&>(std::string&)>
0x0000000000400d54 <+100>: mov %rax,%rdi
0x0000000000400d57 <+103>: callq 0x400b94
<std::forward_as_tuple<std::string>(std::string&&)>
with GCC's forward_as_tuple being:
=> 0x0000000000400b94 <+0>: push %rbp
0x0000000000400b95 <+1>: mov %rsp,%rbp
0x0000000000400b98 <+4>: sub $0x10,%rsp
0x0000000000400b9c <+8>: mov %rdi,-0x8(%rbp)
0x0000000000400ba0 <+12>: mov %rsi,-0x10(%rbp)
0x0000000000400ba4 <+16>: mov -0x10(%rbp),%rax
0x0000000000400ba8 <+20>: mov %rax,%rdi
0x0000000000400bab <+23>: callq 0x400aea
<std::forward<std::string>(std::remove_reference<std::string>::type&)>
0x0000000000400bb0 <+28>: mov %rax,%rdx
0x0000000000400bb3 <+31>: mov -0x8(%rbp),%rax
0x0000000000400bb7 <+35>: mov %rdx,%rsi
0x0000000000400bba <+38>: mov %rax,%rdi
0x0000000000400bbd <+41>: callq 0x400b64
<std::tuple<std::string&&>::tuple<std::string, void>(std::string&&)>
0x0000000000400bc2 <+46>: mov -0x8(%rbp),%rax
0x0000000000400bc6 <+50>: leaveq
0x0000000000400bc7 <+51>: retq
Help!
Cheers, Axel.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>