<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 1, 2012, at 3:48 PM, Justin Holewinski wrote:</div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">This isn't the right approach.  Nothing in the library part of the compiler should be hard coding a stream to write to.  What are you trying to accomplish?<br></blockquote><div><br></div></div><div>There are a lot of places where warning/debug information is passed directly to errs().  For example, take the Linker class.  You can tell it to omit errors/warnings, but it would be preferable to let it emit the errors/warnings to some compiler-controlled stream for message triaging.</div></div></blockquote></div></blockquote><div><br></div><div>Yes, this is broken.  The fix should be in the linker though, not in errs().</div><div><br></div><blockquote type="cite"><div class="gmail_quote"><div>Perhaps I'm just getting the wrong impression from the current LLVM code base.  Take this snippet from LinkModules.cpp:</div><div><br></div><div><div><font face="courier new, monospace">  if (!SrcM->getDataLayout().empty() && !DstM->getDataLayout().empty() &&</font></div>
<div><font face="courier new, monospace">      SrcM->getDataLayout() != DstM->getDataLayout())</font></div><div><font face="courier new, monospace">    errs() << "WARNING: Linking two modules of different data layouts!\n";</font></div>
<div><font face="courier new, monospace">  if (!SrcM->getTargetTriple().empty() &&</font></div><div><font face="courier new, monospace">      DstM->getTargetTriple() != SrcM->getTargetTriple()) {</font></div>
<div><font face="courier new, monospace">    errs() << "WARNING: Linking two modules of different target triples: ";</font></div><div><font face="courier new, monospace">    if (!SrcM->getModuleIdentifier().empty())</font></div>
<div><font face="courier new, monospace">      errs() << SrcM->getModuleIdentifier() << ": ";</font></div><div><font face="courier new, monospace">    errs() << "'" << SrcM->getTargetTriple() << "' and '"</font></div>
<div><font face="courier new, monospace">           << DstM->getTargetTriple() << "'\n";</font></div><div><font face="courier new, monospace">  }</font></div></div><div><br></div><div>Would I be correct in assuming that this is actually "bad" code since it's a library function that writes directly to stderr?</div></div></blockquote><div><br></div><div>Yes, this is extremely unfriendly to using the linker as a library.  It would be much better for the linker to return its error in a proper way (i.e. extending llvm/Support/system_error.h like llvm/Object/Error.h does).</div><br><blockquote type="cite"><div class="gmail_quote">
<div>Is the recommended approach to pass a stream to the constructor of any pass or function that wants to emit output outside of debug mode?  My concern with this approach is that the compiler would then need to know which passes expect an output stream, and which do not.  The supplied patch allows passes to output information without having to worry about where the output is going, it is up to the compiler to specify where this output goes.  </div>
</div></blockquote><br></div><div>The right fix for this is to fix the code to not report errors textually.</div><div><br></div><div>-Chris</div><br></body></html>