Skip to content

Commit

Permalink
clang-tidy and its fixes part I
Browse files Browse the repository at this point in the history
  • Loading branch information
pdschubert committed Apr 14, 2020
1 parent c415b7b commit f639c3f
Show file tree
Hide file tree
Showing 99 changed files with 2,346 additions and 2,277 deletions.
39 changes: 38 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
Checks: '-*,modernize-use-override,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming'
Checks: '-*,
clang-diagnostic-*,
llvm-*,
misc-*,
-misc-unused-parameters,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
readability-*,
-readability-else-after*,
-readability-simplify-boolean-expr,
-readability-implicit-bool-cast,
-readability-static-definition-in-anonymous-namespace,
-readability-implicit-bool-conversion,
-readability-magic-numbers,
-readability-identifier-naming,
cppcoreguidelines-*,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-usage,
bugprone-*,
-bugprone-reserved-identifier,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-use-override,
-modernize-use-trailing-return-type,
performance-*,
clang-analyzer-*,
'

CheckOptions:
- key: readability-identifier-naming.ClassCase
Expand All @@ -15,3 +48,7 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: CamelCase
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
value: 1
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class OpenSSLEVPKDFCTXDescription : public TypeStateDescription {
};

static const std::map<std::string, std::set<int>> OpenSSLEVPKDFFuncs;
// delta matrix to implement the state machine's delta function
static const OpenSSLEVPKDFState delta[5][6];
// Delta matrix to implement the state machine's Delta function
static const OpenSSLEVPKDFState Delta[5][6];

// std::map<std::pair<const llvm::Instruction *, const llvm::Value *>, int>
// requiredKDFState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class OpenSSLSecureHeapDescription : public TypeStateDescription {
};

static const std::map<std::string, std::set<int>> OpenSSLSecureHeapFuncs;
// delta matrix to implement the state machine's delta function
static const OpenSSLSecureHeapState delta[5][6];
// Delta matrix to implement the state machine's Delta function
static const OpenSSLSecureHeapState Delta[5][6];

IDESolver<const llvm::Instruction *, SecureHeapFact, const llvm::Function *,
const llvm::StructType *, const llvm::Value *, SecureHeapValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class OpenSSLSecureMemoryDescription : public TypeStateDescription {
};

static const std::map<std::string, std::set<int>> OpenSSLSecureMemoryFuncs;
// delta matrix to implement the state machine's delta function
static const OpenSSLSecureMemoryState delta[6][7];
// Delta matrix to implement the state machine's Delta function
static const OpenSSLSecureMemoryState Delta[6][7];
OpenSSLSecureMemoryToken funcNameToToken(const std::string &F) const;

