ConstraintManager.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //== ConstraintManager.cpp - Constraints on symbolic values -----*- C++ -*--==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defined the interface to manage constraints on symbolic values.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
  14. using namespace clang;
  15. using namespace ento;
  16. ConstraintManager::~ConstraintManager() {}
  17. static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
  18. SymbolRef Sym) {
  19. const MemRegion *R = State->getStateManager().getRegionManager()
  20. .getSymbolicRegion(Sym);
  21. return loc::MemRegionVal(R);
  22. }
  23. ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
  24. SymbolRef Sym) {
  25. QualType Ty = Sym->getType();
  26. DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
  27. : nonloc::SymbolVal(Sym);
  28. const ProgramStatePair &P = assumeDual(State, V);
  29. if (P.first && !P.second)
  30. return ConditionTruthVal(false);
  31. if (!P.first && P.second)
  32. return ConditionTruthVal(true);
  33. return ConditionTruthVal();
  34. }