Skip to content

Commit 49989f4

Browse files
authored
Merge pull request #477 from secure-software-engineering/f-ClangTidyFixPasses22
clang-tidy: Fixes in passes
2 parents 86a1aef + 60e0acb commit 49989f4

8 files changed

Lines changed: 70 additions & 75 deletions

File tree

include/phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ namespace psr {
3434
class GeneralStatistics {
3535
private:
3636
friend class GeneralStatisticsAnalysis;
37-
size_t functions = 0;
38-
size_t globals = 0;
39-
size_t basicblocks = 0;
40-
size_t allocationsites = 0;
41-
size_t callsites = 0;
42-
size_t instructions = 0;
43-
size_t storeInstructions = 0;
44-
size_t loadInstructions = 0;
45-
size_t memIntrinsic = 0;
46-
size_t globalPointers = 0;
47-
std::set<const llvm::Type *> allocatedTypes;
48-
std::set<const llvm::Instruction *> allocaInstructions;
49-
std::set<const llvm::Instruction *> retResInstructions;
37+
size_t Functions = 0;
38+
size_t Globals = 0;
39+
size_t BasicBlocks = 0;
40+
size_t AllocationSites = 0;
41+
size_t CallSites = 0;
42+
size_t Instructions = 0;
43+
size_t StoreInstructions = 0;
44+
size_t LoadInstructions = 0;
45+
size_t MemIntrinsics = 0;
46+
size_t GlobalPointers = 0;
47+
std::set<const llvm::Type *> AllocatedTypes;
48+
std::set<const llvm::Instruction *> AllocaInstructions;
49+
std::set<const llvm::Instruction *> RetResInstructions;
5050

5151
public:
5252
/**
@@ -145,7 +145,7 @@ class GeneralStatisticsAnalysis
145145
/// The pass itself stores the results.
146146
using Result = GeneralStatistics;
147147

148-
explicit GeneralStatisticsAnalysis();
148+
explicit GeneralStatisticsAnalysis() = default;
149149

150150
GeneralStatistics run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
151151
};

include/phasar/PhasarPass/PhasarPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace psr {
2222

2323
class PhasarPass : public llvm::ModulePass {
2424
public:
25-
static char ID;
25+
static inline char ID = 12;
2626

2727
explicit PhasarPass();
2828
PhasarPass(const PhasarPass &) = delete;

include/phasar/PhasarPass/PhasarPrinterPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace psr {
2121

2222
class PhasarPrinterPass : public llvm::ModulePass {
2323
public:
24-
static char ID;
24+
static inline char ID = 12; // NOLINT FIXME: make const when LLVM supports it
2525

2626
explicit PhasarPrinterPass();
2727
PhasarPrinterPass(const PhasarPrinterPass &) = delete;

lib/PhasarLLVM/Passes/ExampleModulePass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ llvm::AnalysisKey ExampleModulePass::Key;
2323
ExampleModulePass::ExampleModulePass() = default;
2424

2525
llvm::PreservedAnalyses
26-
ExampleModulePass::run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM) {
26+
ExampleModulePass::run(llvm::Module & /*M*/,
27+
llvm::ModuleAnalysisManager & /*MAM*/) {
2728
cout << "ExampleModulePass::run()\n";
2829
return llvm::PreservedAnalyses::all();
2930
}

lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,29 @@ using namespace psr;
3535

3636
namespace psr {
3737

38-
llvm::AnalysisKey GeneralStatisticsAnalysis::Key;
39-
40-
GeneralStatisticsAnalysis::GeneralStatisticsAnalysis() = default;
41-
38+
llvm::AnalysisKey GeneralStatisticsAnalysis::Key; // NOLINT
4239
GeneralStatistics
4340
GeneralStatisticsAnalysis::run(llvm::Module &M,
44-
llvm::ModuleAnalysisManager &AM) {
41+
llvm::ModuleAnalysisManager & /*AM*/) {
4542
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
4643
<< "Running GeneralStatisticsAnalysis");
4744
static const std::set<std::string> MemAllocatingFunctions = {
4845
"operator new(unsigned long)", "operator new[](unsigned long)", "malloc",
4946
"calloc", "realloc"};
5047
for (auto &F : M) {
51-
++Stats.functions;
48+
++Stats.Functions;
5249
for (auto &BB : F) {
53-
++Stats.basicblocks;
50+
++Stats.BasicBlocks;
5451
for (auto &I : BB) {
5552
// found one more instruction
56-
++Stats.instructions;
53+
++Stats.Instructions;
5754
// check for alloca instruction for possible types
5855
if (const llvm::AllocaInst *Alloc =
5956
llvm::dyn_cast<llvm::AllocaInst>(&I)) {
60-
Stats.allocatedTypes.insert(Alloc->getAllocatedType());
57+
Stats.AllocatedTypes.insert(Alloc->getAllocatedType());
6158
// do not add allocas from llvm internal functions
62-
Stats.allocaInstructions.insert(&I);
63-
++Stats.allocationsites;
59+
Stats.AllocaInstructions.insert(&I);
60+
++Stats.AllocationSites;
6461
} // check bitcast instructions for possible types
6562
else {
6663
for (auto *User : I.users()) {
@@ -72,30 +69,30 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
7269
}
7370
// check for return or resume instructions
7471
if (llvm::isa<llvm::ReturnInst>(I) || llvm::isa<llvm::ResumeInst>(I)) {
75-
Stats.retResInstructions.insert(&I);
72+
Stats.RetResInstructions.insert(&I);
7673
}
7774
// check for store instructions
7875
if (llvm::isa<llvm::StoreInst>(I)) {
79-
++Stats.storeInstructions;
76+
++Stats.StoreInstructions;
8077
}
8178
// check for load instructions
8279
if (llvm::isa<llvm::LoadInst>(I)) {
83-
++Stats.loadInstructions;
80+
++Stats.LoadInstructions;
8481
}
8582
// check for llvm's memory intrinsics
8683
if (llvm::isa<llvm::MemIntrinsic>(I)) {
87-
++Stats.memIntrinsic;
84+
++Stats.MemIntrinsics;
8885
}
8986
// check for function calls
9087
if (llvm::isa<llvm::CallInst>(I) || llvm::isa<llvm::InvokeInst>(I)) {
91-
++Stats.callsites;
88+
++Stats.CallSites;
9289
const llvm::CallBase *CallSite = llvm::cast<llvm::CallBase>(&I);
9390
if (CallSite->getCalledFunction()) {
9491
if (MemAllocatingFunctions.count(llvm::demangle(
9592
CallSite->getCalledFunction()->getName().str()))) {
9693
// do not add allocas from llvm internal functions
97-
Stats.allocaInstructions.insert(&I);
98-
++Stats.allocationsites;
94+
Stats.AllocaInstructions.insert(&I);
95+
++Stats.AllocationSites;
9996
// check if an instance of a user-defined type is allocated on the
10097
// heap
10198
for (auto *User : I.users()) {
@@ -113,7 +110,7 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
113110
if (CTor->getCalledFunction() &&
114111
getNthFunctionArgument(CTor->getCalledFunction(), 0)
115112
->getType() == Cast->getDestTy()) {
116-
Stats.allocatedTypes.insert(
113+
Stats.AllocatedTypes.insert(
117114
Cast->getDestTy()->getPointerElementType());
118115
}
119116
}
@@ -130,9 +127,9 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
130127
// check for global pointers
131128
for (auto &Global : M.globals()) {
132129
if (Global.getType()->isPointerTy()) {
133-
++Stats.globalPointers;
130+
++Stats.GlobalPointers;
134131
}
135-
++Stats.globals;
132+
++Stats.Globals;
136133
}
137134
// register stuff in PAMM
138135
// For performance reasons (and out of sheer convenience) we simply initialize
@@ -163,29 +160,29 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
163160
<< "GeneralStatisticsAnalysis summary for module: '"
164161
<< M.getName().str() << "'");
165162
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
166-
<< "Instructions : " << Stats.instructions);
163+
<< "Instructions : " << Stats.Instructions);
167164
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
168-
<< "Allocated Types : " << Stats.allocatedTypes.size());
165+
<< "Allocated Types : " << Stats.AllocatedTypes.size());
169166
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
170-
<< "Allocation Sites : " << Stats.allocationsites);
167+
<< "Allocation Sites : " << Stats.AllocationSites);
171168
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
172-
<< "Basic Blocks : " << Stats.basicblocks);
169+
<< "Basic Blocks : " << Stats.BasicBlocks);
173170
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
174-
<< "Calls Sites : " << Stats.callsites);
171+
<< "Calls Sites : " << Stats.CallSites);
175172
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
176-
<< "Functions : " << Stats.functions);
173+
<< "Functions : " << Stats.Functions);
177174
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
178-
<< "Globals : " << Stats.globals);
175+
<< "Globals : " << Stats.Globals);
179176
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
180-
<< "Global Pointer : " << Stats.globalPointers);
177+
<< "Global Pointer : " << Stats.GlobalPointers);
181178
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
182-
<< "Memory Intrinsics : " << Stats.memIntrinsic);
179+
<< "Memory Intrinsics : " << Stats.MemIntrinsics);
183180
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
184-
<< "Store Instructions : " << Stats.storeInstructions);
181+
<< "Store Instructions : " << Stats.StoreInstructions);
185182
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO) << ' ');
186183
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
187-
<< "Allocated Types << " << Stats.allocatedTypes.size());
188-
for (const auto *Type : Stats.allocatedTypes) {
184+
<< "Allocated Types << " << Stats.AllocatedTypes.size());
185+
for (const auto *Type : Stats.AllocatedTypes) {
189186
std::string TypeStr;
190187
llvm::raw_string_ostream Rso(TypeStr);
191188
Type->print(Rso);
@@ -196,38 +193,38 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
196193
return Stats;
197194
}
198195

