<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Thanks,</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I tried calling ResetAllOptionOccurrences after the run like this…</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">  // Compile the module TimeCompilations times to give better compile time<br class="">  // metrics.<br class="">  for (unsigned I = TimeCompilations; I; --I)<br class="">    if (int RetVal = compileModule(argv, Context))<br class="">      return RetVal;<br class=""><br class="">  if (YamlFile)<br class="">    YamlFile->keep();<br class=""><br class="">  cl::ResetAllOptionOccurrences();<br class=""><br class="">  return 0;<br class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Unfortunately it is still crashing out when the next build starts. Any other thoughts?</div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 18 Nov 2019, at 10:13, James Henderson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I'm not entirely sure what it is that is causing your problem. It's worth noting that the unit tests for CommandLine.cpp can call cl::ParseCommandLineOptions multiple times within a process, although it looks like the options parsed are explicitly removed at the end of each test to avoid polluting the environment of the next test.</div><div class=""><br class=""></div><div class="">Probably the right thing to do is to call the "ResetAllOptionOccurrences" function of the command line parser. This should allow you to use it again cleanly. If you don't call that, you might end up setting options multiple times, which could lead to unexpected behaviour. Note that the comment in this function says that it is explicitly intended to allow parsing different command lines multiple times.</div><div class=""><br class=""></div><div class="">Hope that helps.<br class=""></div><div class=""><br class=""></div><div class="">James<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 17 Nov 2019 at 15:17, Carl Peto via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br class="">
<br class="">
I am running a server that does regular builds using llc. To begin with I was doing a fork/exec to launch llc, passing the files to compile and other switches as command line, etc. then waiting for the subprocess to complete. This was fine but seemed an unnecessary overhead. After all llc is mostly a fairly thin front end over the llc libraries, which do the actual work right?<br class="">
<br class="">
So I took llc.cpp, and the llvm-c and llvm headers and llvm libraries and linked them all into my server program (which is a C based server). I modified llc.cpp to change...<br class="">
<br class="">
int llcmain(int argc, char **argv) {<br class="">
...<br class="">
}<br class="">
<br class="">
...to...<br class="">
<br class="">
extern "C" int llcmain(int argc, char **argv) {<br class="">
...<br class="">
}<br class="">
<br class="">
<br class="">
Now I am calling this function directly from my server code.  This works fine for the first build, however any other builds fail in<br class="">
<br class="">
CommandLine.cpp:1101<br class="">
<br class="">
CommandLineParser::ParseCommandLineOptions<br class="">
<br class="">
assert(hasOptions() && "No options specified!"); <--fails here<br class="">
<br class="">
<br class="">
I'm trying to work out why this is breaking, I am assuming there is some global state left after processing that llc.cpp doesn't normally need to worry about?<br class="">
<br class="">
Is there a way to reset this global state cleanly? I'm assuming there's something about command line processing that is written to only work once, not repeatedly?<br class="">
<br class="">
Thanks for any advice/help.<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>