Skip to content

Commit

Permalink
FactGenerator: Enable more clang-tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Nov 1, 2022
1 parent 18242b8 commit 69a00fe
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 80 deletions.
25 changes: 16 additions & 9 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# -*- yaml -*-
# The following are disabled not because they are undesirable, but because they
# are present in pre-existing code:
#
# -readability-convert-member-functions-to-static,
# -readability-inconsistent-declaration-parameter-name,
# -readability-magic-numbers,
# -readability-suspicious-call-argument,
---

Checks: >
-*,
modernize-*,
performance-*,
readability-const-return-type,
readability-delete-null-pointer,
readability-else-after-return,
readability-non-const-parameter,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-string-compare
readability-*,
misc-static-assert,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers,
-readability-suspicious-call-argument,
WarningsAsErrors: '*'


7 changes: 4 additions & 3 deletions FactGenerator/src/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto FactGenerator::writeConstant(const llvm::Constant &c)

// Record containing function
const llvm::Function *containingFunction = functionContext();
if (containingFunction) {
if (containingFunction != nullptr) {
const std::string funcname = "@" + containingFunction->getName().str();
writeFact(pred::constant::in_func, id, funcname);
}
Expand Down Expand Up @@ -137,10 +137,11 @@ void FactGenerator::writeConstantExpr(

refmode_t index_ref = writeConstant(*c);

if (i > 0)
if (i > 0) {
writeFact(pred::gep_constant_expr::index, refmode, i - 1, index_ref);
else
} else {
writeFact(pred::gep_constant_expr::base, refmode, index_ref);
}
}

writeFact(pred::gep_constant_expr::nindices, refmode, nOperands - 1);
Expand Down
5 changes: 3 additions & 2 deletions FactGenerator/src/ContextManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class ContextManager {

/// Record that a local context has been exited.
void popContext() {
if (contexts.back().isFunction) iFunctionCtx = -1;
if (contexts.back().isFunction) { iFunctionCtx = -1;
}

contexts.pop_back();
}
Expand All @@ -104,7 +105,7 @@ class ContextManager {
return contexts.rend();
}

inline auto instrCount() -> unsigned { return instrIndex; }
[[nodiscard]] inline auto instrCount() const -> unsigned { return instrIndex; }
inline auto constantCount() -> unsigned { return constantIndex++; }
[[nodiscard]] inline auto module() const -> const llvm::Module& {
return mod;
Expand Down
4 changes: 3 additions & 1 deletion FactGenerator/src/FactGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ auto FactGenerator::processModule(
}

// Record successor instruction
if (prev_instr) writeFact(pred::instr::successor, prev_iref, iref);
if (prev_instr != nullptr) {
writeFact(pred::instr::successor, prev_iref, iref);
}

// Store the refmode of this instruction for next iteration
prev_iref = iref;
Expand Down
4 changes: 3 additions & 1 deletion FactGenerator/src/FactWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ auto FactWriter::getWriter(const pred_t& pred) -> csv_writer* {
map<string, csv_writer*>::iterator it = writers.find(key);

// Return existing writer
if (it != writers.end()) return it->second;
if (it != writers.end()) {
return it->second;
}

// Get filesystem path to CSV file
path file = getPath(pred);
Expand Down
14 changes: 10 additions & 4 deletions FactGenerator/src/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ void FactGenerator::writeFunction(
writeFact(pred::func::signature, funcref, demangle(func.getName().data()));

// Record function linkage, visibility, alignment, and GC
if (!linkage.empty()) writeFact(pred::func::linkage, funcref, linkage);
if (!linkage.empty()) {
writeFact(pred::func::linkage, funcref, linkage);
}

if (!visibility.empty())
if (!visibility.empty()) {
writeFact(pred::func::visibility, funcref, visibility);
}

if (func.getAlignment())
if (func.getAlignment() != 0U) {
writeFact(pred::func::alignment, funcref, func.getAlignment());
}

if (func.hasGC()) writeFact(pred::func::gc, funcref, func.getGC());
if (func.hasGC()) {
writeFact(pred::func::gc, funcref, func.getGC());
}

if (func.hasPersonalityFn()) {
llvm::Constant *pers_fn = func.getPersonalityFn();
Expand Down
28 changes: 19 additions & 9 deletions FactGenerator/src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ void FactGenerator::writeGlobalAlias(
refmode_t aliasType = recordType(ga.getType());

// Record visibility
if (!visibility.empty())
if (!visibility.empty()) {
writeFact(pred::alias::visibility, aliasId, visibility);
}

// Record linkage
if (!linkage.empty()) writeFact(pred::alias::linkage, aliasId, linkage);
if (!linkage.empty()) {
writeFact(pred::alias::linkage, aliasId, linkage);
}

// Record type
writeFact(pred::alias::type, aliasId, aliasType);

// Record aliasee
if (Aliasee) {
if (Aliasee != nullptr) {
// Record aliasee constant and generate refmode for it
refmode_t aliasee = writeConstant(*Aliasee);

Expand Down Expand Up @@ -78,23 +81,29 @@ void FactGenerator::writeGlobalVar(
pred::global_var::demangled_name, id, demangle(gv.getName().data()));

// Record external linkage
if (!gv.hasInitializer() && gv.hasExternalLinkage())
if (!gv.hasInitializer() && gv.hasExternalLinkage()) {
writeFact(pred::global_var::linkage, id, "external");
}

// Record linkage
if (!linkage.empty()) writeFact(pred::global_var::linkage, id, linkage);
if (!linkage.empty()) {
writeFact(pred::global_var::linkage, id, linkage);
}

// Record visibility
if (!visibility.empty())
if (!visibility.empty()) {
writeFact(pred::global_var::visibility, id, visibility);
}

// Record thread local mode
if (!thrLocMode.empty())
if (!thrLocMode.empty()) {
writeFact(pred::global_var::threadlocal_mode, id, thrLocMode);
}

// TODO: in lb schema - AddressSpace & hasUnnamedAddr properties
if (gv.isExternallyInitialized())
if (gv.isExternallyInitialized()) {
writeFact(pred::global_var::flag, id, "externally_initialized");
}

// Record flags and type
const char* flag = gv.isConstant() ? "constant" : "global";
Expand Down Expand Up @@ -122,6 +131,7 @@ void FactGenerator::writeGlobalVar(
}

// Record alignment
if (gv.getAlignment())
if (gv.getAlignment() != 0U) {
writeFact(pred::global_var::aligned_to, id, gv.getAlignment());
}
}
Loading

0 comments on commit 69a00fe

Please sign in to comment.