[PATCH] Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a constructor initializer
Jordan Rose
jordan_rose at apple.com
Tue Dec 10 09:10:38 PST 2013
This doesn't actually help the analyzer yet: the init expression will be evaluated, but then the result will be thrown away and the old constant-evaluation mechanism will be used instead (see ``ExprEngine::Visit``). I'm okay with you not worrying about this for now.
I do approve of the comment change, though.
================
Comment at: lib/StaticAnalyzer/Core/BugReporter.cpp:282-294
@@ -267,6 +281,15 @@
} else if (End && isa<CXXDefaultInitExpr>(End)) {
- PathPieces::iterator Next = llvm::next(I);
- if (Next != E) {
- if (PathDiagnosticControlFlowPiece *NextCF =
- dyn_cast<PathDiagnosticControlFlowPiece>(*Next)) {
- NextCF->setStartLocation(CF->getStartLocation());
+ const Expr *InitExpr = cast<CXXDefaultInitExpr>(End)->getExpr();
+ if (Start && containsStmt(InitExpr, Start)) {
+ if (I != Pieces.begin()) {
+ PathPieces::iterator Prev = llvm::prior(I);
+ if (PathDiagnosticControlFlowPiece *PrevCF =
+ dyn_cast<PathDiagnosticControlFlowPiece>(*Prev)) {
+ CF->setStartLocation(PrevCF->getStartLocation());
+ Start = CF->getStartLocation().asStmt();
+ Pieces.erase(Prev);
+ continue;
+ }
+ }
+ } else {
+ PathPieces::iterator Next = llvm::next(I);
----------------
This definitely needs testing. The whole point of this section is to make Xcode arrows prettier, so without a test case that actually includes a plist it's kind of useless.
If you have Xcode, you can test the new arrows by overriding the analyzer binary with the not-so-secret setting CLANG_ANALYZER_EXEC. If not, don't worry about the arrows for now; I'll get to them soon.
================
Comment at: lib/StaticAnalyzer/Core/BugReporter.cpp:251-261
@@ +250,13 @@
+/// the second statement.
+static bool containsStmt(const Stmt *Ex, const Stmt *S) {
+ if (Ex == S)
+ return true;
+
+ for (Stmt::const_child_iterator I = Ex->child_begin(), E = Ex->child_end();
+ I != E; ++I) {
+ if (containsStmt(*I, S))
+ return true;
+ }
+ return false;
+}
+
----------------
Usually we do this using ParentMap so that it's a linear search. We'd have to start adding the children of the CXXDefaultInitExpr to the ParentMap, though.
http://llvm-reviews.chandlerc.com/D2370
More information about the cfe-commits
mailing list