[midend]修复函数参数alloca指令创建错误导致的段错误,修复irprint对argument的识别

This commit is contained in:
rain2133
2025-07-26 13:02:24 +08:00
parent 4b181261ce
commit a231267fc5
2 changed files with 3 additions and 1 deletions

View File

@ -408,7 +408,7 @@ std::any SysYIRGenerator::visitFuncDef(SysYParser::FuncDefContext *ctx){
auto funcArgs = function->getArguments();
std::vector<AllocaInst *> allocas;
for (int i = 0; i < paramActualTypes.size(); ++i) {
AllocaInst *alloca = builder.createAllocaInst(paramActualTypes[i], {}, paramNames[i]);
AllocaInst *alloca = builder.createAllocaInst(Type::getPointerType(paramActualTypes[i]), {}, paramNames[i]);
allocas.push_back(alloca);
module->addVariable(paramNames[i], alloca);
}

View File

@ -72,6 +72,8 @@ std::string SysYPrinter::getValueName(Value *value) {
return std::to_string(constVal->getInt());
} else if (auto constVar = dynamic_cast<ConstantVariable*>(value)) {
return constVar->getName(); // 假设ConstantVariable有自己的名字或通过getByIndices获取值
} else if (auto argVar = dynamic_cast<Argument*>(value)) {
return "%" + argVar->getName(); // 假设ArgumentVariable有自己的名字
}
assert(false && "Unknown value type or unable to get value name");
return "";