<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Yes, the destructor hint was golden.</p>
<p>Frank</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 4/14/20 10:27 PM, Craig Topper
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAF7ks-M59dhcUDvxnNV0dqO1LaHs2owJFqgHXkWFW9aR5PCF8Q@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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" moz-do-not-send="true">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"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
<a
href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=DwMFaQ&c=CJqEzB1piLOyyvZjb8YUQw&r=tFpAzszScTWMAFcrGFW5xg&m=oviBDHJqEC2vv35g8O4RBcGJEiOrougT5L0aM0gH3Dg&s=KDhhMM6rb9PhZnhzJYUujXsFibjWX29VxkIGd3ln_iY&e="
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</blockquote>
</body>
</html>