Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Use of ostringstream in c++ code causes resulting binary to segfault #6727

Closed Quuxplusone closed 14 years ago

Quuxplusone commented 14 years ago
Bugzilla Link PR6289
Status RESOLVED WORKSFORME
Importance P normal
Reported by Shivram K (shivramk@gmail.com)
Reported on 2010-02-13 11:37:56 -0800
Last modified on 2010-04-01 20:49:30 -0700
Version trunk
Hardware Macintosh MacOS X
CC chris@bubblescope.net, dgregor@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The following program segfaults if compiled with clang -O2

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
    ostringstream out;
    out << 10;
    return 0;
}

Compiling with clang++ -O1 or without any optimization works fine.

I'm running Snow Leopard. Using clang from svn trunk.
Quuxplusone commented 14 years ago

This might not be the problem, but a very similar problem arises in Snow Leopard if you try to compile your own g++. Apple have seriously broken the C++ standard library in Snow Leopard, but seem unwilling to fix or acknowledge the problem.

Try adding:

define _GLIBCXX_FULLY_DYNAMIC_STRING

To the top of your program (before you #include any system headers) and see if that cleans up the problem.

Quuxplusone commented 14 years ago
Adding #define _GLIBCXX_FULLY_DYNAMIC_STRING doesn't seem to help.

Here is the stack trace from GDB.

(gdb) bt
#0  0x00001e23 in typeinfo name for std::ostream ()
#1  0x966cb0e3 in std::ios_base::_M_call_callbacks ()
#2  0x966cb1e8 in std::ios_base::~ios_base ()
#3  0x00001b3c in main ()

BTW I'm building a 32-bit binary. Please let me know if you need additional
information.
Quuxplusone commented 14 years ago

Could you please give exactly the build flags you gave to build clang/llvm, and the command line you then use to build your program?

I tried building your program on today's LLVM, and it seems to work fine, in both 64-bit and 32-bit mode, so I must be doing something slightly different to you.

Quuxplusone commented 14 years ago
I'm using LLVM r96099, compiled with ./configure --enable-jit --enable-
optimized --build=i686-apple-darwin10.2.0 --host=i686-apple-darwin10.2.0

The program was compiled with
clang++ -O2 test.cpp
Quuxplusone commented 14 years ago

This is working for me now. Please try the latest Clang from Subversion and re-open this bug if it isn't fixed for you.