SimpleConstraintManager.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 assumeWithinInclusiveRange(ProgramStateRef State,
  33. NonLoc Value,
  34. const llvm::APSInt &From,
  35. const llvm::APSInt &To,
  36. bool InRange) override;
  37. ProgramStateRef assumeSymRel(ProgramStateRef state,
  38. const SymExpr *LHS,
  39. BinaryOperator::Opcode op,
  40. const llvm::APSInt& Int);
  41. ProgramStateRef assumeSymWithinInclusiveRange(ProgramStateRef State,
  42. SymbolRef Sym,
  43. const llvm::APSInt &From,
  44. const llvm::APSInt &To,
  45. bool InRange);
  46. protected:
  47. //===------------------------------------------------------------------===//
  48. // Interface that subclasses must implement.
  49. //===------------------------------------------------------------------===//
  50. // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
  51. // operation for the method being invoked.
  52. virtual ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
  53. const llvm::APSInt& V,
  54. const llvm::APSInt& Adjustment) = 0;
  55. virtual ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym,
  56. const llvm::APSInt& V,
  57. const llvm::APSInt& Adjustment) = 0;
  58. virtual ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym,
  59. const llvm::APSInt& V,
  60. const llvm::APSInt& Adjustment) = 0;
  61. virtual ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym,
  62. const llvm::APSInt& V,
  63. const llvm::APSInt& Adjustment) = 0;
  64. virtual ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym,
  65. const llvm::APSInt& V,
  66. const llvm::APSInt& Adjustment) = 0;
  67. virtual ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym,
  68. const llvm::APSInt& V,
  69. const llvm::APSInt& Adjustment) = 0;
  70. virtual ProgramStateRef assumeSymbolWithinInclusiveRange(
  71. ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &From,
  72. const llvm::APSInt &To, const llvm::APSInt &Adjustment) = 0;
  73. virtual ProgramStateRef assumeSymbolOutOfInclusiveRange(
  74. ProgramStateRef state, SymbolRef Sym, const llvm::APSInt &From,
  75. const llvm::APSInt &To, const llvm::APSInt &Adjustment) = 0;
  76. //===------------------------------------------------------------------===//
  77. // Internal implementation.
  78. //===------------------------------------------------------------------===//
  79. BasicValueFactory &getBasicVals() const { return SVB.getBasicValueFactory(); }
  80. SymbolManager &getSymbolManager() const { return SVB.getSymbolManager(); }
  81. bool canReasonAbout(SVal X) const override;
  82. ProgramStateRef assumeAux(ProgramStateRef state,
  83. NonLoc Cond,
  84. bool Assumption);
  85. ProgramStateRef assumeAuxForSymbol(ProgramStateRef State,
  86. SymbolRef Sym,
  87. bool Assumption);
  88. };
  89. } // end GR namespace
  90. } // end clang namespace
  91. #endif