Clang Project

clang_source_code/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
1//== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interface of a subengine of the CoreEngine.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SUBENGINE_H
13#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SUBENGINE_H
14
15#include "clang/Analysis/ProgramPoint.h"
16#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
17#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
18
19namespace clang {
20
21class CFGBlock;
22class CFGElement;
23class LocationContext;
24class Stmt;
25
26namespace cross_tu {
27class CrossTranslationUnitContext;
28}
29
30namespace ento {
31
32struct NodeBuilderContext;
33class AnalysisManager;
34class ExplodedNodeSet;
35class ExplodedNode;
36class ProgramState;
37class ProgramStateManager;
38class BlockCounter;
39class BranchNodeBuilder;
40class IndirectGotoNodeBuilder;
41class SwitchNodeBuilder;
42class EndOfFunctionNodeBuilder;
43class NodeBuilderWithSinks;
44class MemRegion;
45
46class SubEngine {
47  virtual void anchor();
48public:
49  virtual ~SubEngine() {}
50
51  virtual ProgramStateRef getInitialState(const LocationContext *InitLoc) = 0;
52
53  virtual AnalysisManager &getAnalysisManager() = 0;
54
55  virtual cross_tu::CrossTranslationUnitContext *
56  getCrossTranslationUnitContext() = 0;
57
58  virtual ProgramStateManager &getStateManager() = 0;
59
60  /// Called by CoreEngine. Used to generate new successor
61  /// nodes by processing the 'effects' of a block-level statement.
62  virtual void processCFGElement(const CFGElement EExplodedNodePred,
63                                 unsigned StmtIdxNodeBuilderContext *Ctx)=0;
64
65  /// Called by CoreEngine when it starts processing a CFGBlock.  The
66  /// SubEngine is expected to populate dstNodes with new nodes representing
67  /// updated analysis state, or generate no nodes at all if it doesn't.
68  virtual void processCFGBlockEntrance(const BlockEdge &L,
69                                       NodeBuilderWithSinks &nodeBuilder,
70                                       ExplodedNode *Pred) = 0;
71
72  /// Called by CoreEngine.  Used to generate successor
73  ///  nodes by processing the 'effects' of a branch condition.
74  virtual void processBranch(const Stmt *Condition,
75                             NodeBuilderContextBuilderCtx,
76                             ExplodedNode *Pred,
77                             ExplodedNodeSet &Dst,
78                             const CFGBlock *DstT,
79                             const CFGBlock *DstF) = 0;
80
81  /// Called by CoreEngine.
82  /// Used to generate successor nodes for temporary destructors depending
83  /// on whether the corresponding constructor was visited.
84  virtual void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
85                                             NodeBuilderContext &BldCtx,
86                                             ExplodedNode *Pred,
87                                             ExplodedNodeSet &Dst,
88                                             const CFGBlock *DstT,
89                                             const CFGBlock *DstF) = 0;
90
91  /// Called by CoreEngine.  Used to processing branching behavior
92  /// at static initializers.
93  virtual void processStaticInitializer(const DeclStmt *DS,
94                                        NodeBuilderContextBuilderCtx,
95                                        ExplodedNode *Pred,
96                                        ExplodedNodeSet &Dst,
97                                        const CFGBlock *DstT,
98                                        const CFGBlock *DstF) = 0;
99
100  /// Called by CoreEngine.  Used to generate successor
101  /// nodes by processing the 'effects' of a computed goto jump.
102  virtual void processIndirectGoto(IndirectGotoNodeBuilderbuilder) = 0;
103
104  /// Called by CoreEngine.  Used to generate successor
105  /// nodes by processing the 'effects' of a switch statement.
106  virtual void processSwitch(SwitchNodeBuilderbuilder) = 0;
107
108  /// Called by CoreEngine.  Used to notify checkers that processing a
109  /// function has begun. Called for both inlined and and top-level functions.
110  virtual void processBeginOfFunction(NodeBuilderContext &BC,
111                                      ExplodedNode *Pred,
112                                      ExplodedNodeSet &Dst,
113                                      const BlockEdge &L) = 0;
114
115  /// Called by CoreEngine.  Used to notify checkers that processing a
116  /// function has ended. Called for both inlined and and top-level functions.
117  virtual void processEndOfFunction(NodeBuilderContextBC,
118                                    ExplodedNode *Pred,
119                                    const ReturnStmt *RS = nullptr) = 0;
120
121  // Generate the entry node of the callee.
122  virtual void processCallEnter(NodeBuilderContextBCCallEnter CE,
123                                ExplodedNode *Pred) = 0;
124
125  // Generate the first post callsite node.
126  virtual void processCallExit(ExplodedNode *Pred) = 0;
127
128  /// Called by ConstraintManager. Used to call checker-specific
129  /// logic for handling assumptions on symbolic values.
130  virtual ProgramStateRef processAssume(ProgramStateRef state,
131                                       SVal condbool assumption) = 0;
132
133  /// processRegionChanges - Called by ProgramStateManager whenever a change is
134  /// made to the store. Used to update checkers that track region values.
135  virtual ProgramStateRef
136  processRegionChanges(ProgramStateRef state,
137                       const InvalidatedSymbols *invalidated,
138                       ArrayRef<const MemRegion *> ExplicitRegions,
139                       ArrayRef<const MemRegion *> Regions,
140                       const LocationContext *LCtx,
141                       const CallEvent *Call) = 0;
142
143
144  inline ProgramStateRef
145  processRegionChange(ProgramStateRef state,
146                      const MemRegionMR,
147                      const LocationContext *LCtx) {
148    return processRegionChanges(state, nullptr, MR, MR, LCtx, nullptr);
149  }
150
151  virtual ProgramStateRef
152  processPointerEscapedOnBind(ProgramStateRef StateSVal LocSVal Valconst LocationContext *LCtx) = 0;
153
154  virtual ProgramStateRef
155  notifyCheckersOfPointerEscape(ProgramStateRef State,
156                           const InvalidatedSymbols *Invalidated,
157                           ArrayRef<const MemRegion *> ExplicitRegions,
158                           const CallEvent *Call,
159                           RegionAndSymbolInvalidationTraits &HTraits) = 0;
160
161  /// printState - Called by ProgramStateManager to print checker-specific data.
162  virtual void printState(raw_ostream &OutProgramStateRef State,
163                          const char *NLconst char *Sep,
164                          const LocationContext *LCtx = nullptr) = 0;
165
166  /// Called by CoreEngine when the analysis worklist is either empty or the
167  //  maximum number of analysis steps have been reached.
168  virtual void processEndWorklist() = 0;
169};
170
171// end GR namespace
172
173// end clang namespace
174
175#endif
176
clang::ento::SubEngine::anchor
clang::ento::SubEngine::getInitialState
clang::ento::SubEngine::getAnalysisManager
clang::ento::SubEngine::getCrossTranslationUnitContext
clang::ento::SubEngine::getStateManager
clang::ento::SubEngine::processCFGElement
clang::ento::SubEngine::processCFGBlockEntrance
clang::ento::SubEngine::processBranch
clang::ento::SubEngine::processCleanupTemporaryBranch
clang::ento::SubEngine::processStaticInitializer
clang::ento::SubEngine::processIndirectGoto
clang::ento::SubEngine::processSwitch
clang::ento::SubEngine::processBeginOfFunction
clang::ento::SubEngine::processEndOfFunction
clang::ento::SubEngine::processCallEnter
clang::ento::SubEngine::processCallExit
clang::ento::SubEngine::processAssume
clang::ento::SubEngine::processRegionChanges
clang::ento::SubEngine::processRegionChange
clang::ento::SubEngine::processPointerEscapedOnBind
clang::ento::SubEngine::notifyCheckersOfPointerEscape
clang::ento::SubEngine::printState
clang::ento::SubEngine::processEndWorklist