Skip to content

Commit

Permalink
Fix remaining warnings (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer authored Feb 24, 2024
1 parent 0e2e77c commit bd2e685
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/irgenerator/GenControlStructures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ std::any IRGenerator::visitForeachLoop(const ForeachLoopNode *node) {
// Visit idx variable declaration if required
const DeclStmtNode *idxDeclNode = node->idxVarDecl();
const bool hasIdx = idxDeclNode != nullptr;
SymbolTableEntry *idxEntry;
llvm::Value *idxAddress;
SymbolTableEntry *idxEntry = nullptr;
llvm::Value *idxAddress = nullptr;
if (hasIdx) {
visit(idxDeclNode);
// Get address of idx variable
Expand Down Expand Up @@ -172,6 +172,7 @@ std::any IRGenerator::visitForeachLoop(const ForeachLoopNode *node) {
// Store idx to idx var
llvm::Value *idxAddrInPair = insertStructGEP(pairTy, pairPtr, 0, "idx_addr");
LLVMExprResult idxResult = {.ptr = idxAddrInPair};
assert(idxAddress != nullptr && idxEntry != nullptr);
doAssignment(idxAddress, idxEntry, idxResult, SymbolType(TY_LONG), true);
// Store item to item var
llvm::Value *itemAddrInPair = insertStructGEP(pairTy, pairPtr, 1, "item_addr");
Expand Down
3 changes: 1 addition & 2 deletions src/irgenerator/GenImplicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ void IRGenerator::generateTestMain() {
auto fctDefNode = spice_pointer_cast<FctDefBaseNode *>(testFunction->declNode);
assert(fctDefNode->attrs() != nullptr);
const AttrLstNode *attrs = fctDefNode->attrs()->attrLst();
const CompileTimeValue *testValue = attrs->getAttrValueByName(ATTR_TEST);
assert(testValue->boolValue); // The test attribute must be present
assert(attrs->getAttrValueByName(ATTR_TEST)->boolValue); // The test attribute must be present
const CompileTimeValue *testSkipAttr = attrs->getAttrValueByName(ATTR_TEST_SKIP);
const bool skipTest = testSkipAttr && testSkipAttr->boolValue;
const CompileTimeValue *testNameAttr = attrs->getAttrValueByName(ATTR_TEST_NAME);
Expand Down
7 changes: 5 additions & 2 deletions src/irgenerator/GenStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ std::any IRGenerator::visitDeclStmt(const DeclStmtNode *node) {
generateCtorOrDtorCall(varEntry, node->calledCopyCtor, {rhsAddress});
} else {
// Assign rhs to lhs
#ifndef NDEBUG
LLVMExprResult assignResult = doAssignment(varAddress, varEntry, node->assignExpr(), true);
assert(assignResult.entry == varEntry);
#else
doAssignment(varAddress, varEntry, node->assignExpr(), true);
#endif
varAddress = varEntry->getAddress();
varEntry->updateAddress(varAddress);
}
Expand Down Expand Up @@ -111,8 +115,7 @@ std::any IRGenerator::visitCaseConstant(const spice::compiler::CaseConstantNode
return visit(node->constant());

// Get constant for enum item
Scope *enumScope = node->enumItemEntry->scope;
assert(enumScope->type == ScopeType::ENUM);
assert(node->enumItemEntry->scope->type == ScopeType::ENUM);
auto itemNode = spice_pointer_cast<const EnumItemNode *>(node->enumItemEntry->declNode);
llvm::Constant *constant = llvm::ConstantInt::get(builder.getInt32Ty(), itemNode->itemValue);
return constant;
Expand Down
8 changes: 4 additions & 4 deletions src/irgenerator/GenTopLevelDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ std::any IRGenerator::visitGlobalVarDef(const GlobalVarDefNode *node) {
var->setConstant(isConst);

// Set initializer
llvm::Constant *constantValue;
if (node->hasValue) { // Set the constant value as variable initializer
constantValue = std::any_cast<llvm::Constant *>(visit(node->constant()));
auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant()));
var->setInitializer(constantValue);
} else if (cliOptions.buildMode == BuildMode::DEBUG) { // Set the default value as variable initializer
constantValue = getDefaultValueForSymbolType(node->entry->getType());
llvm::Constant *constantValue = getDefaultValueForSymbolType(node->entry->getType());
var->setInitializer(constantValue);
}
var->setInitializer(constantValue);

node->entry->updateAddress(varAddress);

Expand Down
2 changes: 1 addition & 1 deletion src/irgenerator/GenValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ std::any IRGenerator::visitDataType(const DataTypeNode *node) {

llvm::Value *IRGenerator::buildFatFctPtr(Scope *bodyScope, llvm::Type *capturesStructType, llvm::Value *lambda) {
// Create capture struct if required
llvm::Value *capturesPtr;
llvm::Value *capturesPtr = nullptr;
if (capturesStructType != nullptr) {
assert(bodyScope != nullptr);
// If we have a single capture of ptr type, we can directly store it into the fat ptr. Otherwise, we need a stack allocated
Expand Down
2 changes: 1 addition & 1 deletion src/typechecker/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Function *FunctionManager::insertFunction(Scope *insertScope, const Function &ba
assert(!manifestations.empty());

// Save substantiations in declaration node
Function *manifestationPtr;
Function *manifestationPtr = nullptr;
for (const Function &manifestation : manifestations) {
manifestationPtr = insertSubstantiation(insertScope, manifestation, baseFunction.declNode);
assert(manifestationPtr != nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/typechecker/StructManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Struct *StructManager::insertStruct(Scope *insertScope, Struct &spiceStruct, std
Struct *StructManager::insertSubstantiation(Scope *insertScope, Struct &newManifestation, const ASTNode *declNode) {
const std::string signature = newManifestation.getSignature();

#ifndef NDEBUG
// Make sure that the manifestation does not exist already
for (const auto &manifestations : insertScope->structs)
assert(!manifestations.second.contains(signature));
#endif

// Retrieve the matching manifestation list of the scope
assert(insertScope->structs.contains(declNode->codeLoc));
Expand Down
3 changes: 1 addition & 2 deletions src/typechecker/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,8 +2396,7 @@ std::any TypeChecker::visitCustomDataType(CustomDataTypeNode *node) {
return SymbolType(TY_INT);

if (entryType.isOneOf({TY_STRUCT, TY_INTERFACE})) {
const DataTypeNode *dataTypeNode = dynamic_cast<DataTypeNode *>(node->parent->parent);
assert(dataTypeNode != nullptr);
assert(dynamic_cast<DataTypeNode *>(node->parent->parent) != nullptr);

// Collect the concrete template types
bool allTemplateTypesConcrete = true;
Expand Down

0 comments on commit bd2e685

Please sign in to comment.