[midend]修复replaceAllUsesWith中由于setOperand 间接调用 removeUse 或 addUse导致的迭代器失效问题

This commit is contained in:
rain2133
2025-08-04 00:59:39 +08:00
parent 446a6a6fcb
commit f24cc7ec88
2 changed files with 38 additions and 6 deletions

View File

@ -232,7 +232,7 @@ class Value {
void replaceAllUsesWith(Value *value); ///< 将原来使用该value的使用者全变为使用给定参数value并修改相应use关系
void removeUse(const std::shared_ptr<Use> &use) {
assert(use != nullptr && "Use cannot be null");
assert(use->getValue() != this && "Use does not belong to this Value");
assert(use->getValue() == this && "Use being removed does NOT point to this Value!");
auto it = std::find(uses.begin(), uses.end(), use);
assert(it != uses.end() && "Use not found in Value's uses");
uses.remove(use);