diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 38f23d2..106570b 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -595,10 +595,21 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { identAlloca = dynamic_pointer_cast(tmpIdent); scope.push(node.name, identAlloca); auto varInit = constArrayInit.get(); + std::cout << arraySize << std::endl; + Ptr tmpZero; + if (varType->is_integer_type()) { + tmpZero = CONST_INT(0); + } else { + tmpZero = CONST_FLOAT(0.0); + } for (int i = 0u; i < arraySize; i++) { auto index = CONST_INT(i); auto ptr = builder->create_gep(identAlloca, {CONST_INT(0), index}); - builder->create_store((*varInit)[i], ptr); + if ((*varInit)[i] == nullptr) { + builder->create_store(tmpZero, ptr); + } else { + builder->create_store((*varInit)[i], ptr); + } } } }