[midend]修复内存泄漏和Heap-buffer-overflow问题(getexternalfunction中及其隐秘的错误),修复全局常量标量访问的错误
This commit is contained in:
@@ -1164,17 +1164,20 @@ void Module::cleanup() {
|
||||
}
|
||||
|
||||
void Function::cleanup() {
|
||||
// 清理所有基本块中的使用关系
|
||||
// 首先清理所有基本块中的使用关系
|
||||
for (auto& block : blocks) {
|
||||
if (block) {
|
||||
block->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
// 清理参数列表中的使用关系
|
||||
// 然后安全地清理参数列表中的使用关系
|
||||
for (auto arg : arguments) {
|
||||
if (arg) {
|
||||
// 清理参数的所有使用关系
|
||||
arg->cleanup();
|
||||
// 现在安全地删除参数对象
|
||||
delete arg;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1185,14 +1188,7 @@ void Function::cleanup() {
|
||||
}
|
||||
|
||||
void BasicBlock::cleanup() {
|
||||
// 清理所有指令中的使用关系
|
||||
for (auto& inst : instructions) {
|
||||
if (inst) {
|
||||
inst->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
// 清理指令列表
|
||||
// 直接清理指令列表,让析构函数自然处理
|
||||
instructions.clear();
|
||||
|
||||
// 清理前驱后继关系
|
||||
@@ -1201,14 +1197,8 @@ void BasicBlock::cleanup() {
|
||||
}
|
||||
|
||||
void User::cleanup() {
|
||||
// 清理所有操作数的使用关系
|
||||
for (auto& operand : operands) {
|
||||
if (operand && operand->getValue()) {
|
||||
operand->getValue()->removeUse(operand);
|
||||
}
|
||||
}
|
||||
|
||||
// 清理操作数列表
|
||||
// 简单清理:让shared_ptr的析构函数自动处理Use关系
|
||||
// 这样避免了手动管理可能已经被释放的Value对象
|
||||
operands.clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user