<html>
    <head>
      <base href="https://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 --- - String truncation with buffer_ostream and addPassesToEmitFile"
   href="https://llvm.org/bugs/show_bug.cgi?id=25272">25272</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>String truncation with buffer_ostream and addPassesToEmitFile
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tim.besard@elis.ugent.be
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15132" name="attach_15132" title="testcase.cpp">attachment 15132</a> <a href="attachment.cgi?id=15132&action=edit" title="testcase.cpp">[details]</a></span>
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.</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>