<div dir="ltr">I think buffer_ostream has an internal buffer that doesn't flush until its destructor runs. What happens <div>if you just pass "stream" instead of pstream?</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 14, 2020 at 7:08 PM Frank Winter via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I can use llc to compile my IR module to amdgcn with some non-zero <br>
output. However, if try to write the output (assembly or object) to a <br>
string (via buffer_ostream) the resulting string has always zero length. <br>
Here the code changes I do:<br>
<br>
Original llc:<br>
<br>
       if (Target->addPassesToEmitFile(PM, *OS,<br>
                                       DwoOut ? &DwoOut->os() : nullptr,<br>
                                       FileType, NoVerify, MMIWP))<br>
<br>
<br>
Now, with this tiny change I was hoping to write to a string instead of <br>
the output stream defined by the command line parameters:<br>
<br>
std::string outStr;<br>
raw_string_ostream stream(outStr);<br>
buffer_ostream pstream(stream);<br>
if (Target->addPassesToEmitFile(PM, pstream,<br>
                                     DwoOut ? &DwoOut->os() : nullptr,<br>
                                     FileType, NoVerify, MMIWP))<br>
<br>
<br>
later, e.g., after PM.run(*M), I check the string for content with<br>
<br>
WithColor::warning(errs(), argv[0]) << "with flush, output size: " << <br>
outStr.length() << "\n";<br>
<br>
<br>
But this always yields "with flush, output size: 0"<br>
<br>
I tried to flush the raw_string_ostream before using the string, same <br>
result.<br>
<br>
The used command line was<br>
<br>
llc -march=amdgcn -mcpu=gfx906 < module.ll<br>
<br>
<br>
Anyone see what's wrong with the code?<br>
<br>
<br>
Frank<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>