<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 12, 2016, at 4:59 AM, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com" class="">xazax.hun@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Hi!<br class=""><br class=""></div>(As a ping), I would like to summarize the measurements I done since the original e-mail:<br class=""><br class=""></div>The approach is to first serialize all the translation units to the storage, create an index of the functions, and then load them lazily on demand to achieve cross translation unit support. This does not modify the inter-procedural analysis of the Static Analyzer and could be used for Clang Tidy as well. Once a new inter-procedural analysis is introduced for the Static Analyzer, the cross tu support would profit from it immediately.<br class=""><br class=""></div>Benchmarks:<br class=""><div class="">rAthena, a 150k LOC C project:<br class=""></div><div class="">The size of the serialized ASTs was: 140MB<br class=""></div><div class="">The size of the indexes: 4.4MB<br class=""></div><div class="">The time of the analysis was bellow 4X<br class=""></div>The amount of memory consumed was bellow 2X<br class=""></div>The number of reports is 3 times more<br class=""><br class=""></div>Xerces, 150k LOC C++ project:<br class="">The size of the serialized ASTs was: 800MB<br class="">The size of the indexes: 90MB<br class=""></div>The analysis time using CTU was the half of the one without CTU<br class=""><br class=""></div>LLVM + Clang + Clang tools extra:<br class="">The size of the serialized ASTs was: 45.4 GB<br class="">The size of the indexes: 1,6GB<br class=""><br class="">Some optimization effort to reduce te size of the CFG:<br class="">TU ASTs after omitting function bodies from headers: 42.7 GB<br class="">TU ASTs after omitting STL: 34.0 GB<br class="">TU ASTs after skipping implicit instantiations: 21.5 GB<br class="">TU ASTs after omitting STL and implicit instantiations: 16.0 GB<br class=""><br class=""></div>Considering that the build directory of a debug build is also about 40 GB on my platform, I do not consider the size of the serialized ASTs a blocking issue. However, in case it is a concern, according to the attached statistics about the serialized AST dumps, there are some optimization possibilities in the binary format. <br class=""><br class=""></div>This solution also works in a multi process build/analysis environment. Some of the necessary framework, for example ASTImporter code is being accepted into mainline clang right now.<br class=""><br class=""></div>All in all, this approach:<br class=""></div>- Can discover new bug reports as is.<br class=""></div></div></div></div></div></div></div></blockquote><div><br class=""></div>Hi Gabor,</div><div><br class=""></div><div>I’d like to get more data on this point. We know that inlining-style inter-procedural analysis does not scale. That is the main issue with adding the cross-translation unit support to the clang static analyzer. </div><div><br class=""></div><div>I suspect that the only way the suggested approach works is that we time out more often when the TU support is enabled. Since the static analyzer performs DFS of the paths, this means that we trade catching bugs localized within a single TU to bugs that require deep cross-TU analysis. I suspect those bugs are much harder to understand, but more, importantly, we trade coverage in a lot of cases instead of gaining it.</div><div><br class=""></div><div>Looks like you clam that the number of bugs reported increased for one of the projects, but there is no data for all the other projects. Also, had that project ever been analyzed with the clang static analyzer before and had some of the intra-procedural bugs been fixed before you made the measurement? I’d like to see the absolute number of bugs reported in both cases. Also, it would be good to measure coverage and the number of times the analyzer times out in both cases. (Those statistics should be easy to generate as the tracking is already implemented by the analyzer and we used it when bringing up inter procedural analysis.)</div><div><br class=""></div><div>Thank you,</div><div>Anna.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">- Feasible to implement, does not need sever modifications to the Static Analyzer or Clang Tidy.</div></div></div></div></div></div></blockquote></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">- Has acceptable performance for lots of the real world projects. <br class=""><br class=""></div>I think, this would be a useful addition to the clang source tree. Do you agree?<br class=""><br class=""></div>Regards,<br class=""></div>Gábor<br class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On 4 May 2016 at 15:09, Gábor Horváth <span dir="ltr" class=""><<a href="mailto:xazax.hun@gmail.com" target="_blank" class="">xazax.hun@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Hi!<br class=""><br class=""></div>This e-mail is a proposal based on the work done by Yury Gibrov et al.: <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046299.html" target="_blank" class="">http://lists.llvm.org/pipermail/cfe-dev/2015-December/046299.html</a><b class=""><br class=""><br class=""></b></div>They accomplished a two pass analysis, the first pass is serializing the AST of every translation unit and creates an index of functions, the second pass does the real analysis, which can load the AST of function bodies on demand.<br class=""><br class=""></div>This approach can be used to achieve cross translation unit analysis for the clang Static Analyzer to some extent, but similar approach could be applicable to Clang Tidy and other clang based tools.<br class=""><br class=""></div>While this method is not likely to be a silver bullet for the Static Analyzer, I did some benchmarks to see how feasible this approach is. The baseline was running the Static Analyzer without the two pass analyis, the second one was running using the framework linked above.<br class=""><br class=""></div><div class="">For a 150k LOC C projects I got the following results:<br class=""></div><div class="">The size of the serialized ASTs was: 140MB<br class=""></div><div class="">The size of the indexes (textual representation): 4.4MB<br class=""></div><div class="">The time of the analysis was bellow 4X<br class=""></div><div class="">The amount of memory consumed was bellow 2X<br class=""><br class=""></div><div class="">All in all it looks like a feasible approach for some use cases.<br class=""><br class=""></div><div class="">I also tried to do a benchmark on the LLVM+Clang codebase. Unfortunately I was not able to run the analysis due to some missing features in the AST Importer. But I was able to serialize the ASTs and generate the indices:<br class=""></div><div class="">The siye of the serialized ASTs: 45.4 GB<br class=""></div><div class="">The siye of the function index: 1,6GB<br class=""><br class=""></div><div class="">While these numbers are less promising, I think there are some opportunities to reduce them significantly.<br class=""><br class=""></div><div class="">I propose the introduction of an analysis mode for exporting ASTs. In analysis mode the AST exporter would not emit the function body of a function for several cases:<br class=""></div><div class="">- In case a function is defined in a header, do not emit the body.<br class=""></div><div class="">- In case the function was defined in an implicit template specialisation, do not emit the body.<br class=""><br class=""></div><div class="">I think after similar optimizations it might be feasible to use this approach on LLVM scale projects as well, and it would be much easier to implement Clang based tools that can utilize cross translation unit capabilities.<br class=""><br class=""></div><div class="">In case the analyzer gets a new interprocedural analysis method that would increase the performance the users of this framework would profit from that approach immediately.<br class=""><br class=""></div><div class="">Does a framework like this worth mainlining and working on? What do you think?<br class=""><br class=""></div><div class="">(Note that, AST Importer related improvements are already being mainlined by Yury et al. My question is about the "analysis mode" for exporting ASTs, and a general framework to consume those exported ASTs.)<br class=""></div><div class=""><br class=""></div><div class="">Regards,<br class=""></div><div class="">Gábor<br class=""></div><div class=""><br class=""></div><div class=""><br class=""><br class=""></div></div></div>
</blockquote></div><br class=""></div>
<span id="cid:15538245-1070-4F1D-8877-AB2A3943059B"><statistics.json></span></div></blockquote></div><br class=""></body></html>