[LLVMbugs] [Bug 17896] New: After enabling "-fno-elide-constructors", seg-faulted.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 12 06:03:16 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=17896

            Bug ID: 17896
           Summary: After enabling "-fno-elide-constructors", seg-faulted.
           Product: clang
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zlchen.ken at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I was testing the RVO/NRVO of clang++, after enabling "-fno-elide-constructors"
option, the code gets seg-faulted. The code is extracted from Sean Parent's
slides which was presented in GoingNative2013 conf. 

clang/llvm was built from 3.4 source code on Ubuntu 12.04 LTS X64 server. BTW,
gcc has no problem.

source code:
-----------
#include <iostream>
#include <memory>

using namespace std;

class object_t {
public:
    object_t(const int& x)
        : self_(new int_model_t(x)) {
        cout << "ctor " << endl;
        cout << self_.get() << endl;
    }

    object_t(const object_t& x)
        : self_(new int_model_t(*x.self_)) {
        cout << "copy " << endl;
        cout << "other " << x.self_.get() << endl;
        cout << "this " << self_.get() << endl;
    }

    object_t& operator=(const object_t& x) {
        object_t tmp(x);
        self_ = move(tmp.self_);
        cout << "move " << endl;
        cout << self_.get() << endl;
        return *this;
    }

private:
    struct int_model_t {
        int_model_t(const int& x)
             : data_(x) {
        }
        int data_;
    };

private:
    unique_ptr<int_model_t> self_;
};

object_t func() {
    cout << "entering func" << endl;
    object_t result(5);
    cout << "leaving func" << endl;
    return result;
}

int main() {
    object_t x(func());
    cout << "end of main" << endl;
    return 0;
}

stack trace:
------------

ghost at ubuntu:~/work/test$ clang++ -std=c++11 -g -fno-elide-constructors
elide.cxx
ghost at ubuntu:~/work/test$ ./a.out
entering func
ctor
0x1fc9010
leaving func
copy
other 0x4009bc  <=== why 0x4009bc instead of 0x1fc9010 ?
this 0x1fc9010
*** glibc detected *** ./a.out: free(): invalid pointer: 0x00000000004009bc ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f77beeb5b96]
./a.out[0x400f81]
./a.out[0x400e8f]
./a.out[0x400e25]
./a.out[0x4012a5]
./a.out[0x400b9a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f77bee5876d]
./a.out[0x4009e5]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 2107728                           
/home/ghost/work/test/a.out
00601000-00602000 r--p 00001000 08:01 2107728                           
/home/ghost/work/test/a.out
00602000-00603000 rw-p 00002000 08:01 2107728                           
/home/ghost/work/test/a.out
01fc9000-01fea000 rw-p 00000000 00:00 0                                  [heap]
7f77bee37000-7f77befec000 r-xp 00000000 08:01 1578011                   
/lib/x86_64-linux-gnu/libc-2.15.so
7f77befec000-7f77bf1ec000 ---p 001b5000 08:01 1578011                   
/lib/x86_64-linux-gnu/libc-2.15.so
7f77bf1ec000-7f77bf1f0000 r--p 001b5000 08:01 1578011                   
/lib/x86_64-linux-gnu/libc-2.15.so
7f77bf1f0000-7f77bf1f2000 rw-p 001b9000 08:01 1578011                   
/lib/x86_64-linux-gnu/libc-2.15.so
7f77bf1f2000-7f77bf1f7000 rw-p 00000000 00:00 0
7f77bf1f7000-7f77bf20c000 r-xp 00000000 08:01 1458749                   
/usr/gcc48/lib64/libgcc_s.so.1
7f77bf20c000-7f77bf40c000 ---p 00015000 08:01 1458749                   
/usr/gcc48/lib64/libgcc_s.so.1
7f77bf40c000-7f77bf40d000 rw-p 00015000 08:01 1458749                   
/usr/gcc48/lib64/libgcc_s.so.1
7f77bf40d000-7f77bf508000 r-xp 00000000 08:01 1578022                   
/lib/x86_64-linux-gnu/libm-2.15.so
7f77bf508000-7f77bf707000 ---p 000fb000 08:01 1578022                   
/lib/x86_64-linux-gnu/libm-2.15.so
7f77bf707000-7f77bf708000 r--p 000fa000 08:01 1578022                   
/lib/x86_64-linux-gnu/libm-2.15.so
7f77bf708000-7f77bf709000 rw-p 000fb000 08:01 1578022                   
/lib/x86_64-linux-gnu/libm-2.15.so
7f77bf709000-7f77bf7ed000 r-xp 00000000 08:01 1459463                   
/usr/gcc48/lib64/libstdc++.so.6.0.18
7f77bf7ed000-7f77bf9ed000 ---p 000e4000 08:01 1459463                   
/usr/gcc48/lib64/libstdc++.so.6.0.18
7f77bf9ed000-7f77bf9f5000 r--p 000e4000 08:01 1459463                   
/usr/gcc48/lib64/libstdc++.so.6.0.18
7f77bf9f5000-7f77bf9f7000 rw-p 000ec000 08:01 1459463                   
/usr/gcc48/lib64/libstdc++.so.6.0.18
7f77bf9f7000-7f77bfa0c000 rw-p 00000000 00:00 0
7f77bfa0c000-7f77bfa2e000 r-xp 00000000 08:01 1578023                   
/lib/x86_64-linux-gnu/ld-2.15.so
7f77bfc21000-7f77bfc26000 rw-p 00000000 00:00 0
7f77bfc2a000-7f77bfc2e000 rw-p 00000000 00:00 0
7f77bfc2e000-7f77bfc2f000 r--p 00022000 08:01 1578023                   
/lib/x86_64-linux-gnu/ld-2.15.so
7f77bfc2f000-7f77bfc31000 rw-p 00023000 08:01 1578023                   
/lib/x86_64-linux-gnu/ld-2.15.so
7fff3a915000-7fff3a936000 rw-p 00000000 00:00 0                         
[stack]
7fff3a9ac000-7fff3a9ae000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                 
[vsyscall]
Aborted

-- 
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/20131112/22a265fe/attachment.html>


More information about the llvm-bugs mailing list