Esempio n. 1
0
void StreamChecker::OpenFileAux(CheckerContext &C, const CallExpr *CE) const {
    const GRState *state = C.getState();
    unsigned Count = C.getNodeBuilder().getCurrentBlockCount();
    SValBuilder &svalBuilder = C.getSValBuilder();
    DefinedSVal RetVal =
        cast<DefinedSVal>(svalBuilder.getConjuredSymbolVal(0, CE, Count));
    state = state->BindExpr(CE, RetVal);

    ConstraintManager &CM = C.getConstraintManager();
    // Bifurcate the state into two: one with a valid FILE* pointer, the other
    // with a NULL.
    const GRState *stateNotNull, *stateNull;
    llvm::tie(stateNotNull, stateNull) = CM.assumeDual(state, RetVal);

    if (SymbolRef Sym = RetVal.getAsSymbol()) {
        // if RetVal is not NULL, set the symbol's state to Opened.
        stateNotNull =
            stateNotNull->set<StreamState>(Sym,StreamState::getOpened(CE));
        stateNull =
            stateNull->set<StreamState>(Sym, StreamState::getOpenFailed(CE));

        C.addTransition(stateNotNull);
        C.addTransition(stateNull);
    }
}
Esempio n. 2
0
void StreamChecker::OpenFileAux(CheckerContext &C, const CallExpr *CE) const {
  ProgramStateRef state = C.getState();
  SValBuilder &svalBuilder = C.getSValBuilder();
  const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
  DefinedSVal RetVal = svalBuilder.conjureSymbolVal(nullptr, CE, LCtx,
                                                    C.blockCount())
      .castAs<DefinedSVal>();
  state = state->BindExpr(CE, C.getLocationContext(), RetVal);

  ConstraintManager &CM = C.getConstraintManager();
  // Bifurcate the state into two: one with a valid FILE* pointer, the other
  // with a NULL.
  ProgramStateRef stateNotNull, stateNull;
  std::tie(stateNotNull, stateNull) = CM.assumeDual(state, RetVal);

  if (SymbolRef Sym = RetVal.getAsSymbol()) {
    // if RetVal is not NULL, set the symbol's state to Opened.
    stateNotNull =
      stateNotNull->set<StreamMap>(Sym,StreamState::getOpened(CE));
    stateNull =
      stateNull->set<StreamMap>(Sym, StreamState::getOpenFailed(CE));

    C.addTransition(stateNotNull);
    C.addTransition(stateNull);
  }
}