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