Skip to content

Commit 332b253

Browse files
committed
SIL: fix vtable cache updating in SILVTable::replaceEntries
We first have to remove _all_ old entries from the cache, then add the new entries. Otherwise we'll wrongly remove an existing entry from the cache again if a previous entry was deleted from the vtable.
1 parent 7eedc18 commit 332b253

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/SIL/IR/SILVTable.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ void SILVTable::updateVTableCache(const Entry &entry) {
7878
void SILVTable::replaceEntries(ArrayRef<Entry> newEntries) {
7979
auto entries = getMutableEntries();
8080
ASSERT(newEntries.size() <= entries.size());
81-
for (unsigned i = 0; i < entries.size(); ++i) {
82-
entries[i].getImplementation()->decrementRefCount();
83-
if (i < newEntries.size()) {
84-
entries[i] = newEntries[i];
85-
entries[i].getImplementation()->incrementRefCount();
86-
updateVTableCache(entries[i]);
87-
} else {
88-
removeFromVTableCache(entries[i]);
89-
}
81+
for (Entry &entry : getMutableEntries()) {
82+
entry.getImplementation()->decrementRefCount();
83+
removeFromVTableCache(entry);
84+
}
85+
for (unsigned i = 0; i < newEntries.size(); ++i) {
86+
entries[i] = newEntries[i];
87+
entries[i].getImplementation()->incrementRefCount();
88+
updateVTableCache(entries[i]);
9089
}
9190
NumEntries = newEntries.size();
9291
}

0 commit comments

Comments
 (0)