public:
Expand Down
56 changes: 28 additions & 28 deletions lib/DB/ProjectIRDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ProjectIRDB::ProjectIRDB(const std::vector<std::string> &IRFiles,
ProjectIRDB::ProjectIRDB(const std::vector<llvm::Module *> &Modules,
IRDBOptions Options)
: ProjectIRDB(Options) {
for (auto M : Modules) {
for (auto *M : Modules) {
insertModule(M);
}
if (Options & IRDBOptions::WPA) {
Expand Down Expand Up @@ -244,22 +244,22 @@ llvm::Instruction *ProjectIRDB::getInstruction(std::size_t Id) {

std::size_t ProjectIRDB::getInstructionID(const llvm::Instruction *I) const {
std::size_t Id = 0;
if (auto MD = llvm::cast<llvm::MDString>(
if (auto *MD = llvm::cast<llvm::MDString>(
I->getMetadata(PhasarConfig::MetaDataKind())->getOperand(0))) {
Id = stol(MD->getString().str());
}
return Id;
}

void ProjectIRDB::print() const {
for (auto &[File, Module] : Modules) {
for (const auto &[File, Module] : Modules) {
std::cout << "Module: " << File << std::endl;
llvm::outs() << *Module;
}
}

void ProjectIRDB::emitPreprocessedIR(std::ostream &OS, bool ShortenIR) const {
for (auto &[File, Module] : Modules) {
for (const auto &[File, Module] : Modules) {
OS << "IR module: " << File << '\n';
// print globals
for (auto &Glob : Module->globals()) {
Expand All @@ -271,10 +271,10 @@ void ProjectIRDB::emitPreprocessedIR(std::ostream &OS, bool ShortenIR) const {
OS << '\n';
}
OS << '\n';
for (auto F : getAllFunctions()) {
for (const auto *F : getAllFunctions()) {
if (!F->isDeclaration() && Module->getFunction(F->getName())) {
OS << F->getName().str() << " {\n";
for (auto &BB : *F) {
for (const auto &BB : *F) {
// do not print the label of the first BB
if (BB.getPrevNode()) {
std::string BBLabel;
Expand All @@ -284,7 +284,7 @@ void ProjectIRDB::emitPreprocessedIR(std::ostream &OS, bool ShortenIR) const {
OS << "\n<label " << BBLabel << ">\n";
}
// print all instructions
for (auto &I : BB) {
for (const auto &I : BB) {
OS << " ";
if (ShortenIR) {
OS << llvmIRToShortString(&I);
Expand All @@ -308,8 +308,8 @@ ProjectIRDB::getRetOrResInstructions() const {

const llvm::Function *
ProjectIRDB::getFunctionDefinition(const string &FunctionName) const {
for (auto &[File, Module] : Modules) {
auto F = Module->getFunction(FunctionName);
for (const auto &[File, Module] : Modules) {
auto *F = Module->getFunction(FunctionName);
if (F && !F->isDeclaration()) {
return F;
}
Expand All @@ -319,8 +319,8 @@ ProjectIRDB::getFunctionDefinition(const string &FunctionName) const {

const llvm::Function *
ProjectIRDB::getFunction(const std::string &FunctionName) const {
for (auto &[File, Module] : Modules) {
auto F = Module->getFunction(FunctionName);
for (const auto &[File, Module] : Modules) {
auto *F = Module->getFunction(FunctionName);
if (F) {
return F;
}
Expand All @@ -330,8 +330,8 @@ ProjectIRDB::getFunction(const std::string &FunctionName) const {

const llvm::GlobalVariable *ProjectIRDB::getGlobalVariableDefinition(
const std::string &GlobalVariableName) const {
for (auto &[File, Module] : Modules) {
auto G = Module->getGlobalVariable(GlobalVariableName);
for (const auto &[File, Module] : Modules) {
auto *G = Module->getGlobalVariable(GlobalVariableName);
if (G && !G->isDeclaration()) {
return G;
}
Expand All @@ -342,7 +342,7 @@ const llvm::GlobalVariable *ProjectIRDB::getGlobalVariableDefinition(
llvm::Module *
ProjectIRDB::getModuleDefiningFunction(const std::string &FunctionName) {
for (auto &[File, Module] : Modules) {
auto F = Module->getFunction(FunctionName);
auto *F = Module->getFunction(FunctionName);
if (F && !F->isDeclaration()) {
return Module.get();
}
Expand All @@ -352,8 +352,8 @@ ProjectIRDB::getModuleDefiningFunction(const std::string &FunctionName) {

const llvm::Module *
ProjectIRDB::getModuleDefiningFunction(const std::string &FunctionName) const {
for (auto &[File, Module] : Modules) {
auto F = Module->getFunction(FunctionName);
for (const auto &[File, Module] : Modules) {
auto *F = Module->getFunction(FunctionName);
if (F && !F->isDeclaration()) {
return Module.get();
}
Expand All @@ -374,7 +374,7 @@ std::string ProjectIRDB::valueToPersistedString(const llvm::Value *V) {
llvm::dyn_cast<llvm::GlobalValue>(V)) {
std::cout << "special case: WE ARE AN GLOBAL VARIABLE\n";
std::cout << "all user:\n";
for (auto User : V->users()) {
for (const auto *User : V->users()) {
if (const llvm::Instruction *I =
llvm::dyn_cast<llvm::Instruction>(User)) {
std::cout << I->getFunction()->getName().str() << "\n";
Expand All @@ -386,7 +386,7 @@ std::string ProjectIRDB::valueToPersistedString(const llvm::Value *V) {
// identified by the instruction id and the operand index.
std::cout << "special case: WE ARE AN OPERAND\n";
// We should only have one user in this special case
for (auto User : V->users()) {
for (const auto *User : V->users()) {
if (const llvm::Instruction *I =
llvm::dyn_cast<llvm::Instruction>(User)) {
for (unsigned Idx = 0; Idx < I->getNumOperands(); ++Idx) {
Expand Down Expand Up @@ -422,8 +422,8 @@ const llvm::Value *ProjectIRDB::persistedStringToValue(const std::string &S) {
unsigned OpIdx = stoi(S.substr(J + 3, S.size()));
// std::cout << "FOUND opIdx: " << to_string(opIdx) << "\n";
const llvm::Function *F = getFunctionDefinition(S.substr(0, S.find(".")));
for (auto &BB : *F) {
for (auto &Inst : BB) {
for (const auto &BB : *F) {
for (const auto &Inst : BB) {
if (getMetaDataID(&Inst) == std::to_string(InstID)) {
return Inst.getOperand(OpIdx);
}
Expand All @@ -432,8 +432,8 @@ const llvm::Value *ProjectIRDB::persistedStringToValue(const std::string &S) {
llvm::report_fatal_error("Error: operand not found.");
} else if (S.find(".") != std::string::npos) {
const llvm::Function *F = getFunctionDefinition(S.substr(0, S.find(".")));
for (auto &BB : *F) {
for (auto &Inst : BB) {
for (const auto &BB : *F) {
for (const auto &Inst : BB) {
if (getMetaDataID(&Inst) == S.substr(S.find(".") + 1, S.size())) {
return &Inst;
}
Expand All @@ -453,7 +453,7 @@ std::set<const llvm::Instruction *> ProjectIRDB::getAllocaInstructions() const {

std::set<const llvm::Function *> ProjectIRDB::getAllFunctions() const {
std::set<const llvm::Function *> Functions;
for (auto &[File, Module] : Modules) {
for (const auto &[File, Module] : Modules) {
for (auto &F : *Module) {
Functions.insert(&F);
}
Expand All @@ -476,8 +476,8 @@ set<const llvm::Type *> ProjectIRDB::getAllocatedTypes() const {
std::set<const llvm::StructType *>
ProjectIRDB::getAllocatedStructTypes() const {
std::set<const llvm::StructType *> StructTypes;
for (auto Ty : AllocatedTypes) {
if (auto StructTy = llvm::dyn_cast<llvm::StructType>(Ty)) {
for (const auto *Ty : AllocatedTypes) {
if (const auto *StructTy = llvm::dyn_cast<llvm::StructType>(Ty)) {
StructTypes.insert(StructTy);
}
}
Expand All @@ -488,7 +488,7 @@ set<const llvm::Value *> ProjectIRDB::getAllMemoryLocations() const {
// get all stack and heap alloca instructions
auto AllocaInsts = getAllocaInstructions();
set<const llvm::Value *> AllMemoryLoc;
for (auto AllocaInst : AllocaInsts) {
for (const auto *AllocaInst : AllocaInsts) {
AllMemoryLoc.insert(static_cast<const llvm::Value *>(AllocaInst));
}
set<string> IgnoredGlobalNames = {"llvm.used",
Expand All @@ -499,7 +499,7 @@ set<const llvm::Value *> ProjectIRDB::getAllMemoryLocations() const {
"typeinfo"};
// add global varibales to the memory location set, except the llvm
// intrinsic global variables
for (auto &[File, Module] : Modules) {
for (const auto &[File, Module] : Modules) {
for (auto &GV : Module->globals()) {
if (GV.hasName()) {
string GVName = cxxDemangle(GV.getName().str());
Expand All @@ -522,7 +522,7 @@ bool ProjectIRDB::debugInfoAvailable() const {
}
// During unittests WPAMOD might not be set
else if (Modules.size() >= 1) {
for (auto &[File, Module] : Modules) {
for (const auto &[File, Module] : Modules) {
if (!wasCompiledWithDebugInfo(Module.get())) {
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/PhasarClang/MyMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ void MyMatcher::run(const MatchFinder::MatchResult &Result) {
if (const CXXRecordDecl *CALLER =
Result.Nodes.getNodeAs<CXXRecordDecl>("caller"))
errs() << "CALLER: " << CALLER->getNameAsString() << "\n";
if (auto Caller = Result.Nodes.getNodeAs<clang::FunctionDecl>("caller"))
if (const auto *Caller =
Result.Nodes.getNodeAs<clang::FunctionDecl>("caller"))
errs() << "### Caller:" << Caller->getNameInfo().getAsString() << "\n";
if (auto Callee = Result.Nodes.getNodeAs<clang::FunctionDecl>("callee"))
if (const auto *Callee =
Result.Nodes.getNodeAs<clang::FunctionDecl>("callee"))
errs() << "### Callee:" << Callee->getNameInfo().getAsString() << "\n";
if (auto Call = Result.Nodes.getNodeAs<clang::CallExpr>("call"))
if (const auto *Call = Result.Nodes.getNodeAs<clang::CallExpr>("call"))
errs() << "### with num args: " << Call->getNumArgs() << "\n";
}
//
Expand Down
14 changes: 7 additions & 7 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LLVMBasedBackwardCFG::getSuccsOf(const llvm::Instruction *Stmt) const {
if (Stmt->getPrevNode()) {
Preds.push_back(Stmt->getPrevNode());
}
for (auto PredBlock : llvm::predecessors(Stmt->getParent())) {
for (const auto *PredBlock : llvm::predecessors(Stmt->getParent())) {
Preds.push_back(&PredBlock->back());
}
return Preds;
Expand All @@ -64,10 +64,10 @@ LLVMBasedBackwardCFG::getSuccsOf(const llvm::Instruction *Stmt) const {
std::vector<std::pair<const llvm::Instruction *, const llvm::Instruction *>>
LLVMBasedBackwardCFG::getAllControlFlowEdges(const llvm::Function *Fun) const {
vector<pair<const llvm::Instruction *, const llvm::Instruction *>> Edges;
for (auto &BB : *Fun) {
for (auto &I : BB) {
for (const auto &BB : *Fun) {
for (const auto &I : BB) {
auto Successors = getSuccsOf(&I);
for (auto Successor : Successors) {
for (const auto *Successor : Successors) {
Edges.insert(Edges.begin(), make_pair(Successor, &I));
}
}
Expand All @@ -78,8 +78,8 @@ LLVMBasedBackwardCFG::getAllControlFlowEdges(const llvm::Function *Fun) const {
std::vector<const llvm::Instruction *>
LLVMBasedBackwardCFG::getAllInstructionsOf(const llvm::Function *Fun) const {
vector<const llvm::Instruction *> Instructions;
for (auto &BB : *Fun) {
for (auto &I : BB) {
for (const auto &BB : *Fun) {
for (const auto &I : BB) {
Instructions.insert(Instructions.begin(), &I);
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ bool LLVMBasedBackwardCFG::isFallThroughSuccessor(
bool LLVMBasedBackwardCFG::isBranchTarget(const llvm::Instruction *Stmt,
const llvm::Instruction *Succ) const {
if (const llvm::BranchInst *B = llvm::dyn_cast<llvm::BranchInst>(Succ)) {
for (auto BB : B->successors()) {
for (const auto *BB : B->successors()) {
if (Stmt == &(BB->front())) {
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ std::set<const llvm::Instruction *>
LLVMBasedBackwardsICFG::getReturnSitesOfCallAt(
const llvm::Instruction *N) const {
std::set<const llvm::Instruction *> ReturnSites;
if (auto Call = llvm::dyn_cast<llvm::CallInst>(N)) {
if (auto Prev = Call->getPrevNode())
if (const auto *Call = llvm::dyn_cast<llvm::CallInst>(N)) {
if (const auto *Prev = Call->getPrevNode())
ReturnSites.insert(Prev);
}
if (auto Invoke = llvm::dyn_cast<llvm::InvokeInst>(N)) {
if (const auto *Invoke = llvm::dyn_cast<llvm::InvokeInst>(N)) {
ReturnSites.insert(&Invoke->getNormalDest()->back());
ReturnSites.insert(&Invoke->getUnwindDest()->back());
}
Expand Down
Loading

0 comments on commit f639c3f

Please sign in to comment.