ConstraintManager.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include "llvm/Support/SaveAndRestore.h"
  15. using namespace clang;
  16. using namespace ento;
  17. ConstraintManager::~ConstraintManager() {}
  18. static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
  19. SymbolRef Sym) {
  20. const MemRegion *R = State->getStateManager().getRegionManager()
  21. .getSymbolicRegion(Sym);
  22. return loc::MemRegionVal(R);
  23. }
  24. /// Convenience method to query the state to see if a symbol is null or
  25. /// not null, or neither assumption can be made.
  26. ConditionTruthVal ConstraintManager::isNull(ProgramStateRef State,
  27. SymbolRef Sym) {
  28. // Disable recursive notification of clients.
  29. llvm::SaveAndRestore<bool> DisableNotify(NotifyAssumeClients, false);
  30. QualType Ty = Sym->getType();
  31. DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
  32. : nonloc::SymbolVal(Sym);
  33. const ProgramStatePair &P = assumeDual(State, V);
  34. if (P.first && !P.second)
  35. return ConditionTruthVal(false);
  36. if (!P.first && P.second)
  37. return ConditionTruthVal(true);
  38. return ConditionTruthVal();
  39. }