199-
size_t GeneralStatistics::getAllocationsites() const { return allocationsites; }
196+
size_t GeneralStatistics::getAllocationsites() const { return AllocationSites; }
200197

201-
size_t GeneralStatistics::getFunctioncalls() const { return callsites; }
198+
size_t GeneralStatistics::getFunctioncalls() const { return CallSites; }
202199

203-
size_t GeneralStatistics::getInstructions() const { return instructions; }
200+
size_t GeneralStatistics::getInstructions() const { return Instructions; }
204201

205-
size_t GeneralStatistics::getGlobalPointers() const { return globalPointers; }
202+
size_t GeneralStatistics::getGlobalPointers() const { return GlobalPointers; }
206203

207-
size_t GeneralStatistics::getBasicBlocks() const { return basicblocks; }
204+
size_t GeneralStatistics::getBasicBlocks() const { return BasicBlocks; }
208205

209-
size_t GeneralStatistics::getFunctions() const { return functions; }
206+
size_t GeneralStatistics::getFunctions() const { return Functions; }
210207

211-
size_t GeneralStatistics::getGlobals() const { return globals; }
208+
size_t GeneralStatistics::getGlobals() const { return Globals; }
212209

213-
size_t GeneralStatistics::getMemoryIntrinsics() const { return memIntrinsic; }
210+
size_t GeneralStatistics::getMemoryIntrinsics() const { return MemIntrinsics; }
214211

