PIC: Fix a bug in the code that collects subclasses. We want to collect indirect subclasses as well as direct sub classes.

Swift SVN r20745
This commit is contained in:
Nadav Rotem
2014-07-30 08:45:38 +00:00
parent 230547f71a
commit 8d3c54840d
2 changed files with 16 additions and 8 deletions

View File

@@ -37,17 +37,20 @@ void ClassHierarchyAnalysis::collectSubClasses(ClassDecl *C,
std::vector<ClassDecl*> &Sub) {
// TODO: Cache this search.
assert(Sub.empty() && "Incoming list is not empty");
SmallVector<ClassDecl*, 4> Path;
for (auto &VT : M->getVTableList()) {
ClassDecl *CD = VT.getClass();
// Ignore classes that are at the top of the class hierarchy:
if (!CD->hasSuperclass())
continue;
// Add the superclass to the list of inherited classes.
ClassDecl *Super = CD->getSuperclass()->getClassOrBoundGenericClass();
if (Super == C) {
Sub.push_back(CD);
while (CD->hasSuperclass()) {
Path.push_back(CD);
// Add the superclass to the list of inherited classes.
ClassDecl *Super = CD->getSuperclass()->getClassOrBoundGenericClass();
if (Super == C) {
Sub.insert(Sub.end(), Path.begin(), Path.end());
break;
}
CD = Super;
}
Path.clear();
}
}