Skip to content

Commit 3c77321

Browse files
committed
Reduce function-complexity warnings by clang-tidy
1 parent 30d2c12 commit 3c77321

6 files changed

Lines changed: 172 additions & 136 deletions

File tree

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ class IDEExtendedTaintAnalysis
9393

9494
/// Add source to ret if it belongs to the same function as CurrInst. If
9595
/// addGlobals is true, also add llvm::GlobalValue.
96-
void identity(std::set<d_t> &Ret, const d_t &Source,
97-
const llvm::Instruction *CurrInst, bool AddGlobals = true);
98-
std::set<d_t> identity(const d_t &Source, const llvm::Instruction *CurrInst,
99-
bool AddGlobals = true);
96+
static void identity(std::set<d_t> &Ret, d_t Source,
97+
const llvm::Instruction *CurrInst,
98+
bool AddGlobals = true);
99+
static std::set<d_t> identity(d_t Source, const llvm::Instruction *CurrInst,
100+
bool AddGlobals = true);
100101

101-
[[nodiscard]] static inline bool equivalent(const d_t &LHS, const d_t &RHS) {
102+
[[nodiscard]] static inline bool equivalent(d_t LHS, d_t RHS) {
102103
return LHS->equivalent(RHS);
103104
}
104105

105-
[[nodiscard]] static inline bool
106-
equivalentExceptPointerArithmetics(const d_t &LHS, const d_t &RHS) {
106+
[[nodiscard]] static inline bool equivalentExceptPointerArithmetics(d_t LHS,
107+
d_t RHS) {
107108
return LHS->equivalentExceptPointerArithmetics(RHS);
108109
}
109110

@@ -121,6 +122,11 @@ class IDEExtendedTaintAnalysis
121122
const llvm::Value *ValueOp,
122123
const llvm::Instruction *Store,
123124
unsigned PALevel = 1);
125+
std::set<d_t> propagateAtStore(PointsToInfo<v_t, n_t>::PointsToSetPtrTy PTS,
126+
d_t Source, d_t Val, d_t Mem,
127+
const llvm::Value *PointerOp,
128+
const llvm::Value *ValueOp,
129+
const llvm::Instruction *Store);
124130

125131
template <typename CallBack, typename = std::enable_if_t<std::is_invocable_v<
126132
CallBack, const llvm::Value *>>>
@@ -143,6 +149,8 @@ class IDEExtendedTaintAnalysis
143149
}
144150
}
145151

152+
static const llvm::Value *getVAListTagOrNull(const llvm::Function *DestFun);
153+
146154
void populateWithMayAliases(SourceConfigTy &Facts) const;
147155

