Skip to content

Commit

Permalink
Fix -cppcoreguidelines-init-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Jan 10, 2024
1 parent 1bc5250 commit 65c33e3
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 85 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Checks:
cppcoreguidelines-*
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-avoid-non-const-global-variables
-cppcoreguidelines-init-variables
-cppcoreguidelines-narrowing-conversions
-cppcoreguidelines-no-malloc
-cppcoreguidelines-owning-memory
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void bind_runtime(py::module_ &m) {
.def(
"serialize",
[](block *term, bool emit_size) {
char *data;
size_t size;
char *data = nullptr;
size_t size = 0;
serializeConfiguration(term, nullptr, &data, &size, emit_size);
return py::bytes(std::string(data, data + size));
},
Expand Down
1 change: 1 addition & 0 deletions include/kllvm/parser/KOREScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class token {
ID,
STRING,
TOKEN_EOF,
INVALID,
};

class KOREScanner {
Expand Down
2 changes: 1 addition & 1 deletion lib/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ std::string KORECompositeSort::getHook(KOREDefinition *definition) {
}

ValueType KORECompositeSort::getCategory(std::string const &name) {
SortCategory category;
SortCategory category = SortCategory::Uncomputed;
uint64_t bits = 0;
if (name == "MAP.Map")
category = SortCategory::Map;
Expand Down
6 changes: 3 additions & 3 deletions lib/codegen/CreateStaticTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ llvm::Constant *CreateStaticTerm::notInjectionCase(

int idx = 2;
for (auto &child : constructor->getArguments()) {
llvm::Constant *ChildValue;
llvm::Constant *ChildValue = nullptr;
if (idx++ == 2 && val != nullptr) {
ChildValue = val;
} else {
Expand Down Expand Up @@ -202,7 +202,7 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) {
Module->getContext(), FLOAT_WRAPPER_STRUCT));
auto *globalVar = llvm::dyn_cast<llvm::GlobalVariable>(global);
if (!globalVar->hasInitializer()) {
size_t prec, exp;
size_t prec = 0, exp = 0;
const char last = contents.back();
if (last == 'f' || last == 'F') {
prec = 24;
Expand All @@ -223,7 +223,7 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) {
}
mpfr_t value;
mpfr_init2(value, prec);
int retValue;
int retValue = 0;
if (contents == "+Infinity" || contents == "-Infinity"
|| contents == "Infinity") {
retValue = mpfr_set_str(value, contents.c_str(), 10, MPFR_RNDN);
Expand Down
10 changes: 5 additions & 5 deletions lib/codegen/CreateTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ llvm::Value *CreateTerm::createHook(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), nwords * 8),
CurrentBlock, "koreAllocAlwaysGC");
if (nwords == 1) {
llvm::Value *Word;
llvm::Value *Word = nullptr;
if (cat.bits == 64) {
Word = mint;
} else {
Expand Down Expand Up @@ -519,7 +519,7 @@ llvm::Value *CreateTerm::createHook(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), nwords * 8),
CurrentBlock, "koreAllocAlwaysGC");
if (nwords == 1) {
llvm::Value *Word;
llvm::Value *Word = nullptr;
if (cat.bits == 64) {
Word = mint;
} else {
Expand Down Expand Up @@ -718,13 +718,13 @@ llvm::Value *CreateTerm::createFunctionCall(
case SortCategory::Set: collection = true; break;
default: sret = false; break;
}
llvm::Value *AllocSret;
llvm::Value *AllocSret = nullptr;
types.reserve(args.size());
for (auto arg : args) {
types.push_back(arg->getType());
}
std::vector<llvm::Value *> realArgs = args;
llvm::Type *sretType;
llvm::Type *sretType = nullptr;
if (sret) {
// we don't use alloca here because the tail call optimization pass for llvm
// doesn't handle correctly functions with alloca
Expand Down Expand Up @@ -770,7 +770,7 @@ llvm::Value *CreateTerm::notInjectionCase(
int idx = 2;
std::vector<llvm::Value *> children;
for (auto &child : constructor->getArguments()) {
llvm::Value *ChildValue;
llvm::Value *ChildValue = nullptr;
if (idx == 2 && val != nullptr) {
ChildValue = val;
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ llvm::DIType *getDebugType(ValueType type, std::string const &typeName) {
if (!Dbg)
return nullptr;
static std::map<std::string, llvm::DIType *> types;
llvm::DIType *map, *rangemap, *list, *set, *integer, *floating, *buffer,
*boolean, *mint, *symbol;
llvm::DIType *map = nullptr, *rangemap = nullptr, *list = nullptr, *set = nullptr, *integer = nullptr, *floating = nullptr, *buffer = nullptr,
*boolean = nullptr, *mint = nullptr, *symbol = nullptr;
if (types[typeName]) {
return types[typeName];
}
Expand Down
30 changes: 15 additions & 15 deletions lib/codegen/Decision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void SwitchNode::codegen(Decision *d) {
bool isInt = false;
for (auto &_case : cases) {
auto child = _case.getChild();
llvm::BasicBlock *CaseBlock;
llvm::BasicBlock *CaseBlock = nullptr;
if (child == FailNode::get()) {
CaseBlock = d->FailureBlock;
} else {
Expand Down Expand Up @@ -188,7 +188,7 @@ void SwitchNode::codegen(Decision *d) {
val = cmp;
isInt = true;
}
llvm::Value *failSort, *failPattern;
llvm::Value *failSort = nullptr, *failPattern = nullptr;
if (d->FailPattern) {
auto failReason = getFailPattern(caseData, isInt, d->FailureBlock);
failSort = d->stringLiteral(failReason.first);
Expand Down Expand Up @@ -241,7 +241,7 @@ void SwitchNode::codegen(Decision *d) {
KORESymbolDeclaration *symbolDecl
= d->Definition->getSymbolDeclarations().at(
_case.getConstructor()->getName());
llvm::Instruction *Renamed;
llvm::Instruction *Renamed = nullptr;
for (auto const &binding : _case.getBindings()) {
llvm::Value *ChildPtr = llvm::GetElementPtrInst::CreateInBounds(
BlockType, Cast,
Expand All @@ -250,7 +250,7 @@ void SwitchNode::codegen(Decision *d) {
llvm::Type::getInt32Ty(d->Ctx), offset + 2)},
"", d->CurrentBlock);

llvm::Value *Child;
llvm::Value *Child = nullptr;
auto cat = dynamic_cast<KORECompositeSort *>(
_case.getConstructor()->getArguments()[offset].get())
->getCategory(d->Definition);
Expand Down Expand Up @@ -413,7 +413,7 @@ void FunctionNode::codegen(Decision *d) {
std::vector<llvm::Value *> args;
llvm::StringMap<llvm::Value *> finalSubst;
for (auto [arg, cat] : bindings) {
llvm::Value *val;
llvm::Value *val = nullptr;
if (arg.first.find_first_not_of("-0123456789") == std::string::npos) {
val = llvm::ConstantInt::get(
llvm::Type::getInt64Ty(d->Ctx), std::stoi(arg.first));
Expand Down Expand Up @@ -770,8 +770,8 @@ void makeEvalOrAnywhereFunction(
llvm::BasicBlock *fail
= llvm::BasicBlock::Create(module->getContext(), "fail", matchFunc);

llvm::AllocaInst *choiceBuffer, *choiceDepth;
llvm::IndirectBrInst *jump;
llvm::AllocaInst *choiceBuffer = nullptr, *choiceDepth = nullptr;
llvm::IndirectBrInst *jump = nullptr;
initChoiceBuffer(
dt, module, block, stuck, fail, &choiceBuffer, &choiceDepth, &jump);

Expand All @@ -798,7 +798,7 @@ void abortWhenStuck(
auto &Ctx = Module->getContext();
symbol = d->getAllSymbols().at(ast_to_string(*symbol));
auto BlockType = getBlockType(Module, d, symbol);
llvm::Value *Ptr;
llvm::Value *Ptr = nullptr;
auto BlockPtr = llvm::PointerType::getUnqual(
llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT));
if (symbol->getArguments().empty()) {
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void makeStepFunction(
auto blockType = getValueType({SortCategory::Symbol, 0}, module);
auto debugType
= getDebugType({SortCategory::Symbol, 0}, "SortGeneratedTopCell{}");
llvm::FunctionType *funcType;
llvm::FunctionType *funcType = nullptr;
std::string name;
if (search) {
name = "stepAll";
Expand Down Expand Up @@ -1086,8 +1086,8 @@ void makeStepFunction(
llvm::BasicBlock *fail
= llvm::BasicBlock::Create(module->getContext(), "fail", matchFunc);

llvm::AllocaInst *choiceBuffer, *choiceDepth;
llvm::IndirectBrInst *jump;
llvm::AllocaInst *choiceBuffer = nullptr, *choiceDepth = nullptr;
llvm::IndirectBrInst *jump = nullptr;

initChoiceBuffer(
dt, module, block, pre_stuck, fail, &choiceBuffer, &choiceDepth, &jump);
Expand Down Expand Up @@ -1204,8 +1204,8 @@ void makeMatchReasonFunction(
{FailSubject, FailPattern, FailSort}, "", fail);
setDebugLoc(call);

llvm::AllocaInst *choiceBuffer, *choiceDepth;
llvm::IndirectBrInst *jump;
llvm::AllocaInst *choiceBuffer = nullptr, *choiceDepth = nullptr;
llvm::IndirectBrInst *jump = nullptr;
initChoiceBuffer(
dt, module, block, pre_stuck, fail, &choiceBuffer, &choiceDepth, &jump);

Expand Down Expand Up @@ -1299,8 +1299,8 @@ void makeStepFunction(
llvm::BasicBlock *fail
= llvm::BasicBlock::Create(module->getContext(), "fail", matchFunc);

llvm::AllocaInst *choiceBuffer, *choiceDepth;
llvm::IndirectBrInst *jump;
llvm::AllocaInst *choiceBuffer = nullptr, *choiceDepth = nullptr;
llvm::IndirectBrInst *jump = nullptr;
initChoiceBuffer(
res.dt, module, block, pre_stuck, fail, &choiceBuffer, &choiceDepth,
&jump);
Expand Down
6 changes: 3 additions & 3 deletions lib/codegen/DecisionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DTPreprocessor {

public:
yaml_node_t *get(yaml_node_t *node, std::string const &name) {
yaml_node_pair_t *entry;
yaml_node_pair_t *entry = nullptr;
for (entry = node->data.mapping.pairs.start;
entry < node->data.mapping.pairs.top; ++entry) {
yaml_node_t *key = yaml_document_get_node(doc, entry->key);
Expand All @@ -88,7 +88,7 @@ class DTPreprocessor {

std::vector<std::string> vec(yaml_node_t *node) {
std::vector<std::string> result;
yaml_node_item_t *entry;
yaml_node_item_t *entry = nullptr;
for (entry = node->data.sequence.items.start;
entry < node->data.sequence.items.top; ++entry) {
result.push_back(str(yaml_document_get_node(doc, *entry)));
Expand Down Expand Up @@ -248,7 +248,7 @@ class DTPreprocessor {
iter < list->data.sequence.items.top; ++iter) {
auto _case = yaml_document_get_node(doc, *iter);
std::vector<std::pair<std::string, llvm::Type *>> bindings;
KORESymbol *symbol;
KORESymbol *symbol = nullptr;
if (kind == SwitchLiteral || kind == CheckNull) {
symbol = dv;
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/codegen/EmitConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static std::pair<llvm::Value *, llvm::BasicBlock *> getEval(
}
CreateTerm creator(subst, def, CaseBlock, mod, false);
llvm::Value *result = creator(pattern.get()).first;
llvm::Value *retval;
llvm::Value *retval = nullptr;
ValueType cat = dynamic_cast<KORECompositeSort *>(symbol->getSort().get())
->getCategory(def);
switch (cat.cat) {
Expand Down Expand Up @@ -883,7 +883,7 @@ static void visitCollection(
auto indices = std::vector<llvm::Constant *>{zero, zero};
auto sortDecl
= definition->getSortDeclarations().at(compositeSort->getName());
llvm::Constant *concatPtr;
llvm::Constant *concatPtr = nullptr;
if (sortDecl->getAttributes().count("concat")) {
auto concat = (KORECompositePattern *)sortDecl->getAttributes()
.at("concat")
Expand Down Expand Up @@ -1033,7 +1033,7 @@ static void getVisitor(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), nwords * 8),
CaseBlock, "koreAllocAlwaysGC");
if (nwords == 1) {
llvm::Value *Word;
llvm::Value *Word = nullptr;
if (cat.bits == 64) {
Word = mint;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/KOREParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static std::string str(token tok) {

std::string KOREParser::consume(token next) {
std::string data;
token actual;
auto actual = token::INVALID;
if (buffer.tok == token::EMPTY) {
actual = scanner.yylex(&data, &loc);
} else {
Expand Down
2 changes: 1 addition & 1 deletion runtime/alloc/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void *megabyte_malloc() {
}

static void freshBlock(struct arena *Arena) {
char *nextBlock;
char *nextBlock = nullptr;
if (Arena->block_start == nullptr) {
nextBlock = (char *)megabyte_malloc();
Arena->first_block = nextBlock;
Expand Down
2 changes: 1 addition & 1 deletion runtime/arithmetic/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ size_t *hook_MINT_export(mpz_t in, uint64_t bits) {
auto *allocptr = (size_t *)koreAllocAlwaysGC(allocsize);
memset(allocptr, 0, allocsize);
size_t *exportptr = nwords > count ? allocptr + nwords - count : allocptr;
size_t actualcount;
size_t actualcount = 0;
mpz_export(exportptr, &actualcount, 1, sizeof(size_t), 0, 0, twos);
assert(count == actualcount);
if (count == 0)
Expand Down
14 changes: 7 additions & 7 deletions runtime/collect/collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void migrate(block **blockPtr) {
size_t lenInBytes = get_size(hdr, layout);
auto **forwardingAddress = (block **)(currBlock + 1);
if (!hasForwardingAddress) {
block *newBlock;
block *newBlock = nullptr;
if (shouldPromote || (isInOldGen && collect_old)) {
newBlock = (block *)koreAllocOld(lenInBytes);
} else {
Expand Down Expand Up @@ -93,8 +93,8 @@ static void migrate_string_buffer(stringbuffer **bufferPtr) {
const uint64_t cap = len(buffer->contents);
initialize_migrate();
if (!hasForwardingAddress) {
stringbuffer *newBuffer;
string *newContents;
stringbuffer *newBuffer = nullptr;
string *newContents = nullptr;
if (shouldPromote || (isInOldGen && collect_old)) {
newBuffer = (stringbuffer *)koreAllocOld(sizeof(stringbuffer));
newContents = (string *)koreAllocTokenOld(sizeof(string) + cap);
Expand All @@ -121,8 +121,8 @@ static void migrate_mpz(mpz_ptr *mpzPtr) {
const uint64_t hdr = intgr->h.hdr;
initialize_migrate();
if (!hasForwardingAddress) {
mpz_hdr *newIntgr;
string *newLimbs;
mpz_hdr *newIntgr = nullptr;
string *newLimbs = nullptr;
bool hasLimbs = intgr->i->_mp_alloc > 0;
#ifdef GC_DBG
numBytesLiveAtCollection[oldAge] += sizeof(mpz_hdr);
Expand Down Expand Up @@ -168,8 +168,8 @@ static void migrate_floating(floating **floatingPtr) {
const uint64_t hdr = flt->h.hdr;
initialize_migrate();
if (!hasForwardingAddress) {
floating_hdr *newFlt;
string *newLimbs;
floating_hdr *newFlt = nullptr;
string *newLimbs = nullptr;
string *limbs = struct_base(string, data, flt->f.f->_mpfr_d - 1);
size_t lenLimbs = len(limbs);

Expand Down
2 changes: 1 addition & 1 deletion runtime/collect/migrate_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void migrate_collection_node(void **nodePtr) {
initialize_migrate();
size_t lenInBytes = get_size(hdr, 0);
if (!hasForwardingAddress) {
string *newBlock;
string *newBlock = nullptr;
if (shouldPromote || (isInOldGen && collect_old)) {
newBlock = (string *)koreAllocOld(lenInBytes);
} else {
Expand Down
Loading

0 comments on commit 65c33e3

Please sign in to comment.