[llvm-bugs] [Bug 25272] New: String truncation with buffer_ostream and addPassesToEmitFile

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 21 06:42:44 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=25272

            Bug ID: 25272
           Summary: String truncation with buffer_ostream and
                    addPassesToEmitFile
           Product: new-bugs
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: tim.besard at elis.ugent.be
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15132
  --> https://llvm.org/bugs/attachment.cgi?id=15132&action=edit
testcase.cpp

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

    // .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.

-- 
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/20151021/2297aa01/attachment.html>


More information about the llvm-bugs mailing list