215212
size_t GeneralStatistics::getStoreInstructions() const {
216-
return storeInstructions;
213+
return StoreInstructions;
217214
}
218215

219216
set<const llvm::Type *> GeneralStatistics::getAllocatedTypes() const {
220-
return allocatedTypes;
217+
return AllocatedTypes;
221218
}
222219

223220
set<const llvm::Instruction *>
224221
GeneralStatistics::getAllocaInstructions() const {
225-
return allocaInstructions;
222+
return AllocaInstructions;
226223
}
227224

228225
set<const llvm::Instruction *>
229226
GeneralStatistics::getRetResInstructions() const {
230-
return retResInstructions;
227+
return RetResInstructions;
231228
}
232229

233230
} // namespace psr

lib/PhasarLLVM/Passes/ValueAnnotationPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ size_t ValueAnnotationPass::UniqueValueId = 0;
4242
ValueAnnotationPass::ValueAnnotationPass() = default;
4343

4444
llvm::PreservedAnalyses
45-
ValueAnnotationPass::run(llvm::Module &M, llvm::ModuleAnalysisManager &AM) {
45+
ValueAnnotationPass::run(llvm::Module &M,
46+
llvm::ModuleAnalysisManager & /*AM*/) {
4647
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
4748
<< "Running ValueAnnotationPass");
4849
auto &Context = M.getContext();

lib/PhasarPass/PhasarPass.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848

4949
namespace psr {
5050

51-
char PhasarPass::ID = 12;
52-
5351
PhasarPass::PhasarPass() : llvm::ModulePass(ID) {}
5452

5553
llvm::StringRef PhasarPass::getPassName() const { return "PhasarPass"; }
@@ -181,7 +179,7 @@ bool PhasarPass::runOnModule(llvm::Module &M) {
181179
return false;
182180
}
183181

184-
bool PhasarPass::doInitialization(llvm::Module &M) {
182+
bool PhasarPass::doInitialization(llvm::Module & /*M*/) {
185183
llvm::outs() << "PhasarPass::doInitialization()\n";
186184
initializeLogger(InitLogger);
187185
// check the user's parameters
@@ -198,7 +196,7 @@ bool PhasarPass::doInitialization(llvm::Module &M) {
198196
return false;
199197
}
200198

201-
bool PhasarPass::doFinalization(llvm::Module &M) {
199+
bool PhasarPass::doFinalization(llvm::Module & /*M*/) {
202200
llvm::outs() << "PhasarPass::doFinalization()\n";
203201
return false;
204202
}
@@ -207,12 +205,12 @@ void PhasarPass::getAnalysisUsage(llvm::AnalysisUsage &AU) const {}
207205

208206
void PhasarPass::releaseMemory() {}
209207

210-
void PhasarPass::print(llvm::raw_ostream &O, const llvm::Module *M) const {
208+
void PhasarPass::print(llvm::raw_ostream &O, const llvm::Module * /*M*/) const {
211209
O << "I am a PhasarPass Analysis Result ;-)\n";
212210
}
213211

214-
static llvm::RegisterPass<PhasarPass> Phasar("phasar", "PhASAR Pass",
215-
false /* Only looks at CFG */,
216-
false /* Analysis Pass */);
212+
static const llvm::RegisterPass<PhasarPass>
213+
Phasar("phasar", "PhASAR Pass", false /* Only looks at CFG */,
214+
false /* Analysis Pass */);
217215

218216
} // namespace psr

lib/PhasarPass/PhasarPrinterPass.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
namespace psr {
1919

20-
char PhasarPrinterPass::ID = 12;
21-
2220
PhasarPrinterPass::PhasarPrinterPass() : llvm::ModulePass(ID) {}
2321

2422
llvm::StringRef PhasarPrinterPass::getPassName() const {
@@ -32,12 +30,12 @@ bool PhasarPrinterPass::runOnModule(llvm::Module &M) {
3230
return false;
3331
}
3432

35-
bool PhasarPrinterPass::doInitialization(llvm::Module &M) {
33+
bool PhasarPrinterPass::doInitialization(llvm::Module & /*M*/) {
3634
llvm::outs() << "PhasarPrinterPass::doInitialization()\n";
3735
return false;
3836
}
3937

40-
bool PhasarPrinterPass::doFinalization(llvm::Module &M) {
38+
bool PhasarPrinterPass::doFinalization(llvm::Module & /*M*/) {
4139
llvm::outs() << "PhasarPrinterPass::doFinalization()\n";
4240
return false;
4341
}

0 commit comments

Comments
 (0)