From 913b0d0078b500f80dc89725eb343b34ad849f11 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Fri, 15 Mar 2013 01:15:12 +0000 Subject: [analyzer] Teach trackNullOrUndef to look through ternary operators Allows the suppression visitors trigger more often. llvm-svn: 177137 --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'clang/lib/StaticAnalyzer') diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 22c148be934..550a74667fb 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -772,16 +772,27 @@ static const MemRegion *getLocationRegionIfReference(const Expr *E, return 0; } -bool bugreporter::trackNullOrUndefValue(const ExplodedNode *ErrorNode, +bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, BugReport &report, bool IsArg) { - if (!S || !ErrorNode) + if (!S || !N) return false; + // Peel off OpaqueValueExpr. if (const OpaqueValueExpr *OVE = dyn_cast(S)) S = OVE->getSourceExpr(); - const ExplodedNode *N = ErrorNode; + // Peel off the ternary operator. + if (const ConditionalOperator *CO = dyn_cast(S)) { + ProgramStateRef State = N->getState(); + SVal CondVal = State->getSVal(CO->getCond(), N->getLocationContext()); + if (State->isNull(CondVal).isConstrainedTrue()) { + S = CO->getTrueExpr(); + } else { + assert(State->isNull(CondVal).isConstrainedFalse()); + S = CO->getFalseExpr(); + } + } const Expr *Inner = 0; if (const Expr *Ex = dyn_cast(S)) { -- cgit v1.2.3