Skip to content

Commit 86a1aef

Browse files
authored
Merge pull request #476 from secure-software-engineering/f-ClangTidyFixUtils22
clang-tidy: fix utils
2 parents eb80f64 + 5f5ea02 commit 86a1aef

30 files changed

Lines changed: 474 additions & 418 deletions

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ CheckOptions:
5454
value: (c|d|d1|d2|d3|d4|d5|d5_restoredCtx|eP|f|f3|f4|f5|fCalleeSummary|g|n|dPrime|fPrime)
5555
- key: readability-identifier-naming.ParameterIgnoredRegexp
5656
value: (d|d1|d2|d3|d4|d5|eP|f|n)
57+
- key: readability-identifier-naming.FunctionIgnoredRegexp
58+
value: (try_emplace|from_json|to_json)
5759
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
5860
value: 1
5961
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions

include/phasar/PhasarLLVM/Domain/ExtendedValue.h

Lines changed: 101 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -19,159 +19,180 @@ namespace psr {
1919

2020
class ExtendedValue {
2121
public:
22-
ExtendedValue() {}
23-
explicit ExtendedValue(const llvm::Value *_value) : value(_value) {
24-
assert(value && "ExtendedValue requires an llvm::Value* object");
22+
ExtendedValue() = default;
23+
explicit ExtendedValue(const llvm::Value *Val) : Val(Val) {
24+
assert(Val && "ExtendedValue requires an llvm::Value* object");
2525
}
2626
~ExtendedValue() = default;
2727

28-
bool operator==(const ExtendedValue &rhs) const {
29-
bool isValueEqual = value == rhs.value;
30-
if (!isValueEqual)
28+
bool operator==(const ExtendedValue &Rhs) const {
29+
bool IsValueEqual = Val == Rhs.Val;
30+
if (!IsValueEqual) {
3131
return false;
32+
}
3233

33-
bool isMemLocationSeqEqual = memLocationSeq == rhs.memLocationSeq;
34-
if (!isMemLocationSeqEqual)
34+
bool IsMemLocationSeqEqual = MemLocationSeq == Rhs.MemLocationSeq;
35+
if (!IsMemLocationSeqEqual) {
3536
return false;
37+
}
3638

37-
bool isEndOfTaintedBlockLabelEqual =
38-
endOfTaintedBlockLabel == rhs.endOfTaintedBlockLabel;
39-
if (!isEndOfTaintedBlockLabelEqual)
39+
bool IsEndOfTaintedBlockLabelEqual =
40+
EndOfTaintedBlockLabel == Rhs.EndOfTaintedBlockLabel;
41+
if (!IsEndOfTaintedBlockLabelEqual) {
4042
return false;
43+
}
4144

42-
bool isVaListMemLocationSeqEqual =
43-
vaListMemLocationSeq == rhs.vaListMemLocationSeq;
44-
if (!isVaListMemLocationSeqEqual)
45+
bool IsVaListMemLocationSeqEqual =
46+
VaListMemLocationSeq == Rhs.VaListMemLocationSeq;
47+
if (!IsVaListMemLocationSeqEqual) {
4548
return false;
49+
}
4650

47-
bool isVarArgIndexEqual = varArgIndex == rhs.varArgIndex;
48-
if (!isVarArgIndexEqual)
51+
bool IsVarArgIndexEqual = VarArgIndex == Rhs.VarArgIndex;
52+
if (!IsVarArgIndexEqual) {
4953
return false;
54+
}
5055

51-
bool isCurrentVarArgIndexEqual =
52-
currentVarArgIndex == rhs.currentVarArgIndex;
53-
if (!isCurrentVarArgIndexEqual)
56+
bool IsCurrentVarArgIndexEqual =
57+
CurrentVarArgIndex == Rhs.CurrentVarArgIndex;
58+
if (!IsCurrentVarArgIndexEqual) {
5459
return false;
60+
}
5561

5662
return true;
5763
}
5864

59-
bool operator<(const ExtendedValue &rhs) const {
60-
if (std::less<const llvm::Value *>{}(value, rhs.value))
65+
bool operator<(const ExtendedValue &Rhs) const {
66+
if (std::less<const llvm::Value *>{}(Val, Rhs.Val)) {
6167
return true;
62-
if (std::less<const llvm::Value *>{}(rhs.value, value))
68+
}
69+
if (std::less<const llvm::Value *>{}(Rhs.Val, Val)) {
6370
return false;
71+
}
6472

65-
if (memLocationSeq < rhs.memLocationSeq)
73+
if (MemLocationSeq < Rhs.MemLocationSeq) {
6674
return true;
67-
if (rhs.memLocationSeq < memLocationSeq)
75+
}
76+
if (Rhs.MemLocationSeq < MemLocationSeq) {
6877
return false;
78+
}
6979

70-
if (std::less<std::string>{}(endOfTaintedBlockLabel,
71-
rhs.endOfTaintedBlockLabel))
80+
if (std::less<std::string>{}(EndOfTaintedBlockLabel,
81+
Rhs.EndOfTaintedBlockLabel)) {
7282
return true;
73-
if (std::less<std::string>{}(rhs.endOfTaintedBlockLabel,
74-
endOfTaintedBlockLabel))
83+
}
84+
if (std::less<std::string>{}(Rhs.EndOfTaintedBlockLabel,
85+
EndOfTaintedBlockLabel)) {
7586
return false;
87+
}
7688

77-
if (vaListMemLocationSeq < rhs.vaListMemLocationSeq)
89+
if (VaListMemLocationSeq < Rhs.VaListMemLocationSeq) {
7890
return true;
79-
if (rhs.vaListMemLocationSeq < vaListMemLocationSeq)
91+
}
92+
if (Rhs.VaListMemLocationSeq < VaListMemLocationSeq) {
8093
return false;
94+
}
8195

82-
if (std::less<long>{}(varArgIndex, rhs.varArgIndex))
96+
if (std::less<long>{}(VarArgIndex, Rhs.VarArgIndex)) {
8397
return true;
84-
if (std::less<long>{}(rhs.varArgIndex, varArgIndex))
98+
}
99+
if (std::less<long>{}(Rhs.VarArgIndex, VarArgIndex)) {
85100
return false;
101+
}
86102

87-
return std::less<long>{}(currentVarArgIndex, rhs.currentVarArgIndex);
103+
return std::less<long>{}(CurrentVarArgIndex, Rhs.CurrentVarArgIndex);
88104
}
89105

90-
const llvm::Value *getValue() const { return value; }
106+
[[nodiscard]] const llvm::Value *getValue() const { return Val; }
91107

92-
const std::vector<const llvm::Value *> getMemLocationSeq() const {
93-
return memLocationSeq;
108+
[[nodiscard]] std::vector<const llvm::Value *> getMemLocationSeq() const {
109+
return MemLocationSeq;
94110
}
95-
void setMemLocationSeq(std::vector<const llvm::Value *> _memLocationSeq) {
96-
memLocationSeq = _memLocationSeq;
111+
void
112+
setMemLocationSeq(const std::vector<const llvm::Value *> &MemLocationSeq) {
113+
this->MemLocationSeq = MemLocationSeq;
97114
}
98115

99-
const std::string getEndOfTaintedBlockLabel() const {
100-
return endOfTaintedBlockLabel;
116+
[[nodiscard]] std::string getEndOfTaintedBlockLabel() const {
117+
return EndOfTaintedBlockLabel;
101118
}
102-
void setEndOfTaintedBlockLabel(std::string _endOfTaintedBlockLabel) {
103-
endOfTaintedBlockLabel = _endOfTaintedBlockLabel;
119+
void setEndOfTaintedBlockLabel(const std::string &EndOfTaintedBlockLabel) {
120+
this->EndOfTaintedBlockLabel = EndOfTaintedBlockLabel;
104121
}
105122

106-
const std::vector<const llvm::Value *> getVaListMemLocationSeq() const {
107-
return vaListMemLocationSeq;
123+
[[nodiscard]] std::vector<const llvm::Value *>
124+
getVaListMemLocationSeq() const {
125+
return VaListMemLocationSeq;
108126
}
109127
void setVaListMemLocationSeq(
110-
std::vector<const llvm::Value *> _vaListMemLocationSeq) {
111-
vaListMemLocationSeq = _vaListMemLocationSeq;
128+
const std::vector<const llvm::Value *> &VaListMemLocationSeq) {
129+
this->VaListMemLocationSeq = VaListMemLocationSeq;
112130
}
113131

114-
long getVarArgIndex() const { return varArgIndex; }
115-
void setVarArgIndex(long _varArgIndex) { varArgIndex = _varArgIndex; }
132+
[[nodiscard]] long getVarArgIndex() const { return VarArgIndex; }
133+
void setVarArgIndex(long VarArgIndex) { this->VarArgIndex = VarArgIndex; }
116134

117135
void resetVarArgIndex() {
118-
if (!isVarArgTemplate())
119-
varArgIndex = -1L;
136+
if (!isVarArgTemplate()) {
137+
VarArgIndex = -1L;
138+
}
120139
}
121140

122-
long getCurrentVarArgIndex() const { return currentVarArgIndex; }
141+
[[nodiscard]] long getCurrentVarArgIndex() const {
142+
return CurrentVarArgIndex;
143+
}
123144
void incrementCurrentVarArgIndex() {
124-
if (!isVarArgTemplate())
125-
++currentVarArgIndex;
145+
if (!isVarArgTemplate()) {
146+
++CurrentVarArgIndex;
147+
}
126148
}
127149

128-
bool isVarArgTemplate() const {
129-
return vaListMemLocationSeq.empty() && isVarArg();
150+
[[nodiscard]] bool isVarArg() const { return VarArgIndex > -1L; }
151+
[[nodiscard]] bool isVarArgTemplate() const {
152+
return VaListMemLocationSeq.empty() && isVarArg();
130153
}
131154

132-
[[nodiscard]] bool isVarArg() const { return varArgIndex > -1L; }
133-
134155
private:
135-
const llvm::Value *value = nullptr;
136-
std::vector<const llvm::Value *> memLocationSeq;
137-
std::string endOfTaintedBlockLabel;
156+
const llvm::Value *Val = nullptr;
157+
std::vector<const llvm::Value *> MemLocationSeq;
158+
std::string EndOfTaintedBlockLabel;
138159

139-
std::vector<const llvm::Value *> vaListMemLocationSeq;
140-
long varArgIndex = -1L;
141-
long currentVarArgIndex = -1L;
160+
std::vector<const llvm::Value *> VaListMemLocationSeq;
161+
long VarArgIndex = -1L;
162+
long CurrentVarArgIndex = -1L;
142163
};
143164

144165
} // namespace psr
145166

146167
namespace std {
147168

148169
template <> struct hash<psr::ExtendedValue> {
149-
std::size_t operator()(const psr::ExtendedValue &ev) const {
150-
std::size_t seed = 0x4711;
170+
std::size_t operator()(const psr::ExtendedValue &Ev) const {
171+
std::size_t Seed = 0x4711;
151172

152-
seed ^= hash<const llvm::Value *>{}(ev.getValue()) + 0x9e3779b9 +
153-
(seed << 6) + (seed >> 2);
173+
Seed ^= hash<const llvm::Value *>{}(Ev.getValue()) + 0x9e3779b9 +
174+
(Seed << 6) + (Seed >> 2);
154175

155-
for (const auto &memLocationPart : ev.getMemLocationSeq()) {
156-
seed ^= hash<const llvm::Value *>{}(memLocationPart) + 0x9e3779b9 +
157-
(seed << 6) + (seed >> 2);
176+
for (const auto &MemLocationPart : Ev.getMemLocationSeq()) {
177+
Seed ^= hash<const llvm::Value *>{}(MemLocationPart) + 0x9e3779b9 +
178+
(Seed << 6) + (Seed >> 2);
158179
}
159180

160-
seed ^= hash<string>{}(ev.getEndOfTaintedBlockLabel()) + 0x9e3779b9 +
161-
(seed << 6) + (seed >> 2);
181+
Seed ^= hash<string>{}(Ev.getEndOfTaintedBlockLabel()) + 0x9e3779b9 +
182+
(Seed << 6) + (Seed >> 2);
162183

163-
for (const auto &vaListMemLocationPart : ev.getVaListMemLocationSeq()) {
164-
seed ^= hash<const llvm::Value *>{}(vaListMemLocationPart) + 0x9e3779b9 +
165-
(seed << 6) + (seed >> 2);
184+
for (const auto &VaListMemLocationPart : Ev.getVaListMemLocationSeq()) {
185+
Seed ^= hash<const llvm::Value *>{}(VaListMemLocationPart) + 0x9e3779b9 +
186+
(Seed << 6) + (Seed >> 2);
166187
}
167188

168-
seed ^= hash<long>{}(ev.getVarArgIndex()) + 0x9e3779b9 + (seed << 6) +
169-
(seed >> 2);
189+
Seed ^= hash<long>{}(Ev.getVarArgIndex()) + 0x9e3779b9 + (Seed << 6) +
190+
(Seed >> 2);
170191

171-
seed ^= hash<long>{}(ev.getCurrentVarArgIndex()) + 0x9e3779b9 +
172-
(seed << 6) + (seed >> 2);
192+
Seed ^= hash<long>{}(Ev.getCurrentVarArgIndex()) + 0x9e3779b9 +
193+
(Seed << 6) + (Seed >> 2);
173194

174-
return seed;
195+
return Seed;
175196
}
176197
};
177198

include/phasar/PhasarLLVM/TaintConfig/TaintConfigUtilities.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void collectGeneratedFacts(ContainerTy &Dest, const TaintConfig &Config,
3737
Dest.insert(CB);
3838
}
3939

40-
for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
41-
if (Config.isSource(Callee->getArg(i))) {
42-
Dest.insert(CB->getArgOperand(i));
40+
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
41+
if (Config.isSource(Callee->getArg(I))) {
42+
Dest.insert(CB->getArgOperand(I));
4343
}
4444
}
4545
}
@@ -58,9 +58,9 @@ void collectLeakedFacts(ContainerTy &Dest, const TaintConfig &Config,
5858
std::inserter(Dest, Dest.end()), LeakIf);
5959
}
6060

61-
for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
62-
if (Config.isSink(Callee->getArg(i)) && LeakIf(CB->getArgOperand(i))) {
63-
Dest.insert(CB->getArgOperand(i));
61+
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
62+
if (Config.isSink(Callee->getArg(I)) && LeakIf(CB->getArgOperand(I))) {
63+
Dest.insert(CB->getArgOperand(I));
6464
}
6565
}
6666
}
@@ -70,7 +70,7 @@ inline void collectLeakedFacts(ContainerTy &Dest, const TaintConfig &Config,
7070
const llvm::CallBase *CB,
7171
const llvm::Function *Callee) {
7272
collectLeakedFacts(Dest, Config, CB, Callee,
73-
[](const llvm::Value *V) { return true; });
73+
[](const llvm::Value * /*V*/) { return true; });
7474
}
7575

7676
template <typename ContainerTy,
@@ -79,9 +79,9 @@ template <typename ContainerTy,
7979
void collectSanitizedFacts(ContainerTy &Dest, const TaintConfig &Config,
8080
const llvm::CallBase *CB,
8181
const llvm::Function *Callee) {
82-
for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
83-
if (Config.isSanitizer(Callee->getArg(i))) {
84-
Dest.insert(CB->getArgOperand(i));
82+
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
83+
if (Config.isSanitizer(Callee->getArg(I))) {
84+
Dest.insert(CB->getArgOperand(I));
8585
}
8686
}
8787
}

include/phasar/PhasarLLVM/Utils/BasicBlockOrdering.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class DefaultDominatorTreeAnalysis {
4040
class BasicBlockOrdering {
4141
/// Note: Cannot use std::function, because we need to support move-only
4242
/// functors(e.g. DefaultDominatorTreeAnalysis)
43-
llvm::unique_function<llvm::DominatorTree &(const llvm::Function *)> getDom;
43+
llvm::unique_function<llvm::DominatorTree &(const llvm::Function *)>
44+
getDom; // NOLINT
4445

4546
public:
4647
template <

include/phasar/PhasarLLVM/Utils/BinaryDomain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern const std::map<std::string, BinaryDomain> StringToBinaryDomain;
2828

2929
extern const std::map<BinaryDomain, std::string> BinaryDomainToString;
3030

31-
std::ostream &operator<<(std::ostream &os, const BinaryDomain &b);
31+
std::ostream &operator<<(std::ostream &OS, const BinaryDomain &B);
3232

3333
} // namespace psr
3434

include/phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::string toString(const DataFlowAnalysisType &D);
3737

3838
DataFlowAnalysisType toDataFlowAnalysisType(const std::string &S);
3939

40-
std::ostream &operator<<(std::ostream &os, const DataFlowAnalysisType &D);
40+
std::ostream &operator<<(std::ostream &OS, const DataFlowAnalysisType &D);
4141

4242
} // namespace psr
4343

include/phasar/PhasarLLVM/Utils/IOFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std::string toString(const IOFormat &D);
2424

2525
IOFormat toIOFormat(const std::string &S);
2626

27-
std::ostream &operator<<(std::ostream &os, const IOFormat &D);
27+
std::ostream &operator<<(std::ostream &Os, const IOFormat &D);
2828

2929
} // namespace psr
3030

include/phasar/PhasarLLVM/Utils/LatticeDomain.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ inline bool operator==(const LatticeDomain<L> &Lhs,
6161
std::holds_alternative<Bottom>(Rhs)) {
6262
return true;
6363
}
64-
if (auto LhsPtr = std::get_if<L>(&Lhs)) {
65-
if (auto RhsPtr = std::get_if<L>(&Rhs)) {
64+
if (auto *LhsPtr = std::get_if<L>(&Lhs)) {
65+
if (auto *RhsPtr = std::get_if<L>(&Rhs)) {
6666
return *LhsPtr == *RhsPtr;
6767
}
6868
}
@@ -86,8 +86,8 @@ inline bool operator<(const LatticeDomain<L> &Lhs,
8686
return true;
8787
}
8888

89-
if (auto LhsPtr = std::get_if<L>(&Lhs)) {
90-
if (auto RhsPtr = std::get_if<L>(&Rhs)) {
89+
if (auto *LhsPtr = std::get_if<L>(&Lhs)) {
90+
if (auto *RhsPtr = std::get_if<L>(&Rhs)) {
9191
return *LhsPtr < *RhsPtr;
9292
}
9393
}

0 commit comments

Comments
 (0)