[cfe-commits] r144114 - /cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp

Anna Zaks ganna at apple.com
Tue Nov 8 11:56:36 PST 2011


Author: zaks
Date: Tue Nov  8 13:56:35 2011
New Revision: 144114

URL: http://llvm.org/viewvc/llvm-project?rev=144114&view=rev
Log:
[analyzer] Remove redundant check from DivZeroChecker

Analysis by Ted:
"
    if (stateZero && !stateNotZero) {

is checking to see if:

  (A)  "it is possible for the value to be zero"   (stateZero)

    AND

  (B) "it is not possible for the value to be non-zero"  (!stateNotZero)

That said, the only way for both B to be true AND A to be false is if the path is completely infeasible by the time we reach the divide-by-zero check.  For the most part (all cases?), such cases should automatically get pruned out at branches (i.e., an infeasible path gets dropped), which is the case in our tests.  So the question is whether or not such an infeasible path might not get dropped earlier?  I can't envision any right now.

Indeed, the rest of the checker assumes that if the bug condition didn't fire then 'stateNotZero' is non-NULL:

    C.addTransition(stateNotZero);
"

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp?rev=144114&r1=144113&r2=144114&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp Tue Nov  8 13:56:35 2011
@@ -55,7 +55,8 @@
   const ProgramState *stateNotZero, *stateZero;
   llvm::tie(stateNotZero, stateZero) = CM.assumeDual(C.getState(), *DV);
 
-  if (stateZero && !stateNotZero) {
+  if (!stateNotZero) {
+    assert(stateZero);
     if (ExplodedNode *N = C.generateSink(stateZero)) {
       if (!BT)
         BT.reset(new BuiltinBug("Division by zero"));





More information about the cfe-commits mailing list