1 //== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the interface of a subengine of the CoreEngine.
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SUBENGINE_H
13 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SUBENGINE_H
15 #include "clang/Analysis/ProgramPoint.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
23 class LocationContext;
27 class CrossTranslationUnitContext;
32 struct NodeBuilderContext;
33 class AnalysisManager;
34 class ExplodedNodeSet;
37 class ProgramStateManager;
39 class BranchNodeBuilder;
40 class IndirectGotoNodeBuilder;
41 class SwitchNodeBuilder;
42 class EndOfFunctionNodeBuilder;
43 class NodeBuilderWithSinks;
47 virtual void anchor();
49 virtual ~SubEngine() {}
51 virtual ProgramStateRef getInitialState(const LocationContext *InitLoc) = 0;
53 virtual AnalysisManager &getAnalysisManager() = 0;
55 virtual cross_tu::CrossTranslationUnitContext *
56 getCrossTranslationUnitContext() = 0;
58 virtual ProgramStateManager &getStateManager() = 0;
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 E, ExplodedNode* Pred,
63 unsigned StmtIdx, NodeBuilderContext *Ctx)=0;
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;
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 NodeBuilderContext& BuilderCtx,
79 const CFGBlock *DstF) = 0;
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,
89 const CFGBlock *DstF) = 0;
91 /// Called by CoreEngine. Used to processing branching behavior
92 /// at static initializers.
93 virtual void processStaticInitializer(const DeclStmt *DS,
94 NodeBuilderContext& BuilderCtx,
98 const CFGBlock *DstF) = 0;
100 /// Called by CoreEngine. Used to generate successor
101 /// nodes by processing the 'effects' of a computed goto jump.
102 virtual void processIndirectGoto(IndirectGotoNodeBuilder& builder) = 0;
104 /// Called by CoreEngine. Used to generate successor
105 /// nodes by processing the 'effects' of a switch statement.
106 virtual void processSwitch(SwitchNodeBuilder& builder) = 0;
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,
112 ExplodedNodeSet &Dst,
113 const BlockEdge &L) = 0;
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(NodeBuilderContext& BC,
119 const ReturnStmt *RS = nullptr) = 0;
121 // Generate the entry node of the callee.
122 virtual void processCallEnter(NodeBuilderContext& BC, CallEnter CE,
123 ExplodedNode *Pred) = 0;
125 // Generate the first post callsite node.
126 virtual void processCallExit(ExplodedNode *Pred) = 0;
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 cond, bool assumption) = 0;
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;
144 inline ProgramStateRef
145 processRegionChange(ProgramStateRef state,
147 const LocationContext *LCtx) {
148 return processRegionChanges(state, nullptr, MR, MR, LCtx, nullptr);
151 virtual ProgramStateRef
152 processPointerEscapedOnBind(ProgramStateRef State, SVal Loc, SVal Val, const LocationContext *LCtx) = 0;
154 virtual ProgramStateRef
155 notifyCheckersOfPointerEscape(ProgramStateRef State,
156 const InvalidatedSymbols *Invalidated,
157 ArrayRef<const MemRegion *> ExplicitRegions,
158 const CallEvent *Call,
159 RegionAndSymbolInvalidationTraits &HTraits) = 0;
161 /// printJson - Called by ProgramStateManager to print checker-specific data.
162 virtual void printJson(raw_ostream &Out, ProgramStateRef State,
163 const LocationContext *LCtx, const char *NL,
164 unsigned int Space, bool IsDot) const = 0;
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;
171 } // end GR namespace
173 } // end clang namespace