From b117fd91681f0f36fd5ded72e1f5d17f2645def0 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 3 Sep 2009 01:48:03 +0000 Subject: [PATCH] Fix regression introduced in r80786 and reported in PR 4867. We should use 'dyn_cast' instead of 'cast' as the denominator value could be UnknownVal (and is not guaranteed to be a DefinedVal). llvm-svn: 80869 --- clang/lib/Analysis/GRExprEngineInternalChecks.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Analysis/GRExprEngineInternalChecks.cpp b/clang/lib/Analysis/GRExprEngineInternalChecks.cpp index 45c3079d06ab..ab19a6a94a31 100644 --- a/clang/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/clang/lib/Analysis/GRExprEngineInternalChecks.cpp @@ -716,11 +716,16 @@ void CheckBadDiv::PreVisitBinaryOperator(CheckerContext &C, return; } + // Handle the case where 'Denom' is UnknownVal. + const DefinedSVal *DV = dyn_cast(&Denom); + + if (!DV) + return; + // Check for divide by zero. ConstraintManager &CM = C.getConstraintManager(); const GRState *stateNotZero, *stateZero; - llvm::tie(stateNotZero, stateZero) = CM.AssumeDual(C.getState(), - cast(Denom)); + llvm::tie(stateNotZero, stateZero) = CM.AssumeDual(C.getState(), *DV); if (stateZero && !stateNotZero) { if (ExplodedNode *N = C.GenerateNode(B, stateZero, true)) {