Skip to content

Commit 47e064a

Browse files
authored
Merge pull request #417 from secure-software-engineering/f-InterproceduralFFEnhancements
Bug fixes and enhancements in interprocedural flow functions
2 parents 367b664 + 1c35c90 commit 47e064a

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/LLVMFlowFunctions.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ class MapFactsToCallee : public FlowFunction<const llvm::Value *, Container> {
180180
}
181181
return {};
182182
}
183+
container_type Res;
183184
// Pass global variables as is, if desired
185+
// Globals could also be actual arguments, then the formal argument needs to
186+
// be generated below.
184187
// Need llvm::Constant here to cover also ConstantExpr and ConstantAggregate
185188
if (PropagateGlobals && llvm::isa<llvm::Constant>(Source)) {
186-
return {Source};
189+
Res.insert(Source);
187190
}
188-
container_type Res;
189191
// Handle back propagation of return value in backwards analysis.
190192
// We add it to the result here. Later, normal flow in callee can identify
191193
// it
@@ -259,6 +261,7 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
259261
const llvm::Function *CalleeFun;
260262
const llvm::ReturnInst *ExitInst;
261263
bool PropagateGlobals;
264+
const bool PropagateZeroToCaller;
262265
std::vector<const llvm::Value *> Actuals;
263266
std::vector<const llvm::Value *> Formals;
264267
std::function<bool(const llvm::Value *)> ParamPredicate;
@@ -271,10 +274,12 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
271274
std::function<bool(const llvm::Value *)> ParamPredicate =
272275
[](const llvm::Value *) { return true; },
273276
std::function<bool(const llvm::Function *)> ReturnPredicate =
274-
[](const llvm::Function *) { return true; })
277+
[](const llvm::Function *) { return true; },
278+
bool PropagateZeroToCaller = true)
275279
: CallSite(CallSite), CalleeFun(CalleeFun),
276280
ExitInst(llvm::dyn_cast<llvm::ReturnInst>(ExitInst)),
277281
PropagateGlobals(PropagateGlobals),
282+
PropagateZeroToCaller(PropagateZeroToCaller),
278283
ParamPredicate(std::move(ParamPredicate)),
279284
ReturnPredicate(std::move(ReturnPredicate)) {
280285
assert(ExitInst && "Should not be null");
@@ -294,12 +299,16 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
294299
container_type computeTargets(const llvm::Value *Source) override {
295300
assert(!CalleeFun->isDeclaration() &&
296301
"Cannot perform mapping to caller for function declaration");
297-
// Pass ZeroValue as is
302+
// Pass ZeroValue as is, if desired
298303
if (LLVMZeroValue::getInstance()->isLLVMZeroValue(Source)) {
299-
return {Source};
304+
if (PropagateZeroToCaller) {
305+
return {Source};
306+
}
307+
return {};
300308
}
301309
// Pass global variables as is, if desired
302-
if (PropagateGlobals && llvm::isa<llvm::GlobalVariable>(Source)) {
310+
// Need llvm::Constant here to cover also ConstantExpr and ConstantAggregate
311+
if (PropagateGlobals && llvm::isa<llvm::Constant>(Source)) {
303312
return {Source};
304313
}
305314
// Do the parameter mapping
@@ -340,7 +349,8 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
340349
}
341350
}
342351
// Collect return value facts
343-
if (Source == ExitInst->getReturnValue() && ReturnPredicate(CalleeFun)) {
352+
if (ExitInst != nullptr && Source == ExitInst->getReturnValue() &&
353+
ReturnPredicate(CalleeFun)) {
344354
Res.insert(CallSite);
345355
}
346356
return Res;

0 commit comments

Comments
 (0)