diff options
| author | Ted Kremenek <kremenek@apple.com> | 2012-01-04 08:18:09 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2012-01-04 08:18:09 +0000 |
| commit | 5799cddde0bcd15c285230f7f612e3c8317c90c4 (patch) | |
| tree | 98f2a2328c65cf22433a2952ff36205967825ddb /clang/lib/StaticAnalyzer | |
| parent | 279c77b67795e64718f6a7fa06282023f3b1763a (diff) | |
| download | bcm5719-llvm-5799cddde0bcd15c285230f7f612e3c8317c90c4.tar.gz bcm5719-llvm-5799cddde0bcd15c285230f7f612e3c8317c90c4.zip | |
Extend ConditionBRVisitor to handle condition variable assignments.
llvm-svn: 147526
Diffstat (limited to 'clang/lib/StaticAnalyzer')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 6828a9e1590..88f38a3e4b4 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -604,18 +604,26 @@ ConditionBRVisitor::VisitTrueTest(const Expr *Cond, shouldInvert = !isVarLHS && isVarRHS; } + BinaryOperator::Opcode Op = BExpr->getOpcode(); + + if (BinaryOperator::isAssignmentOp(Op)) { + // For assignment operators, all that we care about is that the LHS + // evaluates to "true" or "false". + return VisitConditionVariable(LhsString, BExpr->getLHS(), tookTrue, + BRC, LC); + } + + // For non-assignment operations, we require that we can understand + // both the LHS and RHS. if (LhsString.empty() || RhsString.empty()) return 0; - - // Should we invert the strings if the LHS is not a variable name? + // Should we invert the strings if the LHS is not a variable name? llvm::SmallString<256> buf; llvm::raw_svector_ostream Out(buf); Out << "Assuming " << (shouldInvert ? RhsString : LhsString) << " is "; // Do we need to invert the opcode? - BinaryOperator::Opcode Op = BExpr->getOpcode(); - if (shouldInvert) switch (Op) { default: break; @@ -654,6 +662,33 @@ ConditionBRVisitor::VisitTrueTest(const Expr *Cond, PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LC); return new PathDiagnosticEventPiece(Loc, Out.str()); } + +PathDiagnosticPiece * +ConditionBRVisitor::VisitConditionVariable(StringRef LhsString, + const Expr *CondVarExpr, + const bool tookTrue, + BugReporterContext &BRC, + const LocationContext *LC) { + llvm::SmallString<256> buf; + llvm::raw_svector_ostream Out(buf); + Out << "Assuming " << LhsString << " is "; + + QualType Ty = CondVarExpr->getType(); + + if (Ty->isPointerType()) + Out << (tookTrue ? "not null" : "null"); + else if (Ty->isObjCObjectPointerType()) + Out << (tookTrue ? "not nil" : "nil"); + else if (Ty->isBooleanType()) + Out << (tookTrue ? "true" : "false"); + else if (Ty->isIntegerType()) + Out << (tookTrue ? "non-zero" : "zero"); + else + return 0; + + PathDiagnosticLocation Loc(CondVarExpr, BRC.getSourceManager(), LC); + return new PathDiagnosticEventPiece(Loc, Out.str()); +} PathDiagnosticPiece * ConditionBRVisitor::VisitTrueTest(const Expr *Cond, |

