[llvm-bugs] [Bug 34427] New: clang generate incompatible code for std::tie

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 2 09:51:43 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34427

            Bug ID: 34427
           Summary: clang generate incompatible code for std::tie
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: wengxt at gmail.com
                CC: llvm-bugs at lists.llvm.org

For example:

#include <tuple>

int main() {
  int a = 1, b = 2;
  auto t = std::tie(a, b);
  return 0;
}

Compile with -std=c++14 -O0 for both clang++ and g++.

Problem is for clang++ and g++ it generate code that return value in different
style, which would cause crash when a clang++ compiled lib and g++ compiled lib
linked together because std symbol is always visible for libstdcxx.

g++ produces: 
0000000000400768 <_ZSt3tieIJiiEESt5tupleIJDpRT_EES3_>:
  400768:       55                      push   %rbp
  400769:       48 89 e5                mov    %rsp,%rbp
  40076c:       48 83 ec 20             sub    $0x20,%rsp
  400770:       48 89 7d f8             mov    %rdi,-0x8(%rbp)
  400774:       48 89 75 f0             mov    %rsi,-0x10(%rbp)
  400778:       48 89 55 e8             mov    %rdx,-0x18(%rbp)
  40077c:       48 8b 55 e8             mov    -0x18(%rbp),%rdx
  400780:       48 8b 4d f0             mov    -0x10(%rbp),%rcx
  400784:       48 8b 45 f8             mov    -0x8(%rbp),%rax
  400788:       48 89 ce                mov    %rcx,%rsi
  40078b:       48 89 c7                mov    %rax,%rdi
  40078e:       e8 a7 ff ff ff          callq  40073a
<_ZNSt5tupleIJRiS0_EEC1IvLb1EEES0_S0_>
  400793:       48 8b 45 f8             mov    -0x8(%rbp),%rax
  400797:       c9                      leaveq 
  400798:       c3                      retq   
  400799:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)

while clang++ produces:
0000000000000850 <_ZSt3tieIJiiEESt5tupleIJDpRT_EES3_>:
 850:   55                      push   %rbp
 851:   48 89 e5                mov    %rsp,%rbp
 854:   48 83 ec 20             sub    $0x20,%rsp
 858:   48 89 7d e8             mov    %rdi,-0x18(%rbp)
 85c:   48 89 75 e0             mov    %rsi,-0x20(%rbp)
 860:   48 8b 75 e8             mov    -0x18(%rbp),%rsi
 864:   48 8b 55 e0             mov    -0x20(%rbp),%rdx
 868:   48 8d 7d f0             lea    -0x10(%rbp),%rdi
 86c:   e8 0f 00 00 00          callq  880
<_ZNSt5tupleIJRiS0_EEC2IvLb1EEES0_S0_>
 871:   48 8b 45 f0             mov    -0x10(%rbp),%rax
 875:   48 8b 55 f8             mov    -0x8(%rbp),%rdx
 879:   48 83 c4 20             add    $0x20,%rsp
 87d:   5d                      pop    %rbp
 87e:   c3                      retq   
 87f:   90                      nop

$ clang -v
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.1
Found candidate GCC installation:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /chakra/core/gcc/src/gcc/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://chakraos.org/bugtracker
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 6.3.1 20170306 (GCC)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170902/4a4d25bd/attachment-0001.html>


More information about the llvm-bugs mailing list