[PATCH] D37897: [StaticAnalyzer] Fix ProgramState for static variables that are not written

Daniel Marjamäki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 13 11:46:56 PDT 2017

danielmarjamaki added inline comments.

Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:123
+  // Is variable changed anywhere in TU?
+  for (const Decl *D : AMgr.getASTContext().getTranslationUnitDecl()->decls()) {
+    if (isChanged(D, VD))
danielmarjamaki wrote:
> danielmarjamaki wrote:
> > dcoughlin wrote:
> > > Since you are calling `getInitialStateForGlobalStaticVar()` in `getInitialState()` for each static variable declaration and `getInitialState()` is called for each top-level function, you are doing an n^3 operation in the size of the translation unit, which is going to be very, very expensive for large translation units.
> > > 
> > > Have you considered doing the analysis for static variables that are never changed during call-graph construction? This should be a linear operation and doing it during call-graph construction would avoid an extra walk of the entire translation unit.
> > hmm... could you tell me where the call-graph construction is that I can tweak?
> I think I found it: `clang/lib/Analysis/CallGraph.cpp`
I now track variable modifications in call-graph construction instead.

Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:155
+  Children.push(FuncBody);
+  while (!Children.empty()) {
+    const Stmt *Child = Children.top();
szepet wrote:
> I think instead of this logic it would be better to use ConstStmtVisitor. In this case it does quite the same thing in a (maybe?) more structured manner. What do you think?
As far as I see ConstStmtVisitor is also recursive. Imho let's have readable code instead..



More information about the cfe-commits mailing list