diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-09-16 06:04:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-09-16 06:04:26 +0000 |
commit | 7c039bf4d87ea475a287374b4cd88ce4d73f3d12 (patch) | |
tree | e989427f688576f62143ba734f1f894b4dcab07c /lib/Analysis/GRExprEngineInternalChecks.cpp | |
parent | 76823024e0b68068915f7631acc88f44e1315133 (diff) |
Have divide-by-zero checker not handled undefined denominators. This is handled by the generic checking for undefined operands for BinaryOperators.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82019 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/GRExprEngineInternalChecks.cpp')
-rw-r--r-- | lib/Analysis/GRExprEngineInternalChecks.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp index 21f1465204..2eb5589117 100644 --- a/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/lib/Analysis/GRExprEngineInternalChecks.cpp @@ -194,8 +194,7 @@ public: class VISIBILITY_HIDDEN DivZero : public BuiltinBug { public: DivZero(GRExprEngine* eng = 0) - : BuiltinBug(eng,"Division-by-zero", - "Division by zero or undefined value.") {} + : BuiltinBug(eng,"Division by zero") {} void registerInitialVisitors(BugReporterContext& BRC, const ExplodedNode* N, @@ -222,24 +221,26 @@ public: llvm::SmallString<256> sbuf; llvm::raw_svector_ostream OS(sbuf); const GRState *ST = N->getState(); - const Expr *Ex = NULL; + const Expr *Ex = NULL; + bool isLeft = true; if (ST->getSVal(B->getLHS()).isUndef()) { Ex = B->getLHS()->IgnoreParenCasts(); - OS << "The left operand of the '"; + isLeft = true; } else if (ST->getSVal(B->getRHS()).isUndef()) { Ex = B->getRHS()->IgnoreParenCasts(); - OS << "The right operand of the '"; + isLeft = false; } - - if (Ex) { - OS << BinaryOperator::getOpcodeStr(B->getOpcode()) - << "' expression is an undefined " - "or otherwise garbage value"; + + if (Ex) { + OS << "The " << (isLeft ? "left" : "right") + << " operand of the '" + << BinaryOperator::getOpcodeStr(B->getOpcode()) + << "' expression is a garbage value"; } else { - // We KNOW that the result was undefined. + // Neither operand was undefined, but the result is undefined. OS << "The result of the '" << BinaryOperator::getOpcodeStr(B->getOpcode()) << "' expression is undefined"; @@ -268,8 +269,10 @@ public: if (const BinaryOperator *B = dyn_cast<BinaryOperator>(S)) { const GRState *ST = N->getState(); - X = ST->getSVal(B->getLHS()).isUndef() - ? B->getLHS()->IgnoreParenCasts() : B->getRHS()->IgnoreParenCasts(); + if (ST->getSVal(B->getLHS()).isUndef()) + X = B->getLHS(); + else if (ST->getSVal(B->getRHS()).isUndef()) + X = B->getRHS(); } registerTrackNullOrUndefValue(BRC, X, N); @@ -766,22 +769,11 @@ void CheckBadDiv::PreVisitBinaryOperator(CheckerContext &C, !B->getRHS()->getType()->isScalarType()) return; - // Check for divide by undefined. SVal Denom = C.getState()->getSVal(B->getRHS()); - - if (Denom.isUndef()) { - if (ExplodedNode *N = C.GenerateNode(B, true)) { - if (!BT) - BT = new DivZero(); - - C.EmitReport(new BuiltinBugReport(*BT, BT->getDescription().c_str(), N)); - } - return; - } - - // Handle the case where 'Denom' is UnknownVal. const DefinedSVal *DV = dyn_cast<DefinedSVal>(&Denom); + // Divide-by-undefined handled in the generic checking for uses of + // undefined values. if (!DV) return; |