diff options
| author | Anna Zaks <ganna@apple.com> | 2013-04-03 19:28:15 +0000 |
|---|---|---|
| committer | Anna Zaks <ganna@apple.com> | 2013-04-03 19:28:15 +0000 |
| commit | b5d2fe8a1d94bfd0a44c3de6f32d4afc1786eb11 (patch) | |
| tree | 3972fe58ff43045975ca2afeeccd4f8d4631ea91 /clang/lib/StaticAnalyzer | |
| parent | ede0983f8858b4acf1978e2d650603a471f3bfc3 (diff) | |
| download | bcm5719-llvm-b5d2fe8a1d94bfd0a44c3de6f32d4afc1786eb11.tar.gz bcm5719-llvm-b5d2fe8a1d94bfd0a44c3de6f32d4afc1786eb11.zip | |
[analyzer] make peelOffOuterExpr in BugReporterVisitors recursively peel off select Exprs
llvm-svn: 178685
Diffstat (limited to 'clang/lib/StaticAnalyzer')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 7f71b8e81ed..60a7e65254d 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -789,36 +789,33 @@ static const MemRegion *getLocationRegionIfReference(const Expr *E, return 0; } -static const Expr *peelOffOuterExpr(const Stmt *S, +static const Expr *peelOffOuterExpr(const Expr *Ex, const ExplodedNode *N) { - if (const Expr *Ex = dyn_cast<Expr>(S)) { - Ex = Ex->IgnoreParenCasts(); - if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Ex)) - return EWC->getSubExpr(); - if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Ex)) - return OVE->getSourceExpr(); - - // Peel off the ternary operator. - if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(Ex)) { - const Expr *CondEx = CO->getCond(); - - // Find a node where the value of the condition is known. - do { - ProgramStateRef State = N->getState(); - SVal CondVal = State->getSVal(CondEx, N->getLocationContext()); - ConditionTruthVal CondEvaluated = State->isNull(CondVal); - if (CondEvaluated.isConstrained()) { - if (CondEvaluated.isConstrainedTrue()) - return CO->getFalseExpr(); - else - return CO->getTrueExpr(); - } - N = N->getFirstPred(); - } while (N); - - } + Ex = Ex->IgnoreParenCasts(); + if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Ex)) + return peelOffOuterExpr(EWC->getSubExpr(), N); + if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Ex)) + return peelOffOuterExpr(OVE->getSourceExpr(), N); + + // Peel off the ternary operator. + if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(Ex)) { + const Expr *CondEx = CO->getCond(); + + // Find a node where the value of the condition is known. + do { + ProgramStateRef State = N->getState(); + SVal CondVal = State->getSVal(CondEx, N->getLocationContext()); + ConditionTruthVal CondEvaluated = State->isNull(CondVal); + if (CondEvaluated.isConstrained()) { + if (CondEvaluated.isConstrainedTrue()) + return peelOffOuterExpr(CO->getFalseExpr(), N); + else + return peelOffOuterExpr(CO->getTrueExpr(), N); + } + N = N->getFirstPred(); + } while (N); } - return 0; + return Ex; } bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N, @@ -828,8 +825,12 @@ bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N, if (!S || !N) return false; - if (const Expr *Ex = peelOffOuterExpr(S, N)) - S = Ex; + if (const Expr *Ex = dyn_cast<Expr>(S)) { + Ex = Ex->IgnoreParenCasts(); + const Expr *PeeledEx = peelOffOuterExpr(Ex, N); + if (Ex != PeeledEx) + S = PeeledEx; + } const Expr *Inner = 0; if (const Expr *Ex = dyn_cast<Expr>(S)) { |

