Home | History | Annotate | Download | only in Core
      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_LIB_STATICANALYZER_CORE_SIMPLECONSTRAINTMANAGER_H
     15 #define LLVM_CLANG_LIB_STATICANALYZER_CORE_SIMPLECONSTRAINTMANAGER_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   ~SimpleConstraintManager() override;
     31 
     32   //===------------------------------------------------------------------===//
     33   // Common implementation for the interface provided by ConstraintManager.
     34   //===------------------------------------------------------------------===//
     35 
     36   ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond,
     37                         bool Assumption) override;
     38 
     39   ProgramStateRef assume(ProgramStateRef state, NonLoc Cond, bool Assumption);
     40 
     41   ProgramStateRef assumeWithinInclusiveRange(ProgramStateRef State,
     42                                              NonLoc Value,
     43                                              const llvm::APSInt &From,
     44                                              const llvm::APSInt &To,
     45                                              bool InRange) override;
     46 
     47   ProgramStateRef assumeSymRel(ProgramStateRef state,
     48                               const SymExpr *LHS,
     49                               BinaryOperator::Opcode op,
     50                               const llvm::APSInt& Int);
     51 
     52   ProgramStateRef assumeSymWithinInclusiveRange(ProgramStateRef State,
     53                                                 SymbolRef Sym,
     54                                                 const llvm::APSInt &From,
     55                                                 const llvm::APSInt &To,
     56                                                 bool InRange);
     57 
     58 
     59 protected:
     60 
     61   //===------------------------------------------------------------------===//
     62   // Interface that subclasses must implement.
     63   //===------------------------------------------------------------------===//
     64 
     65   // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
     66   // operation for the method being invoked.
     67   virtual ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
     68                                      const llvm::APSInt& V,
     69                                      const llvm::APSInt& Adjustment) = 0;
     70 
     71   virtual ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym,
     72                                      const llvm::APSInt& V,
     73                                      const llvm::APSInt& Adjustment) = 0;
     74 
     75   virtual ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym,
     76                                      const llvm::APSInt& V,
     77                                      const llvm::APSInt& Adjustment) = 0;
     78 
     79   virtual ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym,
     80                                      const llvm::APSInt& V,
     81                                      const llvm::APSInt& Adjustment) = 0;
     82 
     83   virtual ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym,
     84                                      const llvm::APSInt& V,
     85                                      const llvm::APSInt& Adjustment) = 0;
     86 
     87   virtual ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym,
     88                                      const llvm::APSInt& V,
     89                                      const llvm::APSInt& Adjustment) = 0;
     90 
     91 
     92   virtual ProgramStateRef assumeSymbolWithinInclusiveRange(
     93       ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &From,
     94       const llvm::APSInt &To, const llvm::APSInt &Adjustment) = 0;
     95 
     96   virtual ProgramStateRef assumeSymbolOutOfInclusiveRange(
     97       ProgramStateRef state, SymbolRef Sym, const llvm::APSInt &From,
     98       const llvm::APSInt &To, const llvm::APSInt &Adjustment) = 0;
     99   //===------------------------------------------------------------------===//
    100   // Internal implementation.
    101   //===------------------------------------------------------------------===//
    102 
    103   BasicValueFactory &getBasicVals() const { return SVB.getBasicValueFactory(); }
    104   SymbolManager &getSymbolManager() const { return SVB.getSymbolManager(); }
    105 
    106   bool canReasonAbout(SVal X) const override;
    107 
    108   ProgramStateRef assumeAux(ProgramStateRef state,
    109                                 NonLoc Cond,
    110                                 bool Assumption);
    111 
    112   ProgramStateRef assumeAuxForSymbol(ProgramStateRef State,
    113                                          SymbolRef Sym,
    114                                          bool Assumption);
    115 };
    116 
    117 } // end GR namespace
    118 
    119 } // end clang namespace
    120 
    121 #endif
    122