10
10
#include " phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h"
11
11
12
12
#include " phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
13
+ #include " phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h"
13
14
#include " phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h"
14
15
#include " phasar/PhasarLLVM/Utils/LLVMShorthands.h"
15
16
#include " phasar/Utils/Logger.h"
@@ -114,7 +115,8 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite)
114
115
}
115
116
const auto *Callee = VFs[VtableIndex];
116
117
if (Callee == nullptr || !Callee->hasName () ||
117
- Callee->getName () == LLVMTypeHierarchy::PureVirtualCallName) {
118
+ Callee->getName () == LLVMTypeHierarchy::PureVirtualCallName ||
119
+ !isConsistentCall (CallSite, Callee)) {
118
120
continue ;
119
121
}
120
122
PossibleCallTargets.insert (Callee);
@@ -130,96 +132,93 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite)
130
132
131
133
auto OTFResolver::resolveFunctionPointer (const llvm::CallBase *CallSite)
132
134
-> FunctionSetTy {
135
+ if (!CallSite->getCalledOperand ()) {
136
+ return {};
137
+ }
138
+
133
139
FunctionSetTy Callees;
134
- if (CallSite->getCalledOperand () &&
135
- CallSite->getCalledOperand ()->getType ()->isPointerTy ()) {
136
- if (const auto *FTy = llvm::dyn_cast<llvm::FunctionType>(
137
- CallSite->getCalledOperand ()->getType ()->getPointerElementType ())) {
138
140
139
- auto PTS = PT.getAliasSet (CallSite->getCalledOperand (), CallSite);
141
+ auto PTS = PT.getAliasSet (CallSite->getCalledOperand (), CallSite);
140
142
141
- llvm::SmallVector<const llvm::GlobalVariable *, 2 > GlobalVariableWL;
142
- llvm::SmallVector<const llvm::ConstantAggregate *> ConstantAggregateWL;
143
- llvm::SmallPtrSet<const llvm::ConstantAggregate *, 4 >
144
- VisitedConstantAggregates;
143
+ llvm::SmallVector<const llvm::GlobalVariable *, 2 > GlobalVariableWL;
144
+ llvm::SmallVector<const llvm::ConstantAggregate *> ConstantAggregateWL;
145
+ llvm::SmallPtrSet<const llvm::ConstantAggregate *, 4 >
146
+ VisitedConstantAggregates;
145
147
146
- for (const auto *P : *PTS) {
147
- if (!llvm::isa<llvm::Constant>(P)) {
148
- continue ;
149
- }
148
+ for (const auto *P : *PTS) {
149
+ if (!llvm::isa<llvm::Constant>(P)) {
150
+ continue ;
151
+ }
150
152
151
- GlobalVariableWL.clear ();
152
- ConstantAggregateWL.clear ();
153
+ GlobalVariableWL.clear ();
154
+ ConstantAggregateWL.clear ();
153
155
154
- if (P->getType ()->isPointerTy () &&
155
- P->getType ()->getPointerElementType ()->isFunctionTy ()) {
156
- if (const auto *F = llvm::dyn_cast<llvm::Function>(P)) {
157
- if (matchesSignature (F, FTy, false )) {
158
- Callees.insert (F);
159
- }
160
- }
156
+ if (P->getType ()->isPointerTy () &&
157
+ P->getType ()->getPointerElementType ()->isFunctionTy ()) {
158
+ if (const auto *F = llvm::dyn_cast<llvm::Function>(P)) {
159
+ if (isConsistentCall (CallSite, F)) {
160
+ Callees.insert (F);
161
161
}
162
+ }
163
+ }
162
164
163
- if (const auto *GVP = llvm::dyn_cast<llvm::GlobalVariable>(P)) {
164
- GlobalVariableWL.push_back (GVP);
165
- } else if (const auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(P)) {
166
- for (const auto &Op : CE->operands ()) {
167
- if (const auto *GVOp = llvm::dyn_cast<llvm::GlobalVariable>(Op)) {
168
- GlobalVariableWL.push_back (GVOp);
169
- }
170
- }
165
+ if (const auto *GVP = llvm::dyn_cast<llvm::GlobalVariable>(P)) {
166
+ GlobalVariableWL.push_back (GVP);
167
+ } else if (const auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(P)) {
168
+ for (const auto &Op : CE->operands ()) {
169
+ if (const auto *GVOp = llvm::dyn_cast<llvm::GlobalVariable>(Op)) {
170
+ GlobalVariableWL.push_back (GVOp);
171
171
}
172
+ }
173
+ }
172
174
173
- if (GlobalVariableWL.empty ()) {
174
- continue ;
175
- }
175
+ if (GlobalVariableWL.empty ()) {
176
+ continue ;
177
+ }
176
178
177
- for (const auto *GV : GlobalVariableWL) {
178
- if (!GV->hasInitializer ()) {
179
- continue ;
180
- }
181
- const auto *InitConst = GV->getInitializer ();
182
- if (const auto *InitConstAggregate =
183
- llvm::dyn_cast<llvm::ConstantAggregate>(InitConst)) {
184
- ConstantAggregateWL.push_back (InitConstAggregate);
179
+ for (const auto *GV : GlobalVariableWL) {
180
+ if (!GV->hasInitializer ()) {
181
+ continue ;
182
+ }
183
+ const auto *InitConst = GV->getInitializer ();
184
+ if (const auto *InitConstAggregate =
185
+ llvm::dyn_cast<llvm::ConstantAggregate>(InitConst)) {
186
+ ConstantAggregateWL.push_back (InitConstAggregate);
187
+ }
188
+ }
189
+
190
+ VisitedConstantAggregates.clear ();
191
+
192
+ while (!ConstantAggregateWL.empty ()) {
193
+ const auto *ConstAggregateItem = ConstantAggregateWL.pop_back_val ();
194
+ // We may have already processed the item, avoid an infinite loop
195
+ if (!VisitedConstantAggregates.insert (ConstAggregateItem).second ) {
196
+ continue ;
197
+ }
198
+ for (const auto &Op : ConstAggregateItem->operands ()) {
199
+ if (const auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(Op)) {
200
+ if (CE->getType ()->isPointerTy () && CE->isCast ()) {
201
+ if (const auto *F =
202
+ llvm::dyn_cast<llvm::Function>(CE->getOperand (0 ));
203
+ F && isConsistentCall (CallSite, F)) {
204
+ Callees.insert (F);
205
+ }
185
206
}
186
207
}
187
208
188
- VisitedConstantAggregates.clear ();
189
-
190
- while (!ConstantAggregateWL.empty ()) {
191
- const auto *ConstAggregateItem = ConstantAggregateWL.pop_back_val ();
192
- // We may have already processed the item, avoid an infinite loop
193
- if (!VisitedConstantAggregates.insert (ConstAggregateItem).second ) {
209
+ if (const auto *F = llvm::dyn_cast<llvm::Function>(Op)) {
210
+ if (isConsistentCall (CallSite, F)) {
211
+ Callees.insert (F);
212
+ }
213
+ } else if (auto *CA = llvm::dyn_cast<llvm::ConstantAggregate>(Op)) {
214
+ ConstantAggregateWL.push_back (CA);
215
+ } else if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Op)) {
216
+ if (!GV->hasInitializer ()) {
194
217
continue ;
195
218
}
196
- for (const auto &Op : ConstAggregateItem->operands ()) {
197
- if (const auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(Op)) {
198
- if (CE->getType ()->isPointerTy () &&
199
- CE->getType ()->getPointerElementType () == FTy &&
200
- CE->isCast ()) {
201
- if (const auto *F =
202
- llvm::dyn_cast<llvm::Function>(CE->getOperand (0 ))) {
203
- Callees.insert (F);
204
- }
205
- }
206
- }
207
-
208
- if (const auto *F = llvm::dyn_cast<llvm::Function>(Op)) {
209
- if (matchesSignature (F, FTy, false )) {
210
- Callees.insert (F);
211
- }
212
- } else if (auto *CA = llvm::dyn_cast<llvm::ConstantAggregate>(Op)) {
213
- ConstantAggregateWL.push_back (CA);
214
- } else if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Op)) {
215
- if (!GV->hasInitializer ()) {
216
- continue ;
217
- }
218
- if (auto *GVCA = llvm::dyn_cast<llvm::ConstantAggregate>(
219
- GV->getInitializer ())) {
220
- ConstantAggregateWL.push_back (GVCA);
221
- }
222
- }
219
+ if (auto *GVCA = llvm::dyn_cast<llvm::ConstantAggregate>(
220
+ GV->getInitializer ())) {
221
+ ConstantAggregateWL.push_back (GVCA);
223
222
}
224
223
}
225
224
}
0 commit comments