From: Ted Kremenek Date: Thu, 3 Sep 2009 01:48:03 +0000 (+0000) Subject: Fix regression introduced in r80786 and reported in PR 4867. We should use X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=970e03a6bf949947d8558ffd1b6cb6563e958831;p=clang 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80869 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp index 45c3079d06..ab19a6a94a 100644 --- a/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/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)) {