Skip to content

Commit caf33c0

Browse files
committed
Sync with implementations of the XTaint Analysis is other repos
1 parent 8f3ae72 commit caf33c0

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEExtendedTaintAnalysis.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ class IDEExtendedTaintAnalysis
9898
static void identity(std::set<d_t> &Ret, d_t Source,
9999
const llvm::Instruction *CurrInst,
100100
bool AddGlobals = true);
101-
static std::set<d_t> identity(d_t Source, const llvm::Instruction *CurrInst,
102-
bool AddGlobals = true);
101+
[[nodiscard]] static std::set<d_t> identity(d_t Source,
102+
const llvm::Instruction *CurrInst,
103+
bool AddGlobals = true);
103104

104105
[[nodiscard]] static inline bool equivalent(d_t LHS, d_t RHS) {
105106
return LHS->equivalent(RHS);
@@ -202,6 +203,8 @@ class IDEExtendedTaintAnalysis
202203

203204
FactFactory.setDataLayout(DL);
204205

206+
this->getIFDSIDESolverConfig().setAutoAddZero(false);
207+
205208
/// TODO: Once we have better PointsToInfo, do a dynamic_cast over PT and
206209
/// set HasPrecisePointsToInfo accordingly
207210
}

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEExtendedTaintAnalysis.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@ IDEExtendedTaintAnalysis::initialSeeds() {
5353
const auto *EntryFn = base_t::ICF->getFunction(Ep);
5454

5555
if (!EntryFn) {
56-
std::cerr << "WARNING: Entry-Function \"" << Ep
57-
<< "\" not contained in the module; skip it\n";
56+
llvm::errs() << "WARNING: Entry-Function \"" << Ep
57+
<< "\" not contained in the module; skip it\n";
5858
continue;
5959
}
6060

6161
Seeds.addSeed(&EntryFn->front().front(), this->base_t::getZeroValue(),
6262
bottomElement());
6363
}
6464

65+
if (Seeds.empty()) {
66+
llvm::errs() << "WARNING: No initial seeds specified, skip the analysis. "
67+
"Please specify an entrypoint function or in the "
68+
"TaintConfig a source llvm::Instruction*\n";
69+
}
70+
6571
return Seeds;
6672
}
6773

@@ -223,9 +229,9 @@ void IDEExtendedTaintAnalysis::generateFromZero(std::set<d_t> &Dest,
223229
const llvm::Value *FormalArg,
224230
const llvm::Value *ActualArg,
225231
bool IncludeActualArg) {
226-
// TSF->isSource already covered by TSF->makeInitialSeeds
227232
if (const auto &SourceCB = TSF->getRegisteredSourceCallBack();
228-
SourceCB && SourceCB(Inst).count(ActualArg)) {
233+
TSF->isSource(ActualArg) ||
234+
(SourceCB && SourceCB(Inst).count(ActualArg))) {
229235
Dest.insert(makeFlowFact(FormalArg));
230236
if (IncludeActualArg) {
231237
Dest.insert(makeFlowFact(ActualArg));
@@ -415,8 +421,9 @@ IDEExtendedTaintAnalysis::getRetFlowFunction(n_t CallSite, f_t CalleeFun,
415421
/// pointer-analysis)
416422
class ArgPointsToCache {
417423
public:
418-
explicit ArgPointsToCache(PointsToInfo<v_t, n_t> *PT, size_t NumArgs)
419-
: Vec(NumArgs, nullptr), PT(PT) {}
424+
explicit ArgPointsToCache(PointsToInfo<v_t, n_t> *PT, size_t NumArgs,
425+
bool HasPrecisePointsToInfo)
426+
: Vec(NumArgs * !!HasPrecisePointsToInfo, nullptr), PT(PT) {}
420427

421428
const PointsToInfo<v_t, n_t>::PointsToSetTy &
422429
getOrCreatePts(size_t Idx, const llvm::Value *Ptr,
@@ -433,8 +440,14 @@ IDEExtendedTaintAnalysis::getRetFlowFunction(n_t CallSite, f_t CalleeFun,
433440
const auto *Call = llvm::cast<llvm::CallBase>(CallSite);
434441
return makeLambdaFlow<d_t>([this, Call, CalleeFun,
435442
ExitStmt{llvm::cast<llvm::ReturnInst>(ExitStmt)},
436-
PTC{ArgPointsToCache(
437-
PT, Call->getNumArgOperands())}](d_t Source) {
443+
PTC{ArgPointsToCache(PT,
444+
Call->getNumArgOperands(),
445+
HasPrecisePointsToInfo)}](
446+
d_t Source) -> std::set<d_t> {
447+
if (isZeroValue(Source)) {
448+
return {Source};
449+
}
450+
438451
std::set<d_t> Ret;
439452

440453
using ArgIterator = llvm::User::const_op_iterator;
@@ -505,7 +518,7 @@ IDEExtendedTaintAnalysis::getCallToRetFlowFunction(
505518
// return makeLambdaFlow<d_t>([CallSite, this](d_t Source) -> std::set<d_t>
506519
// {
507520
// if (isZeroValue(Source)) {
508-
// return {Source};
521+
// return {};
509522
// }
510523

511524
// if (const auto *CS = llvm::dyn_cast<llvm::CallBase>(CallSite)) {
@@ -538,7 +551,15 @@ IDEExtendedTaintAnalysis::getCallToRetFlowFunction(
538551
// The CTR-FF is traditionally an identity function. All CTR-relevant stuff is
539552
// handled on the edges.
540553

541-
return Identity<d_t>::getInstance();
554+
auto HasDeclaration =
555+
std::any_of(Callees.begin(), Callees.end(),
556+
[](const llvm::Function *F) { return F->isDeclaration(); });
557+
558+
if (HasDeclaration) {
559+
return Identity<d_t>::getInstance();
560+
}
561+
562+
return makeFF<Kill<d_t>>(getZeroValue());
542563
}
543564

544565
IDEExtendedTaintAnalysis::FlowFunctionPtrType

0 commit comments

Comments
 (0)