Var without initializer

This commit is contained in:
Rafał Grodziński
2025-08-08 13:11:06 +09:00
parent e4c956cdd6
commit 885094eef6
4 changed files with 26 additions and 14 deletions

View File

@@ -203,14 +203,19 @@ void ModuleBuilder::buildVarDeclaration(shared_ptr<StatementVariable> statement)
if (!setAlloca(statement->getName(), alloca))
return;
} else {
llvm::Value *value = valueForExpression(statement->getExpression());
if (value == nullptr)
return;
llvm::AllocaInst *alloca = builder->CreateAlloca(typeForValueType(statement->getValueType(), 0), nullptr, statement->getName());
if (!setAlloca(statement->getName(), alloca))
return;
builder->CreateStore(value, alloca);
// set initial value
if (statement->getExpression() != nullptr) {
llvm::Value *value = nullptr;
value = valueForExpression(statement->getExpression());
if (value == nullptr)
return;
builder->CreateStore(value, alloca);
}
}
}