]> granicus.if.org Git - clang/commitdiff
Fix regression introduced in r80786 and reported in PR 4867. We should use
authorTed Kremenek <kremenek@apple.com>
Thu, 3 Sep 2009 01:48:03 +0000 (01:48 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 3 Sep 2009 01:48:03 +0000 (01:48 +0000)
'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

lib/Analysis/GRExprEngineInternalChecks.cpp

index 45c3079d06ab310a0c2d4c404ca4acd6552089e0..ab19a6a94a3153ca9c7584561ffc486b52ec4a01 100644 (file)
@@ -716,11 +716,16 @@ void CheckBadDiv::PreVisitBinaryOperator(CheckerContext &C,
     return;
   }
 
+  // Handle the case where 'Denom' is UnknownVal.
+  const DefinedSVal *DV = dyn_cast<DefinedSVal>(&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<DefinedSVal>(Denom));
+  llvm::tie(stateNotZero, stateZero) = CM.AssumeDual(C.getState(), *DV);
   
   if (stateZero && !stateNotZero) {
     if (ExplodedNode *N = C.GenerateNode(B, stateZero, true)) {