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 14 #ifndef LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H 15 #define LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H 16 17 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h" 18 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" 19 20 namespace clang { 21 22 namespace ento { 23 24 class SimpleConstraintManager : public ConstraintManager { 25 SubEngine *SU; 26 SValBuilder &SVB; 27 public: 28 SimpleConstraintManager(SubEngine *subengine, SValBuilder &SB) 29 : SU(subengine), SVB(SB) {} 30 virtual ~SimpleConstraintManager(); 31 32 //===------------------------------------------------------------------===// 33 // Common implementation for the interface provided by ConstraintManager. 34 //===------------------------------------------------------------------===// 35 36 ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond, 37 bool Assumption); 38 39 ProgramStateRef assume(ProgramStateRef state, Loc Cond, bool Assumption); 40 41 ProgramStateRef assume(ProgramStateRef state, NonLoc Cond, bool Assumption); 42 43 ProgramStateRef assumeSymRel(ProgramStateRef state, 44 const SymExpr *LHS, 45 BinaryOperator::Opcode op, 46 const llvm::APSInt& Int); 47 48 protected: 49 50 //===------------------------------------------------------------------===// 51 // Interface that subclasses must implement. 52 //===------------------------------------------------------------------===// 53 54 // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison 55 // operation for the method being invoked. 56 virtual ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym, 57 const llvm::APSInt& V, 58 const llvm::APSInt& Adjustment) = 0; 59 60 virtual ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym, 61 const llvm::APSInt& V, 62 const llvm::APSInt& Adjustment) = 0; 63 64 virtual ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym, 65 const llvm::APSInt& V, 66 const llvm::APSInt& Adjustment) = 0; 67 68 virtual ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym, 69 const llvm::APSInt& V, 70 const llvm::APSInt& Adjustment) = 0; 71 72 virtual ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym, 73 const llvm::APSInt& V, 74 const llvm::APSInt& Adjustment) = 0; 75 76 virtual ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym, 77 const llvm::APSInt& V, 78 const llvm::APSInt& Adjustment) = 0; 79 80 //===------------------------------------------------------------------===// 81 // Internal implementation. 82 //===------------------------------------------------------------------===// 83 84 BasicValueFactory &getBasicVals() const { return SVB.getBasicValueFactory(); } 85 SymbolManager &getSymbolManager() const { return SVB.getSymbolManager(); } 86 87 bool canReasonAbout(SVal X) const; 88 89 ProgramStateRef assumeAux(ProgramStateRef state, 90 Loc Cond, 91 bool Assumption); 92 93 ProgramStateRef assumeAux(ProgramStateRef state, 94 NonLoc Cond, 95 bool Assumption); 96 97 ProgramStateRef assumeAuxForSymbol(ProgramStateRef State, 98 SymbolRef Sym, 99 bool Assumption); 100 }; 101 102 } // end GR namespace 103 104 } // end clang namespace 105 106 #endif 107