I have some code which compiles to an in-memory buffer by wrapping an std::string with an raw_string_ostream and passing it to addPassesToEmitFile. This used to work fine on LLVM 3.5, after wrapping the raw_string_ostream with a formatted_raw_ostream. LLVM 3.7 has changed the interface, requiring a pwrite-able buffer instead. Looking at the raw_pwrite_stream class hierarchy, I decided to wrap the raw_string_ostream with a buffer_ostream. This however yields truncated output (at a seemingly random spot)...
Attached is a relatively large, but straightforward test-case (parse, compile, emit). Compile it with: clang++ -std=c++11 test.cpp $(llvm-config -cxxflags --system-libs --libs all) -L$(llvm-config --libdir) -o test
The test-case works on both LLVM 3.7 and 3.5, by means of #ifdef's.
Output on 3.5:
//
// Generated by LLVM NVPTX Back-End
//
.version 3.2
.target sm_20
.address_size 32
// .globl dummy
.visible .entry dummy(
)
{
ret;
}
Output on 3.7:
//
// Generated by LLVM NVPTX Back-End
//
.version 3.2
.target sm_20
.address_size 32
// .globl dummy
.visible .entry dummy(
I tried compiling with ASAN / running with valgrind, but no errors were revealed. Strangely, deleting the PassManager (currently commented) fixes the output! So I'm still thinking it could be a memory error.
I also suspected a flushing issue, but looking at the source code the buffer_ostream should flush when going out-of-scope, and the raw_string_ostream flushes in its str() getter. Adding additional flush() calls did not change the output.
I'm using LLVM 3.5 vanilla and 3.7 from the Arch repositories, on Linux 64bit.
Extended Description
Hi,
I have some code which compiles to an in-memory buffer by wrapping an std::string with an raw_string_ostream and passing it to addPassesToEmitFile. This used to work fine on LLVM 3.5, after wrapping the raw_string_ostream with a formatted_raw_ostream. LLVM 3.7 has changed the interface, requiring a pwrite-able buffer instead. Looking at the raw_pwrite_stream class hierarchy, I decided to wrap the raw_string_ostream with a buffer_ostream. This however yields truncated output (at a seemingly random spot)...
Attached is a relatively large, but straightforward test-case (parse, compile, emit). Compile it with: clang++ -std=c++11 test.cpp $(llvm-config -cxxflags --system-libs --libs all) -L$(llvm-config --libdir) -o test The test-case works on both LLVM 3.7 and 3.5, by means of #ifdef's.
Output on 3.5: // // Generated by LLVM NVPTX Back-End //
.version 3.2 .target sm_20 .address_size 32
.visible .entry dummy(
) {
}
Output on 3.7: // // Generated by LLVM NVPTX Back-End //
.version 3.2 .target sm_20 .address_size 32
.visible .entry dummy(
I tried compiling with ASAN / running with valgrind, but no errors were revealed. Strangely, deleting the PassManager (currently commented) fixes the output! So I'm still thinking it could be a memory error.
I also suspected a flushing issue, but looking at the source code the buffer_ostream should flush when going out-of-scope, and the raw_string_ostream flushes in its str() getter. Adding additional flush() calls did not change the output.
I'm using LLVM 3.5 vanilla and 3.7 from the Arch repositories, on Linux 64bit.