Index: llvm/include/llvm/TableGen/Record.h =================================================================== --- llvm/include/llvm/TableGen/Record.h +++ llvm/include/llvm/TableGen/Record.h @@ -1440,7 +1440,7 @@ SmallVector TemplateArgs; SmallVector Values; - // All superclasses in the inheritance forest in reverse preorder (yes, it + // All superclasses in the inheritance forest in post-order (yes, it // must be a forest; diamond-shaped inheritance is not allowed). SmallVector, 0> SuperClasses; Index: llvm/lib/TableGen/Record.cpp =================================================================== --- llvm/lib/TableGen/Record.cpp +++ llvm/lib/TableGen/Record.cpp @@ -2112,9 +2112,11 @@ void Record::getDirectSuperClasses(SmallVectorImpl &Classes) const { ArrayRef> SCs = getSuperClasses(); + + // Superclasses are in post-order, so the final one is a direct + // superclass. All of its transitive superclases immediately precede it, + // so we can step through the direct superclasses in reverse order. while (!SCs.empty()) { - // Superclasses are in reverse preorder, so 'back' is a direct superclass, - // and its transitive superclasses are directly preceding it. Record *SC = SCs.back().first; SCs = SCs.drop_back(1 + SC->getSuperClasses().size()); Classes.push_back(SC);