WriteBitcodeToFile terminates program

633 views Asked by At

i execute this simple code, but on "WriteBitcodeToFile" happned exception : "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc"
I don't understand why it happens(. Now i use llvm 3.6.1, i use clang++ 3.6.1. On llvm 3.3 code works fine.

callstack:

0 raise /lib/x86_64-linux-gnu/libc.so.6 0 0x7ffff6da10d5
1 abort /lib/x86_64-linux-gnu/libc.so.6 0 0x7ffff6da483b
2 __gnu_cxx::__verbose_terminate_handler() /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff76cbd4d
3 ?? /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff76c9d96
4 std::terminate() /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff76c9de1
5 __cxa_throw /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff76c9ff8 6 operator new(unsigned long) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff76ca4fc
7 std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator const&) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff7709659
8 std::string::_Rep::_M_clone(std::allocator const&, unsigned long) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff770a3fb
9 std::basic_string, std::allocator

::basic_string(std::string const&) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0 0x7ffff770aadc
10 llvm::Twine::str() const Twine.cpp 19 0x6e43c3
11 llvm::Triple::Triple(llvm::Twine const&) Triple.cpp 449 0x6dec99
12 llvm::WriteBitcodeToFile(llvm::Module const*, llvm::raw_ostream&) BitcodeWriter.cpp 2071 0x42eee5
13 main main.cpp 43 0x40da26

code:

std::error_code err_code;
llvm::LLVMContext &ctx = llvm::getGlobalContext();
llvm::Module *mod;
llvm::SMDiagnostic Err;


std::string filename = InputFilename;

mod = llvm::parseIRFile(filename,Err,ctx).get();

llvm::StringRef sRefName(OutputFilename);
llvm::raw_fd_ostream raw(sRefName, err_code,  (llvm::sys::fs::OpenFlags)8);
 llvm::WriteBitcodeToFile(mod, raw); // SIGABORT
0

There are 0 answers