<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Mar 22, 2015 at 5:12 PM, Robert Ankeney <span dir="ltr"><<a href="mailto:rrankene@gmail.com" target="_blank">rrankene@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>I'm seeing some strange results using a RecursiveASTVisitor on some C code. The following code compiles fine with clang:<br><br>static __inline unsigned int<br>__bswap_32 (unsigned int __bsx)<br>{<br> return __builtin_bswap32 (__bsx);<br>}<br><br></div>But I get the following diagnostic when calling ParseAST:<br><br><span style="color:rgb(0,0,0)">C:/BUG/builtin.c:4:10: </span><span style="color:rgb(255,0,0)">error: </span><span style="color:rgb(0,0,0)">use of unknown builtin '__builtin_bswap32'</span>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(80,80,80)"> return __builtin_bswap32 (__bsx);</span></p><p style="margin:0px;text-indent:0px"><span style="color:rgb(80,80,80)"> ^<br></span></p><br></div><div>It seems odd that I should get this error, as __builtin_bswap32() is supported. Any idea why?<br></div></div></blockquote><div><br></div><div>If you're calling ParseAST yourself, you're likely missing quite a few of the necessary set up steps; in this case, the missing step is a call to InitializeBuiltins on the preprocessor's Builtins::Context object. It's generally better to use the clang Frontend library to set up and initialize the various components of the compiler for you; see ToolInvocation and ClangTool in the Tooling library for some prebuilt wrappers to make this easier.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div></div>Another interesting thing - I get the following results for each of the getDiagnostics() calls:<br><span style="color:rgb(0,0,0)">hasUncompilableErrorOccurred() = True</span>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasUnrecoverableErrorOccurred() = False</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasFatalErrorOccurred() = False</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasErrorOccurred() = True</span></p>
<p style="margin:0px;text-indent:0px;color:rgb(0,0,0)"><br></p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)">As a point of comparison, for the following code:</p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)">int foo()<br>{<br> retrun 42; // Typo on return<br>}</p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)"><br></p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)">I get:</p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">C:/Src/cp.PP/BUG/bug.c:3:3: </span><span style="color:rgb(255,0,0)">error: </span><span style="color:rgb(0,0,0)">use of undeclared identifier 'retrun'</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(80,80,80)"> retrun 42;</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,128,0)"> ^</span></p><p style="margin:0px;text-indent:0px"><br><span style="color:rgb(0,0,0)">hasUncompilableErrorOccurred() = True</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasUnrecoverableErrorOccurred() = True</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasFatalErrorOccurred() = False</span></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,0)">hasErrorOccurred() = True</span></p>
<p style="margin:0px;text-indent:0px;color:rgb(0,0,0)"><br></p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)">For code that generates only a warning, the above 4 calls all return False.</p><p style="margin:0px;text-indent:0px;color:rgb(0,0,0)">I guess I'm not sure what the difference is between <span style="color:rgb(0,0,0)">hasUncompilableErrorOccurred() and </span><br><span style="color:rgb(0,0,0)">hasErrorOccurred(), or what exactly the other 2 functions do. Any enlightenment there?</span></p></div></blockquote><div><br></div><div>In order from most specific to most general:</div><div><br></div><div>hasFatalErrorOccurred() indicates whether we've emitted any "fatal error:" diagnostics. These are diagnostics that indicate a problem sufficiently severe that we don't think we could continue to emit correct diagnostics after emitting one. (For instance: missing a file named by #include, or reached the template instantiation depth limit.)</div><div><br></div><div><div>hasUnrecoverableErrorOccurred indicates whether we think the AST is not essentially correct -- whether tools performing automated analysis and refactorings might get the wrong answer. If an unrecoverable error occurs, we turn off CFG-based analyses and the like. This excludes errors upgraded from warnings, and also "warning-like" errors for ARC issues, functions marked "unavailable", and so on.<br></div><div><br></div></div><div>hasUncompilableErrorOccurred indicates whether we think we could generate correct code from the AST we built. This excludes errors upgraded from warnings, but includes ARC issues and uses of unavailable functions (for which we could analyse the program, but where we couldn't generate working code).<br></div><div><br></div><div>hasErrorOccurred() indicates if we've emitted any "error:" diagnostics, and thus whether the compilation should fail.</div></div></div></div>