<html>
<head>
<base href="http://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 --- - After enabling "-fno-elide-constructors", seg-faulted."
href="http://llvm.org/bugs/show_bug.cgi?id=17896">17896</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>After enabling "-fno-elide-constructors", seg-faulted.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Other
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zlchen.ken@gmail.com
</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>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@ubuntu:~/work/test$ clang++ -std=c++11 -g -fno-elide-constructors
elide.cxx
ghost@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</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>