From 35de14540f1c7d4743483f90aab791cbe515b4bb Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 17 May 2013 09:41:40 +0000 Subject: [analyzer; alternate edges] improve support for edges with PseudoObjectExprs. This optimizes some spurious edges resulting from PseudoObjectExprs. This required far more changes than I anticipated. The current ParentMap does not record any hierarchy information between a PseudoObjectExpr and its *semantic* expressions that may be wrapped in OpaqueValueExprs, which are the expressions actually laid out in the CFG. This means the arrow pruning logic could not map from an expression to its containing PseudoObjectExprs. To solve this, this patch adds a variant of ParentMap that returns the "semantic" parentage of expressions (essentially as they are viewed by the CFG). This alternate ParentMap is then used by the arrow reducing logic to identify edges into pseudo object expressions, and then eliminate them. llvm-svn: 182083 --- clang/lib/Analysis/AnalysisDeclContext.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'clang/lib/Analysis') diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp index 5ff7842407a..316892ea915 100644 --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -212,20 +212,34 @@ void AnalysisDeclContext::dumpCFG(bool ShowColors) { getCFG()->dump(getASTContext().getLangOpts(), ShowColors); } +static ParentMap *constructParentMap(bool isSemantic, + Stmt *Body, + const Decl *D) { + ParentMap *PM = new ParentMap(Body, isSemantic); + if (const CXXConstructorDecl *C = dyn_cast(D)) { + for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), + E = C->init_end(); + I != E; ++I) { + PM->addStmt((*I)->getInit()); + } + } + return PM; +} + ParentMap &AnalysisDeclContext::getParentMap() { if (!PM) { - PM.reset(new ParentMap(getBody())); - if (const CXXConstructorDecl *C = dyn_cast(getDecl())) { - for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), - E = C->init_end(); - I != E; ++I) { - PM->addStmt((*I)->getInit()); - } - } + PM.reset(constructParentMap(false, getBody(), getDecl())); } return *PM; } +ParentMap &AnalysisDeclContext::getSemanticParentMap() { + if (!SemanticPM) { + SemanticPM.reset(constructParentMap(true, getBody(), getDecl())); + } + return *SemanticPM; +} + PseudoConstantAnalysis *AnalysisDeclContext::getPseudoConstantAnalysis() { if (!PCA) PCA.reset(new PseudoConstantAnalysis(getBody())); -- cgit v1.2.3