[PATCH] Division by zero

Anders Rönnholm Anders.Ronnholm at evidente.se
Fri Jul 4 01:15:26 PDT 2014


> Huh. So, I changed it back to the way it was:
> 
>  SVal Val = State->getRawSVal(*L);
> if (Val == S) {
>  Optional<DefinedSVal> DSV = Val.getAs<DefinedSVal>();
>    ConstraintManager &CM = C.getConstraintManager();
>    if (!CM.assume(State, *DSV, false))
>      return true;
>  }
>
>and tried running the tests. No failures. Then I flipped the "false" to "true" in the assume...and still no failures. So we must never be getting into that if-case!
>
>What would that affect?
>
>Jordan


We don't get into the if-case because we never get a Loc from Sval therefore it always returns false and our tests are passed.

Optional<Loc> L = S.getAs<Loc>();
  if (!L)
    return false;


Should we go back to how it was previously and walk backwards on the exploded node or do you have a better idea? Or leave it as it is? How can i write a test were we actually get a Loc?

bool TestAfterDivZeroChecker::isZero(SVal S, CheckerContext &C) const {
  const ExplodedNode *N = C.getPredecessor();
  while (N) {
    ProgramStateRef State = N->getState();

    if (const MemRegion *MR = C.getLocationRegionIfPostStore(N)) {
      SVal Val = State->getSVal(MR);
      if (Val == S) {
        Optional<DefinedSVal> DSV = Val.getAs<DefinedSVal>();
        ConstraintManager &CM = C.getConstraintManager();
        ProgramStateRef stateNotZero, stateZero;
        std::tie(stateNotZero, stateZero) = CM.assumeDual(State, *DSV);

        if (!stateNotZero) {
          assert(stateZero);
          return true;
        }
      }
    }
    N = N->pred_empty() ? nullptr : *(N->pred_begin());
  }
  return false;
}

//Anders



More information about the cfe-commits mailing list