148156
bool isMustAlias(const SanitizerConfigTy &Facts, d_t CurrNod);

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ auto AbstractMemoryLocationImpl::computeOffset(
7171
[[nodiscard]] auto AbstractMemoryLocationImpl::operator-(
7272
const AbstractMemoryLocationImpl &TV) const -> llvm::ArrayRef<ptrdiff_t> {
7373
if (NumOffsets > TV.offsets().size()) {
74-
return offsets().slice(std::max(size_t(1), TV.offsets().size()) - 1);
74+
return offsets().drop_front(std::max(size_t(1), TV.offsets().size()) - 1);
7575
}
76-
return TV.offsets().slice(std::max(1U, NumOffsets) - 1);
76+
return TV.offsets().drop_front(std::max(1U, NumOffsets) - 1);
7777
}
7878

7979
bool AbstractMemoryLocationImpl::equivalentOffsets(
@@ -112,6 +112,7 @@ bool AbstractMemoryLocationImpl::mustAlias(
112112
<< llvmIRToShortString(TV.base()) << ") = " << std::boolalpha
113113
<< (PT.alias(base(), TV.base()) == AliasResult::MustAlias));
114114

115+
// NOLINTNEXTLINE(readability-identifier-naming)
115116
auto getFunctionOrNull = [](const llvm::Value *V) -> const llvm::Function * {
116117
if (const auto *Inst = llvm::dyn_cast<llvm::Instruction>(V)) {
117118
return Inst->getFunction();

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <new>
1313

1414
#include "llvm/IR/Instructions.h"
15+
#include "llvm/Support/Compiler.h"
1516

1617
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.h"
1718
#include "phasar/Utils/Logger.h"
@@ -25,8 +26,8 @@ auto AbstractMemoryLocationFactoryBase::Allocator::Block::create(
2526
Block *Next, size_t NumPointerEntries) -> Block * {
2627
// Allocate one more pointer to store the next-block ptr
2728

28-
if (NumPointerEntries >
29-
std::numeric_limits<size_t>::max() / sizeof(size_t) - 1) [[unlikely]] {
29+
if (LLVM_UNLIKELY(NumPointerEntries >
30+
std::numeric_limits<size_t>::max() / sizeof(size_t) - 1)) {
3031

3132
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), CRITICAL)
3233
<< "Cannot allocate " << NumPointerEntries

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/JoinEdgeFunction.cpp

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ auto JoinEdgeFunction::create(BasicBlockOrdering &BBO,
4444
}
4545
// Helper-function to handle the case where exactly one of {First, Second} is
4646
// a JoinEdgeFunction
47+
// NOLINTNEXTLINE(readability-identifier-naming)
4748
auto joinSingle =
4849
[&BBO](
4950
const EdgeFunctionPtrType &Single, const JoinEdgeFunction *Other,
@@ -64,49 +65,55 @@ auto JoinEdgeFunction::create(BasicBlockOrdering &BBO,
6465
return makeEF<JoinEdgeFunction>(BBO, std::move(Subs), Other->Seed);
6566
};
6667

67-
EdgeDomain Seed = psr::Top{};
68+
/// Check for JoinConstEF:
6869

69-
if (auto *FirstJC = dynamic_cast<JoinConstEdgeFunction *>(&*First)) {
70-
if (auto *SecondJC = dynamic_cast<JoinConstEdgeFunction *>(&*Second)) {
71-
Seed = EdgeDomain(FirstJC->getConstant()).join(SecondJC->getConstant());
72-
First = FirstJC->getFunction();
73-
Second = SecondJC->getFunction();
74-
} else {
75-
Seed = FirstJC->getConstant();
76-
First = FirstJC->getFunction();
77-
}
78-
} else if (auto *SecondJC = dynamic_cast<JoinConstEdgeFunction *>(&*Second)) {
70+
EdgeDomain Seed = psr::Top{};
71+
auto *FirstJC = dynamic_cast<JoinConstEdgeFunction *>(&*First);
72+
auto *SecondJC = dynamic_cast<JoinConstEdgeFunction *>(&*Second);
73+
if (FirstJC && SecondJC) {
74+
Seed = EdgeDomain(FirstJC->getConstant()).join(SecondJC->getConstant());
75+
First = FirstJC->getFunction();
76+
Second = SecondJC->getFunction();
77+
} else if (FirstJC) {
78+
Seed = FirstJC->getConstant();
79+
First = FirstJC->getFunction();
80+
} else if (SecondJC) {
7981
Seed = SecondJC->getConstant();
8082
Second = SecondJC->getFunction();
8183
}
8284

83-
if (&*First == &*Second || First->equal_to(Second)) // Just to be sure...
85+
if (&*First == &*Second || First->equal_to(Second)) {
86+
// Just to be sure...
8487
return First;
88+
}
89+
90+
/// Check for JoinEF:
8591

86-
if (auto *FirstEF = dynamic_cast<JoinEdgeFunction *>(&*First)) {
87-
if (auto *SecondEF = dynamic_cast<JoinEdgeFunction *>(&*Second)) {
88-
// Most difficult case: Both First and Second are JoinEdgeFunctions. Merge
89-
// the subEF-sets by using set-union (deduplicating)
90-
91-
if (SecondEF->SubEF.size() < FirstEF->SubEF.size()) {
92-
std::swap(FirstEF, SecondEF);
93-
}
94-
SubEdgeFuctionsTy Subs(SecondEF->SubEF);
95-
for (const auto &Sub : FirstEF->SubEF) {
96-
Subs.insert(Sub);
97-
}
98-
99-
if (Subs.size() > SubEFThreshold) {
100-
return getAllBot();
101-
}
102-
103-
return makeEF<JoinEdgeFunction>(BBO, std::move(Subs),
104-
FirstEF->Seed.join(SecondEF->Seed, &BBO));
92+
auto *FirstEF = dynamic_cast<JoinEdgeFunction *>(&*First);
93+
auto *SecondEF = dynamic_cast<JoinEdgeFunction *>(&*Second);
94+
if (FirstEF && SecondEF) {
95+
// Most difficult case: Both First and Second are JoinEdgeFunctions. Merge
96+
// the subEF-sets by using set-union (deduplicating)
97+
98+
if (SecondEF->SubEF.size() < FirstEF->SubEF.size()) {
99+
std::swap(FirstEF, SecondEF);
100+
}
101+
SubEdgeFuctionsTy Subs(SecondEF->SubEF);
102+
for (const auto &Sub : FirstEF->SubEF) {
103+
Subs.insert(Sub);
104+
}
105+
106+
if (Subs.size() > SubEFThreshold) {
107+
return getAllBot();
105108
}
106109

110+
return makeEF<JoinEdgeFunction>(BBO, std::move(Subs),
111+
FirstEF->Seed.join(SecondEF->Seed, &BBO));
112+
}
113+
if (FirstEF) {
107114
return joinSingle(Second, FirstEF, First);
108115
}
109-
if (auto *SecondEF = dynamic_cast<JoinEdgeFunction *>(&*Second)) {
116+
if (SecondEF) {
110117
return joinSingle(First, SecondEF, Second);
111118
}
112119

0 commit comments

Comments
 (0)