SimpleConstraintManager.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //== SimpleConstraintManager.h ----------------------------------*- 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. // Code shared between BasicConstraintManager and RangeConstraintManager.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_LIB_STATICANALYZER_CORE_SIMPLECONSTRAINTMANAGER_H
  14. #define LLVM_CLANG_LIB_STATICANALYZER_CORE_SIMPLECONSTRAINTMANAGER_H
  15. #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
  16. #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
  17. namespace clang {
  18. namespace ento {
  19. class SimpleConstraintManager : public ConstraintManager {
  20. SubEngine *SU;
  21. SValBuilder &SVB;
  22. public:
  23. SimpleConstraintManager(SubEngine *subengine, SValBuilder &SB)
  24. : SU(subengine), SVB(SB) {}
  25. ~SimpleConstraintManager() override;
  26. //===------------------------------------------------------------------===//
  27. // Common implementation for the interface provided by ConstraintManager.
  28. //===------------------------------------------------------------------===//
  29. ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond,
  30. bool Assumption) override;
  31. ProgramStateRef assume(ProgramStateRef state, NonLoc Cond, bool Assumption);
  32. ProgramStateRef assumeSymRel(ProgramStateRef state,
  33. const SymExpr *LHS,
  34. BinaryOperator::Opcode op,
  35. const llvm::APSInt& Int);
  36. protected:
  37. //===------------------------------------------------------------------===//
  38. // Interface that subclasses must implement.
  39. //===------------------------------------------------------------------===//
  40. // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
  41. // operation for the method being invoked.
  42. virtual ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
  43. const llvm::APSInt& V,
  44. const llvm::APSInt& Adjustment) = 0;
  45. virtual ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym,
  46. const llvm::APSInt& V,
  47. const llvm::APSInt& Adjustment) = 0;
  48. virtual ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym,
  49. const llvm::APSInt& V,
  50. const llvm::APSInt& Adjustment) = 0;
  51. virtual ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym,
  52. const llvm::APSInt& V,
  53. const llvm::APSInt& Adjustment) = 0;
  54. virtual ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym,
  55. const llvm::APSInt& V,
  56. const llvm::APSInt& Adjustment) = 0;
  57. virtual ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym,
  58. const llvm::APSInt& V,
  59. const llvm::APSInt& Adjustment) = 0;
  60. //===------------------------------------------------------------------===//
  61. // Internal implementation.
  62. //===------------------------------------------------------------------===//
  63. BasicValueFactory &getBasicVals() const { return SVB.getBasicValueFactory(); }
  64. SymbolManager &getSymbolManager() const { return SVB.getSymbolManager(); }
  65. bool canReasonAbout(SVal X) const override;
  66. ProgramStateRef assumeAux(ProgramStateRef state,
  67. NonLoc Cond,
  68. bool Assumption);
  69. ProgramStateRef assumeAuxForSymbol(ProgramStateRef State,
  70. SymbolRef Sym,
  71. bool Assumption);
  72. };
  73. } // end GR namespace
  74. } // end clang namespace
  75. #endif